Fixed bug where flux doesn't run after the first night
This commit is contained in:
@ -7,6 +7,7 @@ import { IConfig } from "./models/iConfig";
|
||||
//@ts-ignore
|
||||
import { GetTimesResult, getTimes } from "suncalc";
|
||||
import HueError = require("node-hue-api/lib/HueError");
|
||||
import cron from "node-cron";
|
||||
|
||||
let Service: HAPNodeJS.Service;
|
||||
let Characteristic: HAPNodeJS.Characteristic;
|
||||
@ -49,11 +50,19 @@ export class FluxAccessory implements IAccessory {
|
||||
this._homebridge = props.homebridge;
|
||||
this._isActive = false;
|
||||
|
||||
this._times = getTimes(new Date(), this._config.latitude, this._config.longitude);
|
||||
|
||||
//Schedule job to refresh times
|
||||
cron.schedule("0 12 * * *", () => {
|
||||
this._times = getTimes(new Date(), this._config.latitude, this._config.longitude);
|
||||
this._log("Updated sunset times");
|
||||
}, {
|
||||
scheduled: true
|
||||
}).start();
|
||||
|
||||
this._hue = props.hue;
|
||||
this.name = this._config.name;
|
||||
|
||||
this._times = getTimes(new Date(), this._config.latitude, this._config.longitude);
|
||||
|
||||
this.platformAccessory = new this._homebridge.platformAccessory(this.name, this.generateUUID(), this._homebridge.hap.Accessory.Categories.SWITCH);
|
||||
|
||||
//@ts-ignore
|
||||
@ -222,10 +231,10 @@ export class FluxAccessory implements IAccessory {
|
||||
|
||||
const now = this.getNow();
|
||||
//Pad start time by an hour before sunset
|
||||
const start = new Date(this._times.sunset.getTime() - (30 * MINUTES_IN_MILLISECOND));
|
||||
const start = new Date(this._times.sunset.getTime() - (60 * MINUTES_IN_MILLISECOND));
|
||||
const sunsetStart = this._times.sunsetStart;
|
||||
const sunsetEnd = new Date(this._times.sunset.getTime() + this._config.sunsetDuration);
|
||||
const nightStart = new Date(sunsetEnd.getTime() + 30 * MINUTES_IN_MILLISECOND);
|
||||
const nightStart = new Date(sunsetEnd.getTime() + 60 * MINUTES_IN_MILLISECOND);
|
||||
const sunrise = new Date(this._times.sunrise.getTime() + 1 * SECONDS_IN_DAY);
|
||||
|
||||
const startColorTemp = this._config.ceilingColorTemp ? this._config.ceilingColorTemp : 4000;
|
||||
|
Reference in New Issue
Block a user