From 859d5d44633ab3afd2d5ebf060d16a88e99f80ff Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 9 Aug 2021 15:16:17 +0200 Subject: stable :tada: --- index.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index b39994d..ddf93d3 100644 --- a/index.ts +++ b/index.ts @@ -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); +}; -- cgit v1.2.3