Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions packages/mos-gateway/src/mosHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export class MosHandler {
private _logger: Winston.Logger
private _disposed = false
private _settings?: MosGatewayConfig
private _coreHandler: CoreHandler | undefined
private _coreHandler!: CoreHandler
private _observers: Array<Observer<any>> = []
private _triggerupdateDevicesTimeout: any = null
private _triggerUpdateDevicesTimeout: any = null
private mosTypes: MosTypes

public static async create(
Expand Down Expand Up @@ -119,9 +119,6 @@ export class MosHandler {
}
}
*/
if (!coreHandler) {
throw Error('coreHandler is undefined!')
}

if (!coreHandler.core) {
throw Error('coreHandler.core is undefined!')
Expand All @@ -133,15 +130,16 @@ export class MosHandler {

this.mosTypes = getMosTypes(this.strict)

await this._updateDevices()
await this._initMosConnection()

if (!this._coreHandler) throw Error('_coreHandler is undefined!')
this._coreHandler.onConnected(() => {
coreHandler.onConnected(() => {
// This is called whenever a connection to Core has been (re-)established
this.setupObservers()
this.sendStatusOfAllMosDevices()
})
this.setupObservers()

this.triggerUpdateDevices()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
async dispose(): Promise<void> {
this._disposed = true
Expand Down Expand Up @@ -209,10 +207,13 @@ export class MosHandler {
this._logger.debug('test log debug')
}
}
if (this._triggerupdateDevicesTimeout) {
clearTimeout(this._triggerupdateDevicesTimeout)
this.triggerUpdateDevices()
}
private triggerUpdateDevices() {
if (this._triggerUpdateDevicesTimeout) {
clearTimeout(this._triggerUpdateDevicesTimeout)
}
this._triggerupdateDevicesTimeout = setTimeout(() => {
this._triggerUpdateDevicesTimeout = setTimeout(() => {
this._updateDevices().catch((e) => {
this._logger.error(stringifyError(e))
})
Expand Down
Loading