homebridge-smartsystem
Version:
SmartServer (Proxy Websockets to TCP sockets, Smappee MQTT, Duotecno IP Nodes, Homekit interface)
43 lines (32 loc) • 1.1 kB
text/typescript
import { Accessory } from "./accessory";
import { Unit } from "../duotecno/protocol";
import { API } from "homebridge";
// Johan Coppieters Jan 2019
//
// Bulb
// - does same thing as a switch, but we tell homekit that we are a light
// so when asking to Siri to turn off all lights, these get turned off too.
// - does same thing as a dimmer (which is also a LightBulb), but we don't supper Brightness.
export class Bulb extends Accessory {
constructor(homebridge: API, unit: Unit) {
super(homebridge, unit);
}
getAccessoryServices() {
const lightbulbService = this.makeService(this.homebridge.Service.Lightbulb);
lightbulbService
.getCharacteristic(this.homebridge.Characteristic.On)
.on('get', this.getState.bind(this))
.on('set', this.setPower.bind(this));
return [lightbulbService];
}
setPower(powerOn, next) {
this.unit.setState(powerOn ? 100 : 0)
.then(() => next())
.catch(err => next(err))
}
setBrightness(value, next) {
this.unit.setState(value)
.then(() => next())
.catch(err => next(err))
}
}