diff --git a/lib/Platform.js b/lib/Platform.js index 47e3268..ea4d485 100644 --- a/lib/Platform.js +++ b/lib/Platform.js @@ -192,7 +192,7 @@ class Platform extends homebridgeLib.Delegate { } myContext.platform = this if (global[globalKey].Platform == null) { - this.fatal('%s plugin not loaded', context.libName) + this.fatal('%s platform not registered', context.libName) } this._identify() @@ -206,8 +206,13 @@ class Platform extends homebridgeLib.Delegate { // Main platform function. // Called by homebridge after restoring accessories from cache. async _main () { + if (this._isHomebridgeLib || global[globalKey].Platform.platform == null) { + global[globalKey].Platform.platform = this + this.debug('starting heartbeat for %j', Object.keys(global[globalKey])) + this._heartbeatStart = new Date() + setTimeout(() => { this._beat(-1) }, 1000) + } if (this._isHomebridgeLib) { - this.debug('plugins: %j', Object.keys(global[globalKey])) const jobs = [] for (const plugin in global[globalKey]) { const platform = global[globalKey][plugin].platform @@ -218,9 +223,6 @@ class Platform extends homebridgeLib.Delegate { jobs.push(events.once(platform, 'initialised')) } } - this.debug('starting heartbeat') - this._heartbeatStart = new Date() - setTimeout(() => { this._beat(-1) }, 1000) for (const job of jobs) { await job }