Fixed bug where not all lights were being set. Fixed after sunset lighting
This commit is contained in:
parent
6625ce952a
commit
eacd56afa5
@ -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)}`)
|
||||
|
@ -16,4 +16,5 @@ export interface IConfig {
|
||||
sunsetColorTemp?: number;
|
||||
transition?: number;
|
||||
delay?: number;
|
||||
watchdog?: number;
|
||||
}
|
Loading…
Reference in New Issue
Block a user