homebridge-yeelighter
Version:
Yeelight support for Homebridge with particular support of ceiling lights
39 lines • 1.77 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WhiteLightService = void 0;
const lightservice_1 = require("./lightservice");
class WhiteLightService extends lightservice_1.LightService {
constructor(parameters) {
super(parameters);
this.onAttributesUpdated = (newAttributes) => {
this.debug(`white light updated ${JSON.stringify(newAttributes)}`);
this.updateCharacteristic(this.platform.Characteristic.On, newAttributes.power);
this.updateCharacteristic(this.platform.Characteristic.Brightness, newAttributes.bright);
};
this.service.displayName = "White Light";
this.installHandlers();
}
async installHandlers() {
this.handleCharacteristic(this.platform.Characteristic.On, async () => {
const attributes = await this.attributes();
return attributes.power;
}, (value) => this.sendCommand("set_power", [value ? "on" : "off", "smooth", 500, 0]));
this.handleCharacteristic(this.platform.Characteristic.Brightness, async () => {
const attributes = await this.attributes();
return attributes.bright;
}, async (value) => {
if (value > 0) {
await this.ensurePowerMode(0);
await this.sendAnimatedCommand("set_bright", value);
this.setAttributes({ power: true, bright: value });
this.saveDefaultIfNeeded();
}
else {
await this.sendSuddenCommand("set_power", "off");
this.setAttributes({ power: false, bright: 0 });
}
});
}
}
exports.WhiteLightService = WhiteLightService;
//# sourceMappingURL=whitelightservice.js.map