homebridge-smartsystem
Version:
SmartServer (Proxy Websockets to TCP sockets, Smappee MQTT, Duotecno IP Nodes, Homekit interface)
35 lines (26 loc) • 755 B
text/typescript
import { Accessory } from "./accessory";
import { Unit } from "../duotecno/protocol";
import { API } from "homebridge";
// Johan Coppieters Jan 2019
//
// Switch
// - not a light.
//
export class Switch extends Accessory {
constructor(homebridge: API, unit: Unit) {
super(homebridge, unit);
}
getAccessoryServices() {
const switchService = this.makeService(this.homebridge.Service.Switch)
switchService
.getCharacteristic(this.homebridge.Characteristic.On)
.on('get', this.getState.bind(this))
.on('set', this.setPower.bind(this));
return [switchService];
}
setPower(powerOn, next) {
this.unit.setState(powerOn > 0)
.then(() => next())
.catch(err => next(err))
}
}