@@ -20,11 +20,7 @@ import {
20
20
PeripheralDeviceType ,
21
21
} from '@sofie-automation/shared-lib/dist/peripheralDevice/peripheralDeviceAPI'
22
22
import { protectString } from '@sofie-automation/shared-lib/dist/lib/protectedString'
23
- import {
24
- PeripheralDeviceCommandId ,
25
- PeripheralDeviceId ,
26
- StudioId ,
27
- } from '@sofie-automation/shared-lib/dist/core/model/Ids'
23
+ import { PeripheralDeviceCommandId , StudioId } from '@sofie-automation/shared-lib/dist/core/model/Ids'
28
24
import { StatusCode } from '@sofie-automation/shared-lib/dist/lib/status'
29
25
import { PeripheralDeviceCommand } from '@sofie-automation/shared-lib/dist/core/model/PeripheralDeviceCommand'
30
26
import { LiveStatusGatewayConfig } from './generated/options'
@@ -152,8 +148,9 @@ export class CoreHandler {
152
148
}
153
149
// setup observers
154
150
const observer = this . core . observe ( PeripheralDevicePubSubCollectionsNames . peripheralDeviceForDevice )
155
- observer . added = ( id ) => this . onDeviceChanged ( id )
156
- observer . changed = ( id ) => this . onDeviceChanged ( id )
151
+ observer . added = ( ) => this . onDeviceChanged ( )
152
+ observer . changed = ( ) => this . onDeviceChanged ( )
153
+ this . onDeviceChanged ( ) // set initial settings
157
154
this . setupObserverForPeripheralDeviceCommands ( this )
158
155
}
159
156
async destroy ( ) : Promise < void > {
@@ -193,13 +190,16 @@ export class CoreHandler {
193
190
this . _onConnected = fcn
194
191
}
195
192
196
- onDeviceChanged ( id : PeripheralDeviceId ) : void {
197
- if ( id !== this . core . deviceId ) return
193
+ onDeviceChanged ( ) : void {
198
194
const col = this . core . getCollection ( PeripheralDevicePubSubCollectionsNames . peripheralDeviceForDevice )
199
195
if ( ! col ) throw new Error ( 'collection "peripheralDeviceForDevice" not found!' )
200
- const device = col . findOne ( id )
201
196
202
- this . deviceSettings = device ?. deviceSettings || { }
197
+ const device = col . findOne ( this . core . deviceId )
198
+ if ( ! device ) {
199
+ throw new Error ( `No "peripheralDeviceForDevice" with id "${ this . core . deviceId } " found!` )
200
+ }
201
+
202
+ this . deviceSettings = device . deviceSettings || { }
203
203
const logLevel = this . deviceSettings [ 'debugLogging' ] ? 'debug' : 'info'
204
204
if ( logLevel !== this . logger . level ) {
205
205
this . logger . level = logLevel
@@ -211,7 +211,7 @@ export class CoreHandler {
211
211
this . logger . info ( 'Loglevel: ' + this . logger . level )
212
212
}
213
213
214
- const studioId = device ? .studioId
214
+ const studioId = device . studioId
215
215
if ( studioId === undefined ) {
216
216
throw new Error ( `Live status gateway must be attached to a studio` )
217
217
}
0 commit comments