Fixed bug where not all lights were being set. Fixed after sunset lighting

This commit is contained in:
watsonb8 2020-04-11 21:07:15 -04:00
parent 6625ce952a
commit eacd56afa5
2 changed files with 19 additions and 16 deletions

View File

@ -47,7 +47,9 @@ export class FluxAccessory implements IAccessory {
Service = props.api.hap.Service; Service = props.api.hap.Service;
Characteristic = props.api.hap.Characteristic; Characteristic = props.api.hap.Characteristic;
this._homebridge = props.homebridge; 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._scheduler.addTask({ delegate: this.updateDelegate, title: "Update" })
this._hue = props.hue; this._hue = props.hue;
@ -164,12 +166,9 @@ export class FluxAccessory implements IAccessory {
} }
private setLights = async (state: LightState) => { private setLights = async (state: LightState) => {
const promises = this._lights.map(async (value: Light) => {
try { try {
await Promise.all(
this._lights.map(async (value: Light) => {
await this._hue.lights.setLightState(value.id, state); await this._hue.lights.setLightState(value.id, state);
})
);
} catch (err) { } catch (err) {
if ((this.isHueError(err)) && err.message === "parameter, xy, is not modifiable. Device is set to off.") { if ((this.isHueError(err)) && err.message === "parameter, xy, is not modifiable. Device is set to off.") {
//Eat this //Eat this
@ -177,6 +176,9 @@ export class FluxAccessory implements IAccessory {
this._log(`Error while setting lights: ${err}`); 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 nightLength = (stopTime.getTime() - sunsetTime.getTime()) / 1000;
const secondsFromSunset = (now.getTime() - sunsetTime.getTime() / 100); const secondsFromSunset = (now.getTime() - sunsetTime.getTime()) / 100;
percentageComplete = secondsFromSunset / nightLength; percentageComplete = secondsFromSunset / nightLength;
} else { } else {
percentageComplete = 1; percentageComplete = 1;
@ -279,10 +281,10 @@ export class FluxAccessory implements IAccessory {
//Set lights //Set lights
const rgb = this.colorTempToRgb(newTemp); const rgb = this.colorTempToRgb(newTemp);
if (rgb && rgb.red && rgb.blue && rgb.green) { if (rgb) {
const lightState = new LightState(); const lightState = new LightState();
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); .rgb(rgb.red, rgb.green, rgb.blue);
await this.setLights(lightState) await this.setLights(lightState)
this._log(`Adjusting light temp to ${newTemp}, ${JSON.stringify(rgb)}`) this._log(`Adjusting light temp to ${newTemp}, ${JSON.stringify(rgb)}`)

View File

@ -16,4 +16,5 @@ export interface IConfig {
sunsetColorTemp?: number; sunsetColorTemp?: number;
transition?: number; transition?: number;
delay?: number; delay?: number;
watchdog?: number;
} }