diff options
author | lonkaars <loek@pipeframe.xyz> | 2021-08-09 15:16:17 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2021-08-09 15:16:17 +0200 |
commit | 859d5d44633ab3afd2d5ebf060d16a88e99f80ff (patch) | |
tree | 48218a16a12bfbab4710254240ba7380c94a2aff | |
parent | e8ca02eda2fea678a407b73af161014d703bab1c (diff) |
stable :tada:
-rw-r--r-- | index.ts | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -1,10 +1,11 @@ -import { AccessoryConfig, AccessoryPlugin, API, Logger, Service } from 'homebridge'; import axios from 'axios'; +import { AccessoryConfig, AccessoryPlugin, API, Logger, Service } from 'homebridge'; const Color = require('color'); export default class ESP8266RGBStrip implements AccessoryPlugin { private infoService: Service; private bulbService: Service; + private lastMessage: string; private state: { on: boolean; brightness: number; @@ -65,9 +66,14 @@ export default class ESP8266RGBStrip implements AccessoryPlugin { } updateLamp() { - var rgb = Color({ h: this.state.hue, s: this.state.saturation, v: Number(this.state.on && this.state.brightness) }); - var color = [rgb.red(), rgb.green(), rgb.blue()].map(i => i.toString(16).padStart(2, '0')).join(''); - axios.post("http://" + this.host, color); + var rgb = Color({ + h: this.state.hue, + s: this.state.saturation, + v: Number(this.state.on && this.state.brightness), + }); + var color = [rgb.red(), rgb.green(), rgb.blue()].map(i => Math.floor(i).toString(16).padStart(2, '0')).join(''); + if (color != this.lastMessage) axios.post('http://' + this.host, color); + this.lastMessage = color; } getServices() { @@ -78,4 +84,6 @@ export default class ESP8266RGBStrip implements AccessoryPlugin { } } -module.exports = (api: API) => { api.registerAccessory('ESP8266RGBStrip', ESP8266RGBStrip) }; +module.exports = (api: API) => { + api.registerAccessory('ESP8266RGBStrip', ESP8266RGBStrip); +}; |