@wanderxjtu/homebridge-yeelighter
Version:
Yeelight support for Homebridge with particular support of ceiling lights
62 lines • 3.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackgroundLightService = void 0;
const lightservice_1 = require("./lightservice");
class BackgroundLightService extends lightservice_1.LightService {
constructor(parameters) {
super(parameters, "background");
this.onAttributesUpdated = (newAttributes) => {
this.debug(`backlight updated ${JSON.stringify(newAttributes)}`);
this.powerMode = (0, lightservice_1.powerModeFromColorModeAndActiveMode)(newAttributes.bg_lmode, 0);
this.updateCharacteristic(this.platform.Characteristic.Saturation, newAttributes.bg_sat);
this.updateCharacteristic(this.platform.Characteristic.Hue, newAttributes.bg_hue);
this.updateCharacteristic(this.platform.Characteristic.On, newAttributes.bg_power);
this.updateCharacteristic(this.platform.Characteristic.Brightness, newAttributes.bg_bright);
};
this.service.displayName = "Background Light";
this.installHandlers();
}
async installHandlers() {
this.handleCharacteristic(this.platform.Characteristic.On, async () => this.getAttribute("bg_power"), value => this.sendCommand("bg_set_power", [value ? "on" : "off", "smooth", 500, lightservice_1.POWERMODE_HSV]));
this.handleCharacteristic(this.platform.Characteristic.Brightness, async () => this.getAttribute("bg_bright"), async (value) => {
if (value > 0) {
this.log("set brightness", value);
await this.sendSuddenCommand("bg_set_bright", value);
this.setAttributes({ bg_bright: value });
// this.updateCharacteristic(this.platform.Characteristic.Brightness, value);
}
else {
this.log(`set brightness to 0, power off`);
await this.sendSuddenCommand("bg_set_power", "off");
}
this.saveDefaultIfNeeded();
});
if (this.platform.config.ctforcolor === undefined || this.platform.config.ctforcolor) {
const characteristic = this.handleCharacteristic(this.platform.Characteristic.ColorTemperature, async () => {
const ct = await this.getAttribute("bg_ct");
return (0, lightservice_1.convertColorTemperature)(ct);
}, async (value) => {
await this.ensurePowerMode(lightservice_1.POWERMODE_CT, "bg_");
this.debug(`setCT ${(0, lightservice_1.convertColorTemperature)(value)}`);
await this.sendSuddenCommand("bg_set_ct_abx", (0, lightservice_1.convertColorTemperature)(value));
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 () => this.getAttribute("bg_hue"), async (value) => {
this.lastHue = value;
await this.setHSV("bg_");
});
this.handleCharacteristic(this.platform.Characteristic.Saturation, async () => this.getAttribute("bg_sat"), async (value) => {
this.lastSat = value;
await this.setHSV("bg_");
});
}
}
exports.BackgroundLightService = BackgroundLightService;
//# sourceMappingURL=backgroundlightservice.js.map