diff --git a/dist/accessory.d.ts b/dist/accessory.d.ts new file mode 100644 index 0000000..7960c06 --- /dev/null +++ b/dist/accessory.d.ts @@ -0,0 +1,28 @@ +import { PlatformAccessory, CharacteristicValue } from 'homebridge'; +import { ESPHomeRGBWWPlatform } from './platform'; +export declare class ESPHomeRGBWWAccessory { + private readonly platform; + private readonly accessory; + private readonly config; + private service; + private mqttClient; + private static readonly MAX_BRIGHTNESS; + private currentState; + constructor(platform: ESPHomeRGBWWPlatform, accessory: PlatformAccessory, config: any); + private rgbToHsv; + private hsvToRgb; + private handleStateUpdate; + private publishCommand; + setOn(value: CharacteristicValue): Promise; + getOn(): Promise; + setBrightness(value: CharacteristicValue): Promise; + getBrightness(): Promise; + setHue(value: CharacteristicValue): Promise; + getHue(): Promise; + setSaturation(value: CharacteristicValue): Promise; + getSaturation(): Promise; + setColorTemperature(value: CharacteristicValue): Promise; + getColorTemperature(): Promise; + private updateRGBColor; +} +//# sourceMappingURL=accessory.d.ts.map \ No newline at end of file diff --git a/dist/accessory.d.ts.map b/dist/accessory.d.ts.map new file mode 100644 index 0000000..ecbf569 --- /dev/null +++ b/dist/accessory.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"accessory.d.ts","sourceRoot":"","sources":["../src/accessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAelD,qBAAa,qBAAqB;IAc9B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAfzB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAO;IAE7C,OAAO,CAAC,YAAY,CAMlB;gBAGiB,QAAQ,EAAE,oBAAoB,EAC9B,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,GAAG;IAkD9B,OAAO,CAAC,QAAQ;IAiChB,OAAO,CAAC,QAAQ;IA+BhB,OAAO,CAAC,iBAAiB;IA+BzB,OAAO,CAAC,cAAc;IAOhB,KAAK,CAAC,KAAK,EAAE,mBAAmB;IAMhC,KAAK,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAIrC,aAAa,CAAC,KAAK,EAAE,mBAAmB;IAOxC,aAAa,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAI7C,MAAM,CAAC,KAAK,EAAE,mBAAmB;IAMjC,MAAM,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAItC,aAAa,CAAC,KAAK,EAAE,mBAAmB;IAMxC,aAAa,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAI7C,mBAAmB,CAAC,KAAK,EAAE,mBAAmB;IAM9C,mBAAmB,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAIzD,OAAO,CAAC,cAAc;CAevB"} \ No newline at end of file diff --git a/dist/accessory.js b/dist/accessory.js index a9e7914..a6794b5 100644 --- a/dist/accessory.js +++ b/dist/accessory.js @@ -1,247 +1,239 @@ "use strict"; -const mqtt = require("mqtt"); - +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ESPHomeRGBWWAccessory = void 0; +const mqtt = __importStar(require("mqtt")); class ESPHomeRGBWWAccessory { - static MAX_BRIGHTNESS = 255; - - constructor(platform, accessory, config) { - this.platform = platform; - this.accessory = accessory; - this.config = config; - this.currentState = { - on: false, - brightness: 100, - hue: 0, - saturation: 0, - colorTemperature: 300, - }; - - this.accessory - .getService(this.platform.Service.AccessoryInformation) - .setCharacteristic(this.platform.Characteristic.Manufacturer, config.manufacturer || "ESPHome") - .setCharacteristic(this.platform.Characteristic.Model, config.model || "RGBWW Light") - .setCharacteristic(this.platform.Characteristic.SerialNumber, config.id); - - this.service = - this.accessory.getService(this.platform.Service.Lightbulb) || - this.accessory.addService(this.platform.Service.Lightbulb); - - this.service.setCharacteristic(this.platform.Characteristic.Name, config.name); - - this.service - .getCharacteristic(this.platform.Characteristic.On) - .onSet(this.setOn.bind(this)) - .onGet(this.getOn.bind(this)); - - this.service - .getCharacteristic(this.platform.Characteristic.Brightness) - .onSet(this.setBrightness.bind(this)) - .onGet(this.getBrightness.bind(this)); - - this.service - .getCharacteristic(this.platform.Characteristic.Hue) - .onSet(this.setHue.bind(this)) - .onGet(this.getHue.bind(this)); - - this.service - .getCharacteristic(this.platform.Characteristic.Saturation) - .onSet(this.setSaturation.bind(this)) - .onGet(this.getSaturation.bind(this)); - - this.service - .getCharacteristic(this.platform.Characteristic.ColorTemperature) - .onSet(this.setColorTemperature.bind(this)) - .onGet(this.getColorTemperature.bind(this)); - - this.mqttClient = mqtt.connect(config.mqtt_broker || "mqtt://localhost:1883"); - - this.mqttClient.on("connect", () => { - this.platform.log.info("Connected to MQTT broker"); - this.mqttClient.subscribe(config.state_topic); - }); - - this.mqttClient.on("message", (topic, message) => { - if (topic === config.state_topic) { - this.handleStateUpdate(message.toString()); - } - }); - - this.mqttClient.on("error", (error) => { - this.platform.log.error("MQTT error:", error); - }); - } - - rgbToHsv(r, g, b) { - r /= 255; - g /= 255; - b /= 255; - - const max = Math.max(r, g, b); - const min = Math.min(r, g, b); - const delta = max - min; - - let h = 0; - let s = 0; - const v = max; - - if (delta > 0) { - s = delta / max; - - if (max === r) { - h = ((g - b) / delta) % 6; - } else if (max === g) { - h = (b - r) / delta + 2; - } else { - h = (r - g) / delta + 4; - } - - h *= 60; - if (h < 0) { - h += 360; - } - } - - return { h, s: s * 100, v: v * 100 }; - } - - hsvToRgb(h, s, v) { - s /= 100; - v /= 100; - - const c = v * s; - const x = c * (1 - Math.abs((h / 60) % 2 - 1)); - const m = v - c; - - let r = 0; - let g = 0; - let b = 0; - - if (h >= 0 && h < 60) { - r = c; - g = x; - b = 0; - } else if (h < 120) { - r = x; - g = c; - b = 0; - } else if (h < 180) { - r = 0; - g = c; - b = x; - } else if (h < 240) { - r = 0; - g = x; - b = c; - } else if (h < 300) { - r = x; - g = 0; - b = c; - } else { - r = c; - g = 0; - b = x; - } - - return { - r: Math.round((r + m) * 255), - g: Math.round((g + m) * 255), - b: Math.round((b + m) * 255), - }; - } - - handleStateUpdate(message) { - try { - const state = JSON.parse(message); - - this.currentState.on = state.state === "ON"; - this.currentState.brightness = Math.round((state.brightness / ESPHomeRGBWWAccessory.MAX_BRIGHTNESS) * 100); - - if (state.color && state.color.r !== undefined) { - const hsv = this.rgbToHsv(state.color.r, state.color.g, state.color.b); - this.currentState.hue = hsv.h; - this.currentState.saturation = hsv.s; - } - - if (state.color_temp) { - this.currentState.colorTemperature = state.color_temp; - } - - this.service.updateCharacteristic(this.platform.Characteristic.On, this.currentState.on); - this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.currentState.brightness); - this.service.updateCharacteristic(this.platform.Characteristic.Hue, this.currentState.hue); - this.service.updateCharacteristic(this.platform.Characteristic.Saturation, this.currentState.saturation); - this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.currentState.colorTemperature); - } catch (error) { - this.platform.log.error("Failed to parse state update:", error); - } - } - - publishCommand(payload) { - this.mqttClient.publish(this.config.command_topic, JSON.stringify(payload)); - } - - async setOn(value) { - this.currentState.on = value; - this.publishCommand({ state: value ? "ON" : "OFF" }); - this.platform.log.debug("Set On ->", value); - } - - async getOn() { - return this.currentState.on; - } - - async setBrightness(value) { - this.currentState.brightness = value; - const brightness = Math.round(((value) / 100) * ESPHomeRGBWWAccessory.MAX_BRIGHTNESS); - this.publishCommand({ brightness }); - this.platform.log.debug("Set Brightness ->", value); - } - - async getBrightness() { - return this.currentState.brightness; - } - - async setHue(value) { - this.currentState.hue = value; - this.updateRGBColor(); - this.platform.log.debug("Set Hue ->", value); - } - - async getHue() { - return this.currentState.hue; - } - - async setSaturation(value) { - this.currentState.saturation = value; - this.updateRGBColor(); - this.platform.log.debug("Set Saturation ->", value); - } - - async getSaturation() { - return this.currentState.saturation; - } - - async setColorTemperature(value) { - this.currentState.colorTemperature = value; - this.publishCommand({ color_temp: value }); - this.platform.log.debug("Set ColorTemperature ->", value); - } - - async getColorTemperature() { - return this.currentState.colorTemperature; - } - - updateRGBColor() { - const rgb = this.hsvToRgb(this.currentState.hue, this.currentState.saturation, this.currentState.brightness); - - this.publishCommand({ - color: { - r: rgb.r, - g: rgb.g, - b: rgb.b, - }, - }); - } + constructor(platform, accessory, config) { + this.platform = platform; + this.accessory = accessory; + this.config = config; + this.currentState = { + on: false, + brightness: 100, + hue: 0, + saturation: 0, + colorTemperature: 300, + }; + this.accessory.getService(this.platform.Service.AccessoryInformation) + .setCharacteristic(this.platform.Characteristic.Manufacturer, config.manufacturer || 'ESPHome') + .setCharacteristic(this.platform.Characteristic.Model, config.model || 'RGBWW Light') + .setCharacteristic(this.platform.Characteristic.SerialNumber, config.id); + this.service = this.accessory.getService(this.platform.Service.Lightbulb) + || this.accessory.addService(this.platform.Service.Lightbulb); + this.service.setCharacteristic(this.platform.Characteristic.Name, config.name); + this.service.getCharacteristic(this.platform.Characteristic.On) + .onSet(this.setOn.bind(this)) + .onGet(this.getOn.bind(this)); + this.service.getCharacteristic(this.platform.Characteristic.Brightness) + .onSet(this.setBrightness.bind(this)) + .onGet(this.getBrightness.bind(this)); + this.service.getCharacteristic(this.platform.Characteristic.Hue) + .onSet(this.setHue.bind(this)) + .onGet(this.getHue.bind(this)); + this.service.getCharacteristic(this.platform.Characteristic.Saturation) + .onSet(this.setSaturation.bind(this)) + .onGet(this.getSaturation.bind(this)); + this.service.getCharacteristic(this.platform.Characteristic.ColorTemperature) + .onSet(this.setColorTemperature.bind(this)) + .onGet(this.getColorTemperature.bind(this)); + this.mqttClient = mqtt.connect(config.mqtt_broker || 'mqtt://localhost:1883'); + this.mqttClient.on('connect', () => { + this.platform.log.info('Connected to MQTT broker'); + this.mqttClient.subscribe(config.state_topic); + }); + this.mqttClient.on('message', (topic, message) => { + if (topic === config.state_topic) { + this.handleStateUpdate(message.toString()); + } + }); + this.mqttClient.on('error', (error) => { + this.platform.log.error('MQTT error:', error); + }); + } + rgbToHsv(r, g, b) { + r /= 255; + g /= 255; + b /= 255; + const max = Math.max(r, g, b); + const min = Math.min(r, g, b); + const delta = max - min; + let h = 0; + let s = 0; + const v = max; + if (delta > 0) { + s = delta / max; + if (max === r) { + h = ((g - b) / delta) % 6; + } + else if (max === g) { + h = (b - r) / delta + 2; + } + else { + h = (r - g) / delta + 4; + } + h *= 60; + if (h < 0) { + h += 360; + } + } + return { h, s: s * 100, v: v * 100 }; + } + hsvToRgb(h, s, v) { + s /= 100; + v /= 100; + const c = v * s; + const x = c * (1 - Math.abs((h / 60) % 2 - 1)); + const m = v - c; + let r = 0, g = 0, b = 0; + if (h >= 0 && h < 60) { + r = c; + g = x; + b = 0; + } + else if (h < 120) { + r = x; + g = c; + b = 0; + } + else if (h < 180) { + r = 0; + g = c; + b = x; + } + else if (h < 240) { + r = 0; + g = x; + b = c; + } + else if (h < 300) { + r = x; + g = 0; + b = c; + } + else { + r = c; + g = 0; + b = x; + } + return { + r: Math.round((r + m) * 255), + g: Math.round((g + m) * 255), + b: Math.round((b + m) * 255), + }; + } + handleStateUpdate(message) { + try { + const state = JSON.parse(message); + this.currentState.on = state.state === 'ON'; + if (state.brightness != null && isFinite(state.brightness)) { + this.currentState.brightness = Math.round((state.brightness / ESPHomeRGBWWAccessory.MAX_BRIGHTNESS) * 100); + } + if (state.color && state.color.r != null && state.color.g != null && state.color.b != null) { + const hsv = this.rgbToHsv(state.color.r, state.color.g, state.color.b); + this.currentState.hue = hsv.h; + this.currentState.saturation = hsv.s; + } + if (state.color_temp) { + this.currentState.colorTemperature = state.color_temp; + } + this.service.updateCharacteristic(this.platform.Characteristic.On, this.currentState.on); + this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.currentState.brightness); + this.service.updateCharacteristic(this.platform.Characteristic.Hue, this.currentState.hue); + this.service.updateCharacteristic(this.platform.Characteristic.Saturation, this.currentState.saturation); + this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.currentState.colorTemperature); + } + catch (error) { + this.platform.log.error('Failed to parse state update:', error); + } + } + publishCommand(payload) { + this.mqttClient.publish(this.config.command_topic, JSON.stringify(payload)); + } + async setOn(value) { + this.currentState.on = value; + this.publishCommand({ state: value ? 'ON' : 'OFF' }); + this.platform.log.debug('Set On ->', value); + } + async getOn() { + return this.currentState.on; + } + async setBrightness(value) { + this.currentState.brightness = value; + const brightness = Math.round((value / 100) * ESPHomeRGBWWAccessory.MAX_BRIGHTNESS); + this.publishCommand({ brightness }); + this.platform.log.debug('Set Brightness ->', value); + } + async getBrightness() { + return this.currentState.brightness; + } + async setHue(value) { + this.currentState.hue = value; + this.updateRGBColor(); + this.platform.log.debug('Set Hue ->', value); + } + async getHue() { + return this.currentState.hue; + } + async setSaturation(value) { + this.currentState.saturation = value; + this.updateRGBColor(); + this.platform.log.debug('Set Saturation ->', value); + } + async getSaturation() { + return this.currentState.saturation; + } + async setColorTemperature(value) { + this.currentState.colorTemperature = value; + this.publishCommand({ color_temp: value }); + this.platform.log.debug('Set ColorTemperature ->', value); + } + async getColorTemperature() { + return this.currentState.colorTemperature; + } + updateRGBColor() { + const rgb = this.hsvToRgb(this.currentState.hue, this.currentState.saturation, this.currentState.brightness); + this.publishCommand({ + color: { + r: rgb.r, + g: rgb.g, + b: rgb.b, + }, + }); + } } - -module.exports = { ESPHomeRGBWWAccessory }; +exports.ESPHomeRGBWWAccessory = ESPHomeRGBWWAccessory; +ESPHomeRGBWWAccessory.MAX_BRIGHTNESS = 255; +//# sourceMappingURL=accessory.js.map \ No newline at end of file diff --git a/dist/accessory.js.map b/dist/accessory.js.map new file mode 100644 index 0000000..cc61520 --- /dev/null +++ b/dist/accessory.js.map @@ -0,0 +1 @@ +{"version":3,"file":"accessory.js","sourceRoot":"","sources":["../src/accessory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,2CAA6B;AAc7B,MAAa,qBAAqB;IAahC,YACmB,QAA8B,EAC9B,SAA4B,EAC5B,MAAW;QAFX,aAAQ,GAAR,QAAQ,CAAsB;QAC9B,cAAS,GAAT,SAAS,CAAmB;QAC5B,WAAM,GAAN,MAAM,CAAK;QAXtB,iBAAY,GAAG;YACrB,EAAE,EAAE,KAAK;YACT,UAAU,EAAE,GAAG;YACf,GAAG,EAAE,CAAC;YACN,UAAU,EAAE,CAAC;YACb,gBAAgB,EAAE,GAAG;SACtB,CAAC;QAOA,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAE;aACnE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,SAAS,CAAC;aAC9F,iBAAiB,CAAC,IAAI,CAAC,QAAQ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UAAU,GAAG,KAAe,CAAC;QAC/C,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,KAA0B;QAClD,IAAI,CAAC,YAAY,CAAC,gBAAgB,GAAG,KAAe,CAAC;QACrD,IAAI,CAAC,cAAc,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,mBAAmB;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC;IAC5C,CAAC;IAEO,cAAc;QACpB,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,YAAY,CAAC,GAAG,EACrB,IAAI,CAAC,YAAY,CAAC,UAAU,EAC5B,IAAI,CAAC,YAAY,CAAC,UAAU,CAC7B,CAAC;QAEF,IAAI,CAAC,cAAc,CAAC;YAClB,KAAK,EAAE;gBACL,CAAC,EAAE,GAAG,CAAC,CAAC;gBACR,CAAC,EAAE,GAAG,CAAC,CAAC;gBACR,CAAC,EAAE,GAAG,CAAC,CAAC;aACT;SACF,CAAC,CAAC;IACL,CAAC;;AAzOH,sDA0OC;AAvOyB,oCAAc,GAAG,GAAG,AAAN,CAAO"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..670657e --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,4 @@ +import { API } from 'homebridge'; +declare const _default: (api: API) => void; +export = _default; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map new file mode 100644 index 0000000..772c515 --- /dev/null +++ b/dist/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;yBAGvB,KAAK,GAAG;AAAlB,kBAEE"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 89c3c61..11f90fc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,6 +1,6 @@ "use strict"; -const { ESPHomeRGBWWPlatform } = require("./platform"); - +const platform_1 = require("./platform"); module.exports = (api) => { - api.registerPlatform("homebridge-esphome-rgbww", "ESPHomeRGBWW", ESPHomeRGBWWPlatform); + api.registerPlatform('homebridge-esphome-rgbww', 'ESPHomeRGBWW', platform_1.ESPHomeRGBWWPlatform); }; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000..37cabc4 --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,yCAAkD;AAElD,iBAAS,CAAC,GAAQ,EAAE,EAAE;IACpB,GAAG,CAAC,gBAAgB,CAAC,0BAA0B,EAAE,cAAc,EAAE,+BAAoB,CAAC,CAAC;AACzF,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/platform.d.ts b/dist/platform.d.ts new file mode 100644 index 0000000..96428d4 --- /dev/null +++ b/dist/platform.d.ts @@ -0,0 +1,13 @@ +import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from 'homebridge'; +export declare class ESPHomeRGBWWPlatform implements DynamicPlatformPlugin { + readonly log: Logger; + readonly config: PlatformConfig; + readonly api: API; + readonly Service: typeof Service; + readonly Characteristic: typeof Characteristic; + readonly accessories: PlatformAccessory[]; + constructor(log: Logger, config: PlatformConfig, api: API); + configureAccessory(accessory: PlatformAccessory): void; + discoverDevices(): void; +} +//# sourceMappingURL=platform.d.ts.map \ No newline at end of file diff --git a/dist/platform.d.ts.map b/dist/platform.d.ts.map new file mode 100644 index 0000000..23bdc51 --- /dev/null +++ b/dist/platform.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,qBAAqB,EACrB,MAAM,EACN,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,cAAc,EACf,MAAM,YAAY,CAAC;AAGpB,qBAAa,oBAAqB,YAAW,qBAAqB;aAM9C,GAAG,EAAE,MAAM;aACX,MAAM,EAAE,cAAc;aACtB,GAAG,EAAE,GAAG;IAP1B,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAwB;IAC/D,SAAgB,cAAc,EAAE,OAAO,cAAc,CAA+B;IACpF,SAAgB,WAAW,EAAE,iBAAiB,EAAE,CAAM;gBAGpC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,GAAG;IAS1B,kBAAkB,CAAC,SAAS,EAAE,iBAAiB;IAK/C,eAAe;CAuBhB"} \ No newline at end of file diff --git a/dist/platform.js b/dist/platform.js index 15c37d9..cd0f8d9 100644 --- a/dist/platform.js +++ b/dist/platform.js @@ -1,45 +1,46 @@ "use strict"; -const { ESPHomeRGBWWAccessory } = require("./accessory"); - +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ESPHomeRGBWWPlatform = void 0; +const accessory_1 = require("./accessory"); class ESPHomeRGBWWPlatform { - constructor(log, config, api) { - this.log = log; - this.config = config; - this.api = api; - this.Service = this.api.hap.Service; - this.Characteristic = this.api.hap.Characteristic; - this.accessories = []; - - this.log.debug("Finished initializing platform:", this.config.name); - this.api.on("didFinishLaunching", () => { - this.discoverDevices(); - }); - } - - configureAccessory(accessory) { - this.log.info("Loading accessory from cache:", accessory.displayName); - this.accessories.push(accessory); - } - - discoverDevices() { - const devices = this.config.lights || []; - - for (const device of devices) { - const uuid = this.api.hap.uuid.generate(device.id); - const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid); - - if (existingAccessory) { - this.log.info("Restoring existing accessory from cache:", existingAccessory.displayName); - new ESPHomeRGBWWAccessory(this, existingAccessory, device); - } else { - this.log.info("Adding new accessory:", device.name); - const accessory = new this.api.platformAccessory(device.name, uuid); - accessory.context.device = device; - new ESPHomeRGBWWAccessory(this, accessory, device); - this.api.registerPlatformAccessories("homebridge-esphome-rgbww", "ESPHomeRGBWW", [accessory]); - } - } - } + constructor(log, config, api) { + this.log = log; + this.config = config; + this.api = api; + this.Service = this.api.hap.Service; + this.Characteristic = this.api.hap.Characteristic; + this.accessories = []; + this.log.debug('Finished initializing platform:', this.config.name); + this.api.on('didFinishLaunching', () => { + this.discoverDevices(); + }); + } + configureAccessory(accessory) { + this.log.info('Loading accessory from cache:', accessory.displayName); + this.accessories.push(accessory); + } + discoverDevices() { + const devices = this.config.lights || []; + for (const device of devices) { + const uuid = this.api.hap.uuid.generate(device.id); + const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid); + if (existingAccessory) { + this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName); + if (existingAccessory.displayName !== device.name) { + existingAccessory.displayName = device.name; + this.api.updatePlatformAccessories([existingAccessory]); + } + new accessory_1.ESPHomeRGBWWAccessory(this, existingAccessory, device); + } + else { + this.log.info('Adding new accessory:', device.name); + const accessory = new this.api.platformAccessory(device.name, uuid); + accessory.context.device = device; + new accessory_1.ESPHomeRGBWWAccessory(this, accessory, device); + this.api.registerPlatformAccessories('homebridge-esphome-rgbww', 'ESPHomeRGBWW', [accessory]); + } + } + } } - -module.exports = { ESPHomeRGBWWPlatform }; +exports.ESPHomeRGBWWPlatform = ESPHomeRGBWWPlatform; +//# sourceMappingURL=platform.js.map \ No newline at end of file diff --git a/dist/platform.js.map b/dist/platform.js.map new file mode 100644 index 0000000..d89ecb2 --- /dev/null +++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AAC;YAEtF,IAAI,iBAAiB,EAAE,CAAC;gBACtB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,0CAA0C,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;gBACzF,IAAI,iBAAiB,CAAC,WAAW,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;oBAClD,iBAAiB,CAAC,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC;oBAC5C,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;gBAC1D,CAAC;gBACD,IAAI,iCAAqB,CAAC,IAAI,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;YAC7D,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;gBACpD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACpE,SAAS,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;gBAClC,IAAI,iCAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;gBACnD,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,0BAA0B,EAAE,cAAc,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;YAChG,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA7CD,oDA6CC"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c7daf87..ef76ed9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-esphome-rgbww", - "version": "2026.02.23", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebridge-esphome-rgbww", - "version": "2026.02.23", + "version": "1.0.1", "license": "MIT", "dependencies": { "mqtt": "^5.3.5" diff --git a/package.json b/package.json index 6f3338d..7eb1951 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-esphome-rgbww", - "version": "1.0.0", + "version": "1.0.1", "description": "Homebridge plugin for ESPHome RGBWW lights with HSV support", "main": "dist/index.js", "files": [ diff --git a/src/accessory.ts b/src/accessory.ts index 2a4c5dd..c475892 100644 --- a/src/accessory.ts +++ b/src/accessory.ts @@ -149,9 +149,12 @@ export class ESPHomeRGBWWAccessory { const state: LightState = JSON.parse(message); this.currentState.on = state.state === 'ON'; - this.currentState.brightness = Math.round((state.brightness / ESPHomeRGBWWAccessory.MAX_BRIGHTNESS) * 100); - if (state.color && state.color.r !== undefined) { + if (state.brightness != null && isFinite(state.brightness)) { + this.currentState.brightness = Math.round((state.brightness / ESPHomeRGBWWAccessory.MAX_BRIGHTNESS) * 100); + } + + if (state.color && state.color.r != null && state.color.g != null && state.color.b != null) { const hsv = this.rgbToHsv(state.color.r, state.color.g, state.color.b); this.currentState.hue = hsv.h; this.currentState.saturation = hsv.s; diff --git a/src/platform.ts b/src/platform.ts index 4f01452..852e2f5 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -40,6 +40,10 @@ export class ESPHomeRGBWWPlatform implements DynamicPlatformPlugin { if (existingAccessory) { this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName); + if (existingAccessory.displayName !== device.name) { + existingAccessory.displayName = device.name; + this.api.updatePlatformAccessories([existingAccessory]); + } new ESPHomeRGBWWAccessory(this, existingAccessory, device); } else { this.log.info('Adding new accessory:', device.name);