UNPKG

homebridge-yeelighter

Version:

Yeelight support for Homebridge with particular support of ceiling lights

80 lines 4.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ColorLightService = void 0; const lightservice_1 = require("./lightservice"); class ColorLightService extends lightservice_1.LightService { constructor(parameters) { super(parameters); this.onAttributesUpdated = (newAttributes) => { this.debug(`color light updated ${JSON.stringify(newAttributes)}`); this.powerMode = (0, lightservice_1.powerModeFromColorModeAndActiveMode)(newAttributes.color_mode, newAttributes.active_mode); if (this.powerMode === lightservice_1.POWERMODE_HSV) { this.updateCharacteristic(this.platform.Characteristic.Saturation, newAttributes.sat); this.updateCharacteristic(this.platform.Characteristic.Hue, newAttributes.hue); this.updateCharacteristic(this.platform.Characteristic.Brightness, newAttributes.bright); } if (this.powerMode === lightservice_1.POWERMODE_CT) { this.updateCharacteristic(this.platform.Characteristic.ColorTemperature, (0, lightservice_1.convertColorTemperature)(newAttributes.ct)); } this.updateCharacteristic(this.platform.Characteristic.On, newAttributes.power); }; this.service.displayName = "Color Light"; this.installHandlers(); } async installHandlers() { this.handleCharacteristic(this.platform.Characteristic.On, async () => this.getAttribute("power"), (value) => { this.cancelAllDebounces(); return this.sendCommand("set_power", [value ? "on" : "off", "smooth", 500, 0]); }); this.handleCharacteristic(this.platform.Characteristic.Brightness, async () => this.getAttribute("bright"), async (value) => { this.log(`set brightness to ${value}`); if (value > 0) { await this.sendAnimatedCommand("set_bright", value); } else { this.cancelAllDebounces(); await this.sendSuddenCommand("set_power", "off"); this.log(`set brightness to 0, power off`); } this.saveDefaultIfNeeded(); }); if (this.platform.config.ctforcolor) { const characteristic = this.handleCharacteristic(this.platform.Characteristic.ColorTemperature, async () => { const attributes = await this.attributes(); this.debug(`getCT: ${JSON.stringify(attributes)} -> ${(0, lightservice_1.convertColorTemperature)(attributes.ct)}`); return (0, lightservice_1.convertColorTemperature)(attributes.ct); }, async (value) => { const kelvin = (0, lightservice_1.convertColorTemperature)(value); await this.ensurePowerMode(lightservice_1.POWERMODE_CT); this.debug(`setCT: ${(0, lightservice_1.convertColorTemperature)(value)}`); await this.sendAnimatedCommand("set_ct_abx", kelvin); this.setAttributes({ ct: kelvin }); this.updateColorFromCT(value); this.saveDefaultIfNeeded(); }); characteristic.setProps({ ...characteristic.props, maxValue: (0, lightservice_1.convertColorTemperature)(this.specs.colorTemperature.min), minValue: (0, lightservice_1.convertColorTemperature)(this.specs.colorTemperature.max) }); } this.handleCharacteristic(this.platform.Characteristic.Hue, async () => { const attributes = await this.attributes(); this.log(`getHue: ${JSON.stringify(attributes)}`); return attributes.hue; }, async (value) => { this.lastHue = value; await this.setHSV(); }); this.handleCharacteristic(this.platform.Characteristic.Saturation, async () => { const attributes = await this.attributes(); this.debug(`getSat: ${JSON.stringify(attributes)}`); return attributes.sat; }, async (value) => { this.lastSat = value; await this.setHSV(); }); } } exports.ColorLightService = ColorLightService; //# sourceMappingURL=colorlightservice.js.map