|
8 | 8 | SomeCompanionConfigField,
|
9 | 9 | } from '@companion-module/base'
|
10 | 10 | import PQueue from 'p-queue'
|
11 |
| -import { GetConfigFields, DeviceConfig } from './config.js' |
| 11 | +import { GetConfigFields, DeviceConfig, DEFAULT_CONFIG, ensureRequiredConfigIsDefined } from './config.js' |
12 | 12 | import { FeedbackId, GetFeedbacksList } from './feedback.js'
|
13 | 13 | import { DoAction, GetActionsList } from './actions.js'
|
14 | 14 | import { SpotifyPlaybackState, SpotifyState } from './state.js'
|
@@ -48,7 +48,7 @@ class SpotifyInstance extends InstanceBase<DeviceConfig> implements SpotifyInsta
|
48 | 48 | playbackState: null,
|
49 | 49 | }
|
50 | 50 |
|
51 |
| - this.config = {} |
| 51 | + this.config = { ...DEFAULT_CONFIG } |
52 | 52 | }
|
53 | 53 |
|
54 | 54 | public async checkIfApiErrorShouldRetry(err: any): Promise<boolean> {
|
@@ -106,6 +106,9 @@ class SpotifyInstance extends InstanceBase<DeviceConfig> implements SpotifyInsta
|
106 | 106 |
|
107 | 107 | async configUpdated(config: DeviceConfig): Promise<void> {
|
108 | 108 | this.config = config
|
| 109 | + if (ensureRequiredConfigIsDefined(this.config)) { |
| 110 | + this.saveConfig(this.config) |
| 111 | + } |
109 | 112 |
|
110 | 113 | this.setupOrRefreshAuthentication()
|
111 | 114 |
|
@@ -191,13 +194,16 @@ class SpotifyInstance extends InstanceBase<DeviceConfig> implements SpotifyInsta
|
191 | 194 |
|
192 | 195 | async init(config: DeviceConfig): Promise<void> {
|
193 | 196 | this.config = config
|
| 197 | + if (ensureRequiredConfigIsDefined(this.config)) { |
| 198 | + this.saveConfig(this.config) |
| 199 | + } |
194 | 200 |
|
195 | 201 | this.updateStatus(InstanceStatus.Connecting)
|
196 | 202 |
|
197 | 203 | this.setupOrRefreshAuthentication()
|
198 | 204 |
|
199 |
| - if (!this.pollTimer) { |
200 |
| - this.pollTimer = setInterval(() => this.queuePoll(), 3000) // Check every 3 seconds. This leaves a bit of headroom before we hit the daily api limit |
| 205 | + if (!this.pollTimer && this.config.pollInterval) { |
| 206 | + this.pollTimer = setInterval(() => this.queuePoll(), this.config.pollInterval * 1000) // Check every 3 seconds. This leaves a bit of headroom before we hit the daily api limit |
201 | 207 | }
|
202 | 208 |
|
203 | 209 | this.initActions()
|
|
0 commit comments