From eacd56afa5b579d08394c7108594e2ab3f7213b9 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Sat, 11 Apr 2020 21:07:15 -0400 Subject: [PATCH] Fixed bug where not all lights were being set. Fixed after sunset lighting --- src/fluxAccessory.ts | 34 ++++++++++++++++++---------------- src/models/iConfig.ts | 1 + 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/fluxAccessory.ts b/src/fluxAccessory.ts index b9078e9..d8cb375 100644 --- a/src/fluxAccessory.ts +++ b/src/fluxAccessory.ts @@ -47,7 +47,9 @@ export class FluxAccessory implements IAccessory { Service = props.api.hap.Service; Characteristic = props.api.hap.Characteristic; this._homebridge = props.homebridge; - this._scheduler = new Scheduler(this._config.delay ? this._config.delay : 60000, 60000, this._log); + this._scheduler = new Scheduler( + this._config.delay ? this._config.delay : 60000, + this._config.watchdog ? this._config.watchdog : 120000, this._log); this._scheduler.addTask({ delegate: this.updateDelegate, title: "Update" }) this._hue = props.hue; @@ -164,19 +166,19 @@ export class FluxAccessory implements IAccessory { } private setLights = async (state: LightState) => { - try { - await Promise.all( - this._lights.map(async (value: Light) => { - await this._hue.lights.setLightState(value.id, state); - }) - ); - } catch (err) { - if ((this.isHueError(err)) && err.message === "parameter, xy, is not modifiable. Device is set to off.") { - //Eat this - } else { - this._log(`Error while setting lights: ${err}`); + const promises = this._lights.map(async (value: Light) => { + try { + await this._hue.lights.setLightState(value.id, state); + } catch (err) { + if ((this.isHueError(err)) && err.message === "parameter, xy, is not modifiable. Device is set to off.") { + //Eat this + } else { + this._log(`Error while setting lights: ${err}`); + } } - } + }); + + await Promise.all(promises); } /** @@ -261,7 +263,7 @@ export class FluxAccessory implements IAccessory { } const nightLength = (stopTime.getTime() - sunsetTime.getTime()) / 1000; - const secondsFromSunset = (now.getTime() - sunsetTime.getTime() / 100); + const secondsFromSunset = (now.getTime() - sunsetTime.getTime()) / 100; percentageComplete = secondsFromSunset / nightLength; } else { percentageComplete = 1; @@ -279,10 +281,10 @@ export class FluxAccessory implements IAccessory { //Set lights const rgb = this.colorTempToRgb(newTemp); - if (rgb && rgb.red && rgb.blue && rgb.green) { + if (rgb) { const lightState = new LightState(); lightState - .transitionInMillis(this._config.transition ? this._config.transition : 5) + .transitionInMillis(this._config.transition ? this._config.transition : 5000) .rgb(rgb.red, rgb.green, rgb.blue); await this.setLights(lightState) this._log(`Adjusting light temp to ${newTemp}, ${JSON.stringify(rgb)}`) diff --git a/src/models/iConfig.ts b/src/models/iConfig.ts index 38bfcc7..10397b3 100644 --- a/src/models/iConfig.ts +++ b/src/models/iConfig.ts @@ -16,4 +16,5 @@ export interface IConfig { sunsetColorTemp?: number; transition?: number; delay?: number; + watchdog?: number; } \ No newline at end of file