Compare commits
2 Commits
master
...
feature/wi
Author | SHA1 | Date | |
---|---|---|---|
|
440a4d62a1 | ||
|
d73dead5d4 |
130
.drone.yml
Normal file
130
.drone.yml
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: default
|
||||||
|
|
||||||
|
node:
|
||||||
|
lan: internal
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: node
|
||||||
|
commands:
|
||||||
|
- npm install
|
||||||
|
- npm run build
|
||||||
|
|
||||||
|
- name: version
|
||||||
|
image: node
|
||||||
|
commands:
|
||||||
|
- export version=`node -p "require('./package.json').version"`
|
||||||
|
- export commit=`echo $DRONE_COMMIT | cut -c1-5`
|
||||||
|
- npm version prerelease --preid=$commit --git-tag-version=false --allow-same-version=true
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- tag
|
||||||
|
- pull_request
|
||||||
|
branch:
|
||||||
|
include:
|
||||||
|
- master
|
||||||
|
|
||||||
|
- name: publish pre
|
||||||
|
image: plugins/npm:1.0.0
|
||||||
|
settings:
|
||||||
|
username:
|
||||||
|
from_secret: npm_username
|
||||||
|
password:
|
||||||
|
from_secret: npm_password
|
||||||
|
email: b.watson@watsonlabs.net
|
||||||
|
registry: "http://10.44.1.6:4873/"
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- tag
|
||||||
|
- pull_request
|
||||||
|
branch:
|
||||||
|
include:
|
||||||
|
- master
|
||||||
|
|
||||||
|
- name: publish tagged version
|
||||||
|
image: plugins/npm:1.0.0
|
||||||
|
settings:
|
||||||
|
username:
|
||||||
|
from_secret: npm_username
|
||||||
|
password:
|
||||||
|
from_secret: npm_password
|
||||||
|
email: b.watson@watsonlabs.net
|
||||||
|
registry: "http://10.44.1.6:4873/"
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
- name: remove old package
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
environment:
|
||||||
|
SSH_USER:
|
||||||
|
from_secret: ssh_user
|
||||||
|
settings:
|
||||||
|
host: homebridge.me
|
||||||
|
envs:
|
||||||
|
- SSH_USER
|
||||||
|
username:
|
||||||
|
from_secret: ssh_user
|
||||||
|
key:
|
||||||
|
from_secret: ssh_key
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- rm -r /home/$SSH_USER/.npm-global/lib/node_modules/@watsonb8/homebridge-flux
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
- name: deploy
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: homebridge.me
|
||||||
|
username:
|
||||||
|
from_secret: ssh_user
|
||||||
|
key:
|
||||||
|
from_secret: ssh_key
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- npm install -g @watsonb8/homebridge-flux --registry http://10.44.1.6:4873
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
- name: restart homebridge
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: homebridge.me
|
||||||
|
username:
|
||||||
|
from_secret: elevated_ssh_user
|
||||||
|
key:
|
||||||
|
from_secret: ssh_key
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- systemctl restart homebridge
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
- name: Notify
|
||||||
|
image: drillster/drone-email
|
||||||
|
settings:
|
||||||
|
host: 10.44.1.13
|
||||||
|
username: srvGitea
|
||||||
|
password:
|
||||||
|
from_secret: smtp_password
|
||||||
|
from: drone@watsonlabs.net
|
||||||
|
skip_verify: true
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- failure
|
@ -1,85 +0,0 @@
|
|||||||
name: Build homebridge-flux
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
- run: |
|
|
||||||
npm ci
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
version:
|
|
||||||
name: Version
|
|
||||||
outputs:
|
|
||||||
version: ${{ steps.get_version.outputs.version }}
|
|
||||||
commit: ${{ steps.get_version.outputs.commit }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
- id: get_version
|
|
||||||
name: Set Version
|
|
||||||
run: |
|
|
||||||
export version=`node -p "require('./package.json').version"`
|
|
||||||
export commit=`echo $GITHUB_SHA | cut -c1-5`
|
|
||||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "commit=$commit" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
publish_tagged:
|
|
||||||
name: Publish Latest
|
|
||||||
needs:
|
|
||||||
- build
|
|
||||||
- version
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
- run: npm config set @watsonb8:registry https://gitea.watsonlabs.net/api/packages/watsonb8/npm/
|
|
||||||
- name: Publish
|
|
||||||
env:
|
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
COMMIT: ${{ needs.version.outputs.commit }}
|
|
||||||
run: |
|
|
||||||
npm config set -- '//gitea.watsonlabs.net/api/packages/watsonb8/npm/:_authToken' "$NPM_TOKEN"
|
|
||||||
npm version prerelease --preid="$COMMIT" --git-tag-version=false --allow-same-version=true
|
|
||||||
npm publish
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
runs-on:
|
|
||||||
- ubuntu-latest
|
|
||||||
- internal
|
|
||||||
name: Deploy
|
|
||||||
needs:
|
|
||||||
- publish_tagged
|
|
||||||
- version
|
|
||||||
steps:
|
|
||||||
- name: Set up SSH key
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.ELEVATED_HOMEBRIDGE_SSH_KEY }}" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
ssh-keyscan -p 22 homebridge.me >> ~/.ssh/known_hosts
|
|
||||||
sudo apt update
|
|
||||||
sudo apt install sshpass
|
|
||||||
|
|
||||||
- name: Remove old Package
|
|
||||||
run: |
|
|
||||||
sshpass -p '${{ secrets.ELEVATED_HOMEBRIDGE_PASSWORD }}' ssh -v -o StrictHostKeyChecking=no ${{ secrets.ELEVATED_HOMEBRIDGE_USER }}@${{ secrets.HOMEBRIDGE_HOST }} <<'ENDSSH'
|
|
||||||
rm -r /home/${{ secrets.HOMEBRIDGE_USER }}/.npm-global/lib/node_modules/@watsonb8/homebridge-flux
|
|
||||||
ENDSSH
|
|
||||||
- name: Deploy
|
|
||||||
env:
|
|
||||||
COMMIT: ${{ needs.version.outputs.commit }}
|
|
||||||
run: |
|
|
||||||
sshpass -p '${{ secrets.ELEVATED_HOMEBRIDGE_PASSWORD }}' ssh -v -o StrictHostKeyChecking=no ${{ secrets.ELEVATED_HOMEBRIDGE_USER }}@${{ secrets.HOMEBRIDGE_HOST }} <<'ENDSSH'
|
|
||||||
npm install -g @watsonb8/homebridge-flux@$COMMIT
|
|
||||||
ENDSSH
|
|
@ -1,154 +0,0 @@
|
|||||||
{
|
|
||||||
"pluginAlias": "Flux",
|
|
||||||
"pluginType": "platform",
|
|
||||||
"singular": true,
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"name": {
|
|
||||||
"title": "Switch Name",
|
|
||||||
"type": "string",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"ipAddress": {
|
|
||||||
"title": "IP Address",
|
|
||||||
"type": "string",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"userName": {
|
|
||||||
"title": "User Name",
|
|
||||||
"type": "string",
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"clientKey": {
|
|
||||||
"title": "Client Key",
|
|
||||||
"type": "string",
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"latitude": {
|
|
||||||
"title": "Latitude",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"longitude": {
|
|
||||||
"title": "Longitude",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"testNowDateString": {
|
|
||||||
"title": "Test Date Time",
|
|
||||||
"type": "string",
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"hueLights": {
|
|
||||||
"title": "Hue Lights",
|
|
||||||
"type": "array",
|
|
||||||
"uniqueItems": true,
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"name": {
|
|
||||||
"title": "Name",
|
|
||||||
"type": "string",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"cron": {
|
|
||||||
"title": "Cron Schedule",
|
|
||||||
"type": "string",
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"on": {
|
|
||||||
"title": "On",
|
|
||||||
"type": "boolean",
|
|
||||||
"required": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"wizLights": {
|
|
||||||
"title": "Wiz Lights",
|
|
||||||
"type": "array",
|
|
||||||
"uniqueItems": true,
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"ip": {
|
|
||||||
"title": "Ip Address",
|
|
||||||
"type": "string",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"mac": {
|
|
||||||
"title": "Mac Address",
|
|
||||||
"type": "string",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"cron": {
|
|
||||||
"title": "Cron Schedule",
|
|
||||||
"type": "string",
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"on": {
|
|
||||||
"title": "On",
|
|
||||||
"type": "boolean",
|
|
||||||
"required": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"wizDiscoveryEnabled": {
|
|
||||||
"title": "Wiz Discovery Enabled",
|
|
||||||
"type": "boolean",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"hueCeilingColorTemp": {
|
|
||||||
"title": "Hue Ceiling Color Temperature",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"hueSunsetColorTemp": {
|
|
||||||
"title": "Hue Sunset Color Temperature",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"hueFloorColorTemp": {
|
|
||||||
"title": "Hue Floor Color Temperature",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"wizCeilingColorTemp": {
|
|
||||||
"title": "Wiz Ceiling Color Temperature",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"wizSunsetColorTemp": {
|
|
||||||
"title": "Wiz Sunset Color Temperature",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"wizFloorColorTemp": {
|
|
||||||
"title": "Wiz Floor Color Temperature",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"sunsetDuration": {
|
|
||||||
"title": "Sunset Duration",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"transition": {
|
|
||||||
"title": "Transition Time",
|
|
||||||
"type": "number",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"cron": {
|
|
||||||
"title": "Default Cron",
|
|
||||||
"type": "string",
|
|
||||||
"required": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"form": null,
|
|
||||||
"display": null
|
|
||||||
}
|
|
1382
package-lock.json
generated
1382
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -1,16 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@watsonb8/homebridge-flux",
|
"name": "@watsonb8/homebridge-flux",
|
||||||
"version": "1.2.0",
|
"version": "1.1.3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "bin/index.js",
|
"main": "bin/index.js",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://gitea.watsonlabs.net"
|
"registry": "http://10.44.1.6:4873/"
|
||||||
},
|
},
|
||||||
"files": [
|
|
||||||
"bin",
|
|
||||||
"src",
|
|
||||||
"config.schema.json"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
@ -34,7 +29,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node-cron": "^2.0.3",
|
"@types/node-cron": "^2.0.3",
|
||||||
"@types/suncalc": "^1.8.0",
|
"@types/suncalc": "^1.8.0",
|
||||||
"@watsonb8/wiz-lib": "^1.0.1-ae175.0",
|
"@watsonb8/wiz-lib": "^1.0.1-62427.0",
|
||||||
"node-cron": "^2.0.3",
|
"node-cron": "^2.0.3",
|
||||||
"node-hue-api": "^4.0.5",
|
"node-hue-api": "^4.0.5",
|
||||||
"suncalc": "^1.8.0"
|
"suncalc": "^1.8.0"
|
||||||
|
@ -6,12 +6,11 @@ import { IConfig } from "./models/iConfig";
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
import { GetTimesResult, getTimes } from "suncalc";
|
import { GetTimesResult, getTimes } from "suncalc";
|
||||||
import HueError = require("node-hue-api/lib/HueError");
|
import HueError = require("node-hue-api/lib/HueError");
|
||||||
import cron, { ScheduledTask } from "node-cron";
|
import cron from "node-cron";
|
||||||
import { WizBulb } from "@watsonb8/wiz-lib/build/wizBulb";
|
import { WizBulb } from "@watsonb8/wiz-lib/build/wizBulb";
|
||||||
import { colorTemperature2rgb, RGB } from "@watsonb8/wiz-lib";
|
import { colorTemperature2rgb, RGB } from "@watsonb8/wiz-lib";
|
||||||
import { PlatformAccessory } from "homebridge";
|
import { PlatformAccessory } from "homebridge";
|
||||||
import { Platform } from "./platform";
|
import { Platform } from "./platform";
|
||||||
import { colorTempToRgb } from "./util/colorUtil";
|
|
||||||
|
|
||||||
const SECONDS_IN_DAY = 86400000;
|
const SECONDS_IN_DAY = 86400000;
|
||||||
const MINUTES_IN_MILLISECOND = 60000;
|
const MINUTES_IN_MILLISECOND = 60000;
|
||||||
@ -30,10 +29,6 @@ export class FluxAccessory {
|
|||||||
private readonly _accessory: PlatformAccessory;
|
private readonly _accessory: PlatformAccessory;
|
||||||
private _config: IConfig;
|
private _config: IConfig;
|
||||||
private _isActive: boolean;
|
private _isActive: boolean;
|
||||||
private _hueRGB: RGB;
|
|
||||||
private _wizRGB: RGB;
|
|
||||||
private _fade: number;
|
|
||||||
private _cron: string;
|
|
||||||
|
|
||||||
//Service fields
|
//Service fields
|
||||||
private _switchService;
|
private _switchService;
|
||||||
@ -44,7 +39,6 @@ export class FluxAccessory {
|
|||||||
private _wizLights: Array<WizBulb> = [];
|
private _wizLights: Array<WizBulb> = [];
|
||||||
|
|
||||||
private _times: GetTimesResult;
|
private _times: GetTimesResult;
|
||||||
private _tasks: Array<ScheduledTask> = [];
|
|
||||||
|
|
||||||
constructor(props: IFluxProps) {
|
constructor(props: IFluxProps) {
|
||||||
//Assign class variables
|
//Assign class variables
|
||||||
@ -53,12 +47,6 @@ export class FluxAccessory {
|
|||||||
this._config = props.config;
|
this._config = props.config;
|
||||||
this._isActive = false;
|
this._isActive = false;
|
||||||
this._wizLights = props.wizBulbs;
|
this._wizLights = props.wizBulbs;
|
||||||
this._hue = props.hue;
|
|
||||||
this.name = this._config.name;
|
|
||||||
this._hueRGB = { r: 0, g: 0, b: 0 };
|
|
||||||
this._wizRGB = { r: 0, g: 0, b: 0 };
|
|
||||||
this._fade = this._config.transition ?? 30000;
|
|
||||||
this._cron = this._config.cron ?? "*/30 * * * * *";
|
|
||||||
|
|
||||||
this._times = getTimes(
|
this._times = getTimes(
|
||||||
new Date(),
|
new Date(),
|
||||||
@ -82,20 +70,8 @@ export class FluxAccessory {
|
|||||||
}
|
}
|
||||||
).start();
|
).start();
|
||||||
|
|
||||||
//Schedule job to refresh hues every minute
|
this._hue = props.hue;
|
||||||
this.updateRGB();
|
this.name = this._config.name;
|
||||||
cron.schedule(
|
|
||||||
"* * * * *",
|
|
||||||
() => {
|
|
||||||
this.updateRGB();
|
|
||||||
this._platform.log.info("Updated hues");
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scheduled: true,
|
|
||||||
}
|
|
||||||
).start();
|
|
||||||
|
|
||||||
this.scheduleLights();
|
|
||||||
|
|
||||||
this._accessory
|
this._accessory
|
||||||
.getService(this._platform.api.hap.Service.AccessoryInformation)!
|
.getService(this._platform.api.hap.Service.AccessoryInformation)!
|
||||||
@ -130,8 +106,6 @@ export class FluxAccessory {
|
|||||||
.on("set", this.onSetEnabled)
|
.on("set", this.onSetEnabled)
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
.on("get", this.onGetEnabled);
|
.on("get", this.onGetEnabled);
|
||||||
|
|
||||||
// this.test();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public name: string = "Flux";
|
public name: string = "Flux";
|
||||||
@ -152,11 +126,9 @@ export class FluxAccessory {
|
|||||||
this._config.latitude,
|
this._config.latitude,
|
||||||
this._config.longitude
|
this._config.longitude
|
||||||
);
|
);
|
||||||
this._isActive = true;
|
this.update();
|
||||||
this.enable();
|
|
||||||
} else {
|
} else {
|
||||||
this._isActive = false;
|
this._isActive = false;
|
||||||
this.disable();
|
|
||||||
}
|
}
|
||||||
return callback();
|
return callback();
|
||||||
};
|
};
|
||||||
@ -176,19 +148,112 @@ export class FluxAccessory {
|
|||||||
* Populates internal lights array using the configuration values
|
* Populates internal lights array using the configuration values
|
||||||
*/
|
*/
|
||||||
private getLights = async (): Promise<void> => {
|
private getLights = async (): Promise<void> => {
|
||||||
for (const value of this._config.hueLights) {
|
for (const value of this._config.lights) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const light: Light = await this._hue.lights.getLightByName(
|
const light: Light = await this._hue.lights.getLightByName(value);
|
||||||
value.name
|
|
||||||
);
|
|
||||||
this._lights.push(light);
|
this._lights.push(light);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private colorTempToRgb = (kelvin: number): RGB => {
|
||||||
|
var temp = kelvin / 100;
|
||||||
|
var red, green, blue;
|
||||||
|
if (temp <= 66) {
|
||||||
|
red = 255;
|
||||||
|
green = temp;
|
||||||
|
green = 99.4708025861 * Math.log(green) - 161.1195681661;
|
||||||
|
|
||||||
|
if (temp <= 19) {
|
||||||
|
blue = 0;
|
||||||
|
} else {
|
||||||
|
blue = temp - 10;
|
||||||
|
blue = 138.5177312231 * Math.log(blue) - 305.0447927307;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
red = temp - 60;
|
||||||
|
red = 329.698727446 * Math.pow(red, -0.1332047592);
|
||||||
|
|
||||||
|
green = temp - 60;
|
||||||
|
green = 288.1221695283 * Math.pow(green, -0.0755148492);
|
||||||
|
|
||||||
|
blue = 255;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
r: this.clamp(red, 0, 255),
|
||||||
|
g: this.clamp(green, 0, 255),
|
||||||
|
b: this.clamp(blue, 0, 255),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
private clamp(x: number, min: number, max: number) {
|
||||||
|
if (x < min) {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
if (x > max) {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
private isHueError = (object: any): object is HueError => {
|
private isHueError = (object: any): object is HueError => {
|
||||||
return "_hueError" in object;
|
return "_hueError" in object;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private setHueLights = async (state: LightState) => {
|
||||||
|
const promises: Array<Promise<unknown> | PromiseLike<unknown>> = [];
|
||||||
|
this._lights.map(async (light: Light) => {
|
||||||
|
try {
|
||||||
|
await this._hue.lights.setLightState(light.id, state);
|
||||||
|
} catch (err) {
|
||||||
|
if (
|
||||||
|
this.isHueError(err) &&
|
||||||
|
err.message ===
|
||||||
|
"parameter, xy, is not modifiable. Device is set to off."
|
||||||
|
) {
|
||||||
|
//Eat this
|
||||||
|
} else {
|
||||||
|
this._platform.log.info(
|
||||||
|
`Error while setting lights: ${err}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
};
|
||||||
|
|
||||||
|
private setWizLights = async (rgb: RGB, fade: number): Promise<void> => {
|
||||||
|
await Promise.all(
|
||||||
|
this._wizLights.map(async (bulb) => {
|
||||||
|
const pilot = await bulb.get();
|
||||||
|
bulb.set(rgb, pilot?.dimming, fade);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to generate a UUID
|
||||||
|
*/
|
||||||
|
private generateUUID(): string {
|
||||||
|
// Public Domain/MIT
|
||||||
|
var d = new Date().getTime();
|
||||||
|
if (
|
||||||
|
typeof performance !== "undefined" &&
|
||||||
|
typeof performance.now === "function"
|
||||||
|
) {
|
||||||
|
d += performance.now(); //use high-precision timer if available
|
||||||
|
}
|
||||||
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
||||||
|
/[xy]/g,
|
||||||
|
function (c) {
|
||||||
|
var r = (d + Math.random() * 16) % 16 | 0;
|
||||||
|
d = Math.floor(d / 16);
|
||||||
|
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets adjusted color temperature.
|
* Gets adjusted color temperature.
|
||||||
*/
|
*/
|
||||||
@ -218,7 +283,13 @@ export class FluxAccessory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateRGB = (): void => {
|
private update = async (): Promise<void> => {
|
||||||
|
this._isActive = true;
|
||||||
|
while (this._isActive) {
|
||||||
|
if (this._lights.length === 0) {
|
||||||
|
await this.getLights();
|
||||||
|
}
|
||||||
|
|
||||||
const now = this.getNow();
|
const now = this.getNow();
|
||||||
//Pad start time by an hour before sunset
|
//Pad start time by an hour before sunset
|
||||||
const start = new Date(
|
const start = new Date(
|
||||||
@ -235,191 +306,61 @@ export class FluxAccessory {
|
|||||||
this._times.sunrise.getTime() + 1 * SECONDS_IN_DAY
|
this._times.sunrise.getTime() + 1 * SECONDS_IN_DAY
|
||||||
);
|
);
|
||||||
|
|
||||||
const hueStartColorTemp = this._config.hueCeilingColorTemp ?? 4000;
|
const startColorTemp = this._config.ceilingColorTemp
|
||||||
const hueSunsetColorTemp = this._config.hueSunsetColorTemp ?? 2800;
|
? this._config.ceilingColorTemp
|
||||||
const hueFloorColorTemp = this._config.hueFloorColorTemp ?? 1900;
|
: 4000;
|
||||||
|
const sunsetColorTemp = this._config.sunsetColorTemp
|
||||||
|
? this._config.sunsetColorTemp
|
||||||
|
: 2800;
|
||||||
|
const floorColorTemp = this._config.floorColorTemp
|
||||||
|
? this._config.floorColorTemp
|
||||||
|
: 1900;
|
||||||
|
|
||||||
const wizStartColorTemp = this._config.wizCeilingColorTemp ?? 4000;
|
let newTemp = 0;
|
||||||
const wizSunsetColorTemp = this._config.wizSunsetColorTemp ?? 2800;
|
|
||||||
const wizFloorColorTemp = this._config.wizFloorColorTemp ?? 1900;
|
|
||||||
|
|
||||||
let newHueTemp = this._config.hueCeilingColorTemp;
|
|
||||||
let newWizTemp = this._config.wizCeilingColorTemp;
|
|
||||||
|
|
||||||
if (start < now && now < sunsetStart) {
|
if (start < now && now < sunsetStart) {
|
||||||
newHueTemp = this.getTempOffset(
|
newTemp = this.getTempOffset(
|
||||||
hueStartColorTemp,
|
startColorTemp,
|
||||||
hueSunsetColorTemp,
|
sunsetColorTemp,
|
||||||
start,
|
|
||||||
sunsetStart
|
|
||||||
);
|
|
||||||
|
|
||||||
newWizTemp = this.getTempOffset(
|
|
||||||
wizStartColorTemp,
|
|
||||||
wizSunsetColorTemp,
|
|
||||||
start,
|
start,
|
||||||
sunsetStart
|
sunsetStart
|
||||||
);
|
);
|
||||||
} else if (sunsetStart < now && now < sunsetEnd) {
|
} else if (sunsetStart < now && now < sunsetEnd) {
|
||||||
newHueTemp = this._config.hueSunsetColorTemp;
|
newTemp = this._config.sunsetColorTemp;
|
||||||
newWizTemp = this._config.wizSunsetColorTemp;
|
|
||||||
} else if (sunsetEnd < now && now < nightStart) {
|
} else if (sunsetEnd < now && now < nightStart) {
|
||||||
newHueTemp = this.getTempOffset(
|
newTemp = this.getTempOffset(
|
||||||
hueSunsetColorTemp,
|
sunsetColorTemp,
|
||||||
hueFloorColorTemp,
|
floorColorTemp,
|
||||||
sunsetEnd,
|
|
||||||
nightStart
|
|
||||||
);
|
|
||||||
|
|
||||||
newWizTemp = this.getTempOffset(
|
|
||||||
wizSunsetColorTemp,
|
|
||||||
wizFloorColorTemp,
|
|
||||||
sunsetEnd,
|
sunsetEnd,
|
||||||
nightStart
|
nightStart
|
||||||
);
|
);
|
||||||
} else if (nightStart < now && now < sunrise) {
|
} else if (nightStart < now && now < sunrise) {
|
||||||
newHueTemp = this._config.hueFloorColorTemp;
|
newTemp = this._config.floorColorTemp;
|
||||||
newWizTemp = this._config.wizFloorColorTemp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set RGB
|
//Set lights
|
||||||
this._hueRGB = colorTempToRgb(newHueTemp);
|
const hueRGB = this.colorTempToRgb(newTemp);
|
||||||
this._wizRGB = colorTemperature2rgb(newWizTemp);
|
const wizRGB = colorTemperature2rgb(newTemp);
|
||||||
};
|
if (hueRGB && newTemp !== 0) {
|
||||||
|
|
||||||
private scheduleLights = async (): Promise<void> => {
|
|
||||||
if (this._lights.length === 0) {
|
|
||||||
await this.getLights();
|
|
||||||
}
|
|
||||||
this._tasks = [...this.getHueTasks(), ...this.getWizTasks()];
|
|
||||||
};
|
|
||||||
|
|
||||||
private getHueTasks(): Array<ScheduledTask> {
|
|
||||||
return this._config.hueLights.map((hueLightConfig) => {
|
|
||||||
let light = this._lights.find((x) => x.name == hueLightConfig.name);
|
|
||||||
let schedule: string = hueLightConfig.cron ?? this._cron;
|
|
||||||
this._platform.log.info(
|
|
||||||
`Scheduling task for ${light?.name}: ${schedule}`
|
|
||||||
);
|
|
||||||
return cron.schedule(
|
|
||||||
schedule,
|
|
||||||
async () => {
|
|
||||||
await this.updateHueLight(
|
|
||||||
light,
|
|
||||||
hueLightConfig?.on ?? false
|
|
||||||
);
|
|
||||||
this._platform.log.info("Updated hues");
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scheduled: false,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private getWizTasks(): Array<ScheduledTask> {
|
|
||||||
return this._wizLights.map((wizBulb) => {
|
|
||||||
let wizLightConfig = this._config.wizLights.find(
|
|
||||||
(x) => x.ip == wizBulb.getIp()
|
|
||||||
);
|
|
||||||
let schedule: string = wizLightConfig?.cron ?? this._cron;
|
|
||||||
this._platform.log.info(
|
|
||||||
`Scheduling task for ${wizBulb.getMac()}: ${schedule}`
|
|
||||||
);
|
|
||||||
return cron.schedule(
|
|
||||||
schedule,
|
|
||||||
async () => {
|
|
||||||
await this.updateWizLight(
|
|
||||||
wizBulb,
|
|
||||||
wizLightConfig?.on ?? false
|
|
||||||
);
|
|
||||||
this._platform.log.info("Updated hues");
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scheduled: false,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateWizLight = async (
|
|
||||||
wizBulb: WizBulb,
|
|
||||||
on: Boolean
|
|
||||||
): Promise<void> => {
|
|
||||||
let pilot;
|
|
||||||
try {
|
|
||||||
pilot = await wizBulb.get();
|
|
||||||
} catch (err: any) {
|
|
||||||
this._platform.log.error(err.message);
|
|
||||||
}
|
|
||||||
if (pilot && pilot.state) {
|
|
||||||
this._platform.log.info(`Adjusting wiz bulb: ${wizBulb.getMac()}`);
|
|
||||||
|
|
||||||
await wizBulb.set(
|
|
||||||
this._wizRGB,
|
|
||||||
on ? 100 : pilot.dimming,
|
|
||||||
this._fade
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private updateHueLight = async (
|
|
||||||
hueLight: Light | undefined,
|
|
||||||
on: Boolean
|
|
||||||
): Promise<void> => {
|
|
||||||
if (!hueLight) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._platform.log.info(`Adjusting wiz bulb: ${hueLight.name}`);
|
|
||||||
|
|
||||||
const lightState = new LightState();
|
const lightState = new LightState();
|
||||||
lightState
|
lightState
|
||||||
.transitionInMillis(this._fade)
|
.transitionInMillis(
|
||||||
.rgb(this._hueRGB.r ?? 0, this._hueRGB.g ?? 0, this._hueRGB.b ?? 0);
|
this._config.transition ? this._config.transition : 5000
|
||||||
|
)
|
||||||
if (on) {
|
.rgb(hueRGB.r ?? 0, hueRGB.g ?? 0, hueRGB.b ?? 0);
|
||||||
lightState.brightness(100).on(true);
|
await this.setHueLights(lightState);
|
||||||
}
|
await this.setWizLights(
|
||||||
try {
|
wizRGB,
|
||||||
await this._hue.lights.setLightState(hueLight.id, lightState);
|
this._config.transition ? this._config.transition / 1000 : 5
|
||||||
} catch (err) {
|
);
|
||||||
if (
|
this._platform.log.info(
|
||||||
this.isHueError(err) &&
|
`Adjusting light temp to ${newTemp}, ${JSON.stringify(
|
||||||
err.message ===
|
hueRGB
|
||||||
"parameter, xy, is not modifiable. Device is set to off."
|
)}`
|
||||||
) {
|
|
||||||
//Eat this
|
|
||||||
} else {
|
|
||||||
this._platform.log.info(`Error while setting lights: ${err}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private enable() {
|
|
||||||
this._tasks.forEach((task) => task.start());
|
|
||||||
}
|
|
||||||
|
|
||||||
private disable() {
|
|
||||||
this._tasks.forEach((task) => task.stop());
|
|
||||||
}
|
|
||||||
|
|
||||||
private test = async () => {
|
|
||||||
for (let i = 2500; i > 0; i--) {
|
|
||||||
this._platform.log.info(`i: ${i}`);
|
|
||||||
for (const wizBulb of this._wizLights) {
|
|
||||||
let pilot;
|
|
||||||
try {
|
|
||||||
pilot = await wizBulb.get();
|
|
||||||
} catch (err: any) {
|
|
||||||
this._platform.log.error(err.message);
|
|
||||||
}
|
|
||||||
this._platform.log.info(
|
|
||||||
`Adjusting wiz bulb: ${wizBulb.getMac()}`
|
|
||||||
);
|
);
|
||||||
wizBulb.set(colorTemperature2rgb(i), 100, this._fade);
|
|
||||||
}
|
}
|
||||||
await Sleep(100);
|
|
||||||
|
await Sleep(this._config.delay ? this._config.delay : 60000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
135
src/index.ts
135
src/index.ts
@ -9,3 +9,138 @@ import { Platform } from "./platform";
|
|||||||
export = (api: API) => {
|
export = (api: API) => {
|
||||||
api.registerPlatform(PLATFORM_NAME, Platform);
|
api.registerPlatform(PLATFORM_NAME, Platform);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// import { IConfig } from "./models/iConfig";
|
||||||
|
// import { v3 } from "node-hue-api";
|
||||||
|
// import LocalBootstrap = require("node-hue-api/lib/api/http/LocalBootstrap");
|
||||||
|
// import Api = require("node-hue-api/lib/api/Api");
|
||||||
|
// import { Sleep } from "./sleep";
|
||||||
|
// import { IAccessory } from "./models/iAccessory";
|
||||||
|
// import { FluxAccessory } from "./fluxAccessory";
|
||||||
|
// import { WizBulb } from "@watsonb8/wiz-lib/build/wizBulb";
|
||||||
|
// import discover from "@watsonb8/wiz-lib/build/discovery";
|
||||||
|
|
||||||
|
// let Accessory: any;
|
||||||
|
// let Homebridge: any;
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Main entry.
|
||||||
|
// * @param homebridge
|
||||||
|
// */
|
||||||
|
// export default function (homebridge: any) {
|
||||||
|
// Homebridge = homebridge;
|
||||||
|
// Accessory = homebridge.platformAccessory;
|
||||||
|
// homebridge.registerPlatform("homebridge-flux", "Flux", FluxPlatform, true);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// class FluxPlatform {
|
||||||
|
// log: any = {};
|
||||||
|
// api: any;
|
||||||
|
// accessoryList: Array<IAccessory> = [];
|
||||||
|
// config: IConfig;
|
||||||
|
// hue: Api | undefined;
|
||||||
|
|
||||||
|
// constructor(log: any, config: any, api: any) {
|
||||||
|
// this.log = log;
|
||||||
|
// this.api = api;
|
||||||
|
// this.config = config;
|
||||||
|
// this.log("INFO - Registering Flux platform");
|
||||||
|
// this.api.on("didFinishLaunching", this.didFinishLaunching.bind(this));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private connectWiz = async () => {
|
||||||
|
// if (!this.config) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return await discover();
|
||||||
|
// };
|
||||||
|
|
||||||
|
// private connectHue = async () => {
|
||||||
|
// if (!this.config) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (this.config.userName && this.config.clientKey) {
|
||||||
|
// this.hue = await v3.api
|
||||||
|
// .createLocal(this.config.ipAddress)
|
||||||
|
// .connect(
|
||||||
|
// this.config.userName,
|
||||||
|
// this.config.clientKey,
|
||||||
|
// undefined
|
||||||
|
// );
|
||||||
|
// this.log("Using existing connection info");
|
||||||
|
// } else {
|
||||||
|
// const unauthenticatedApi = await v3.api
|
||||||
|
// .createLocal(this.config.ipAddress)
|
||||||
|
// .connect(undefined, undefined, undefined);
|
||||||
|
// let createdUser;
|
||||||
|
// let connected = false;
|
||||||
|
// while (!connected) {
|
||||||
|
// try {
|
||||||
|
// this.log("Creating hue user. Push link button");
|
||||||
|
// createdUser = await unauthenticatedApi.users.createUser(
|
||||||
|
// "homebridge",
|
||||||
|
// "HueChase"
|
||||||
|
// );
|
||||||
|
|
||||||
|
// this.hue = await v3.api
|
||||||
|
// .createLocal(this.config.ipAddress)
|
||||||
|
// .connect(
|
||||||
|
// createdUser.username,
|
||||||
|
// createdUser.clientKey,
|
||||||
|
// undefined
|
||||||
|
// );
|
||||||
|
// this.log("Connected to Hue Bridge");
|
||||||
|
// this.log(
|
||||||
|
// `UserName: ${createdUser.username}, ClientKey: ${createdUser.clientkey}`
|
||||||
|
// );
|
||||||
|
// connected = true;
|
||||||
|
// } catch (err: any) {
|
||||||
|
// if (err.getHueErrorType() === 101) {
|
||||||
|
// this.log(
|
||||||
|
// "The Link button on the bridge was not pressed. Please press the Link button and try again."
|
||||||
|
// );
|
||||||
|
// Sleep(5000);
|
||||||
|
// } else {
|
||||||
|
// this.log(`Unexpected Error: ${err.message}`);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Handler for didFinishLaunching
|
||||||
|
// * Happens after constructor
|
||||||
|
// */
|
||||||
|
// private didFinishLaunching() {
|
||||||
|
// this.log(`INFO - Done registering Flux platform`);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Called by homebridge to gather accessories.
|
||||||
|
// * @param callback
|
||||||
|
// */
|
||||||
|
// public accessories = async (
|
||||||
|
// callback: (accessories: Array<IAccessory>) => void
|
||||||
|
// ) => {
|
||||||
|
// //Connect to hue bridge
|
||||||
|
// await this.connectHue();
|
||||||
|
// const wizBulbs = await this.connectWiz();
|
||||||
|
|
||||||
|
// this.accessoryList.push(
|
||||||
|
// new FluxAccessory({
|
||||||
|
// api: this.api,
|
||||||
|
// log: this.log,
|
||||||
|
// homebridge: Homebridge,
|
||||||
|
// hue: this.hue!,
|
||||||
|
// wizBulbs: wizBulbs ?? [],
|
||||||
|
// config: this.config,
|
||||||
|
// })
|
||||||
|
// );
|
||||||
|
|
||||||
|
// callback(this.accessoryList);
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
@ -17,14 +17,7 @@ export interface IConfig {
|
|||||||
/**
|
/**
|
||||||
* The list of lights to affect
|
* The list of lights to affect
|
||||||
*/
|
*/
|
||||||
hueLights: Array<{ name: string; cron?: string; on?: boolean }>;
|
lights: Array<string>;
|
||||||
|
|
||||||
/**
|
|
||||||
* The list of wiz lights to affect
|
|
||||||
*/
|
|
||||||
wizLights: Array<{ ip: string; mac: string; cron?: string; on?: boolean }>;
|
|
||||||
|
|
||||||
wizDiscoveryEnabled: boolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the enable switch in homekit
|
* The name of the enable switch in homekit
|
||||||
@ -34,32 +27,17 @@ export interface IConfig {
|
|||||||
/**
|
/**
|
||||||
* The color temperature at the start of sunset transition
|
* The color temperature at the start of sunset transition
|
||||||
*/
|
*/
|
||||||
hueCeilingColorTemp: number;
|
ceilingColorTemp: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The color temp during the night
|
* The color temp during the night
|
||||||
*/
|
*/
|
||||||
hueFloorColorTemp: number;
|
floorColorTemp: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The color temp at sunet
|
* The color temp at sunet
|
||||||
*/
|
*/
|
||||||
hueSunsetColorTemp: number;
|
sunsetColorTemp: number;
|
||||||
|
|
||||||
/**
|
|
||||||
* The color temperature at the start of sunset transition
|
|
||||||
*/
|
|
||||||
wizCeilingColorTemp: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The color temp during the night
|
|
||||||
*/
|
|
||||||
wizFloorColorTemp: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The color temp at sunet
|
|
||||||
*/
|
|
||||||
wizSunsetColorTemp: number;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time in milliseconds the lights should remain at sunset temperature.
|
* The time in milliseconds the lights should remain at sunset temperature.
|
||||||
@ -74,7 +52,7 @@ export interface IConfig {
|
|||||||
/**
|
/**
|
||||||
* The number of milliseconds to wait btw updates
|
* The number of milliseconds to wait btw updates
|
||||||
*/
|
*/
|
||||||
cron?: string;
|
delay?: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current formatted date and time to use with testing
|
* The current formatted date and time to use with testing
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import { Discover } from "@watsonb8/wiz-lib/build/discovery";
|
import discover from "@watsonb8/wiz-lib/build/discovery";
|
||||||
import { WizBulb } from "@watsonb8/wiz-lib/build/wizBulb";
|
|
||||||
import {
|
import {
|
||||||
API,
|
API,
|
||||||
|
Characteristic,
|
||||||
DynamicPlatformPlugin,
|
DynamicPlatformPlugin,
|
||||||
Logger,
|
Logger,
|
||||||
|
Logging,
|
||||||
PlatformAccessory,
|
PlatformAccessory,
|
||||||
PlatformConfig,
|
PlatformConfig,
|
||||||
|
Service,
|
||||||
UnknownContext,
|
UnknownContext,
|
||||||
} from "homebridge";
|
} from "homebridge";
|
||||||
import { v3 } from "node-hue-api";
|
import { v3 } from "node-hue-api";
|
||||||
@ -17,7 +19,6 @@ import { Sleep } from "./sleep";
|
|||||||
|
|
||||||
export class Platform implements DynamicPlatformPlugin {
|
export class Platform implements DynamicPlatformPlugin {
|
||||||
private hue: Api | undefined;
|
private hue: Api | undefined;
|
||||||
private wiz: Discover;
|
|
||||||
private accessory: PlatformAccessory | undefined = undefined;
|
private accessory: PlatformAccessory | undefined = undefined;
|
||||||
private config: IConfig;
|
private config: IConfig;
|
||||||
constructor(
|
constructor(
|
||||||
@ -26,7 +27,6 @@ export class Platform implements DynamicPlatformPlugin {
|
|||||||
public readonly api: API
|
public readonly api: API
|
||||||
) {
|
) {
|
||||||
this.config = config as unknown as IConfig;
|
this.config = config as unknown as IConfig;
|
||||||
this.wiz = new Discover();
|
|
||||||
this.log.info("INFO - Registering Flux platform");
|
this.log.info("INFO - Registering Flux platform");
|
||||||
this.api.on("didFinishLaunching", this.didFinishLaunching.bind(this));
|
this.api.on("didFinishLaunching", this.didFinishLaunching.bind(this));
|
||||||
}
|
}
|
||||||
@ -77,27 +77,7 @@ export class Platform implements DynamicPlatformPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let bulbs: Array<WizBulb> = await this.wiz.createWizBulbs(
|
return await discover();
|
||||||
this.config.wizLights
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this.config.wizDiscoveryEnabled) {
|
|
||||||
let discoveredBulbs: Array<WizBulb> = await this.wiz.discover();
|
|
||||||
let filtered = [];
|
|
||||||
for (const bulb of discoveredBulbs) {
|
|
||||||
if (
|
|
||||||
!bulbs.some(
|
|
||||||
(manualBulb) => manualBulb.getIp() === bulb.getIp()
|
|
||||||
) &&
|
|
||||||
bulb.isRGB()
|
|
||||||
) {
|
|
||||||
filtered.push(bulb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bulbs.push(...filtered);
|
|
||||||
}
|
|
||||||
|
|
||||||
return bulbs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private connectHue = async () => {
|
private connectHue = async () => {
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
import { RGB } from "@watsonb8/wiz-lib";
|
|
||||||
|
|
||||||
export const colorTempToRgb = (kelvin: number): RGB => {
|
|
||||||
var temp = kelvin / 100;
|
|
||||||
var red, green, blue;
|
|
||||||
if (temp <= 66) {
|
|
||||||
red = 255;
|
|
||||||
green = temp;
|
|
||||||
green = 99.4708025861 * Math.log(green) - 161.1195681661;
|
|
||||||
|
|
||||||
if (temp <= 19) {
|
|
||||||
blue = 0;
|
|
||||||
} else {
|
|
||||||
blue = temp - 10;
|
|
||||||
blue = 138.5177312231 * Math.log(blue) - 305.0447927307;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
red = temp - 60;
|
|
||||||
red = 329.698727446 * Math.pow(red, -0.1332047592);
|
|
||||||
|
|
||||||
green = temp - 60;
|
|
||||||
green = 288.1221695283 * Math.pow(green, -0.0755148492);
|
|
||||||
|
|
||||||
blue = 255;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
r: clamp(red, 0, 255),
|
|
||||||
g: clamp(green, 0, 255),
|
|
||||||
b: clamp(blue, 0, 255),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const clamp = (x: number, min: number, max: number) => {
|
|
||||||
if (x < min) {
|
|
||||||
return min;
|
|
||||||
}
|
|
||||||
if (x > max) {
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user