From c4e5a12645297c134ba564ea8c5e0b484b996d44 Mon Sep 17 00:00:00 2001 From: bwp91 <43026681+bwp91@users.noreply.github.com> Date: Sun, 11 Oct 2020 09:11:39 +0100 Subject: [PATCH] Update govee.js --- lib/govee.js | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/govee.js b/lib/govee.js index bcf3f735..b8d1d3e7 100644 --- a/lib/govee.js +++ b/lib/govee.js @@ -36,29 +36,14 @@ class Govee { } this.log('Plugin has finished initialising. Synching with Govee.') this.httpClient = new GoveeHTTP(this.config, this.log) - await this.goveeDeviceSync(true) + await this.goveeSync(true) this.log('[%s] devices loaded from your Govee account.', this.devicesInGV.size) - await this.goveeStatusSync() + await this.goveeSync() this.refreshDevice = promInterval( async () => { if (this.refreshFlag) { try { - await this.goveeDeviceSync(false) - } catch (err) { - if (this.debug) { - this.log.warn(err.message) - } - } - } - }, - cns.refreshTime * 1000, - { stopOnError: false } - ) - this.refreshStatus = promInterval( - async () => { - if (this.refreshFlag) { - try { - await this.goveeStatusSync() + await this.goveeSync() } catch (err) { if (this.debug) { this.log.warn(err.message) @@ -79,7 +64,9 @@ class Govee { this.log.warn('Invalid Govee API key - please double check it.') this.log.warn('**********************************************') } else { + this.log.warn('********** Cannot load homebridge-govee *********') this.log.warn(err.message) + this.log.warn('*************************************************') } } } @@ -88,7 +75,7 @@ class Govee { this.refreshFlag = false } - async goveeDeviceSync () { + async goveeSync () { const res = await this.httpClient.getDevices() res.forEach(device => this.devicesInGV.set(device.device, device)) this.devicesInHB.forEach(a => { @@ -98,9 +85,6 @@ class Govee { } }) this.devicesInGV.forEach(d => this.refreshDevice(d)) - } - - async goveeStatusSync () { this.devicesInHB.forEach(async accessory => { try { if (!accessory.context.retrievable) throw new Error('current status could not be retrieved') @@ -112,7 +96,7 @@ class Govee { }) } - async refreshDevice (device) { + refreshDevice (device) { try { let accessory if (cns.modelsLED.includes(device.model)) { @@ -128,7 +112,7 @@ class Govee { /********** UNSUPPORTED **********/ - throw new Error("it isn't supported") + return /*********/ } accessory.context.controllable = device.controllable @@ -157,7 +141,6 @@ class Govee { } this.devicesInHB.set(device.device, accessory) this.api.registerPlatformAccessories('homebridge-govee', 'Govee', [accessory]) - this.log(' → [%s] has been added to Homebridge.', device.deviceName) return accessory } catch (err) { this.log.warn(' → [%s] could not be added to Homebridge as %s.', device.deviceName, err) @@ -173,7 +156,6 @@ class Govee { try { this.devicesInHB.delete(accessory.context.gvDeviceId) this.api.unregisterPlatformAccessories('homebridge-govee', 'Govee', [accessory]) - this.log('[%s] has been removed from Homebridge.', accessory.displayName) } catch (err) { this.log.warn("[%s] needed to be removed but couldn't as %s.", accessory.displayName, err) }