homebridge-smartsystem
Version:
SmartServer (Proxy Websockets to TCP sockets, Smappee MQTT, Duotecno IP Nodes, Homekit interface)
95 lines • 4.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GarageDoor = void 0;
const types_1 = require("../duotecno/types");
const logger_1 = require("../duotecno/logger");
const accessory_1 = require("./accessory");
// Johan Coppieters Jun 2020
//
// Garagedoor
// - has security, so when opening you need to authenticate
// - TargetDoorState -> Characteristic.CurrentDoorState.OPEN, .STOPPED, .CLOSED
//
//
class GarageDoor extends accessory_1.Accessory {
constructor(homebridge, unit) {
super(homebridge, unit);
}
getAccessoryServices() {
// GarageDoorOpener needs authentication
const garageDoor = this.makeService(this.homebridge.Service.GarageDoorOpener);
this.attachServices(garageDoor);
return [garageDoor];
}
attachServices(door) {
door.getCharacteristic(this.homebridge.Characteristic.TargetDoorState)
.on('get', this.getTargetDoorState.bind(this))
.on('set', this.setDoorState.bind(this));
door.getCharacteristic(this.homebridge.Characteristic.CurrentDoorState)
.on('get', this.getDoorState.bind(this));
}
DT2HB(status) {
if (status == types_1.UnitState.kOpen)
return this.homebridge.Characteristic.CurrentDoorState.OPEN;
else if (status == types_1.UnitState.kClosing)
return this.homebridge.Characteristic.CurrentDoorState.CLOSING;
else if (status == types_1.UnitState.kClosed)
return this.homebridge.Characteristic.CurrentDoorState.CLOSED;
else if (status == types_1.UnitState.kOpening)
return this.homebridge.Characteristic.CurrentDoorState.OPENING;
else if (status == types_1.UnitState.kStopped)
return this.homebridge.Characteristic.CurrentDoorState.STOPPED;
else
return this.homebridge.Characteristic.CurrentDoorState.STOPPED; // ????
}
HB2DT(state) {
if (state == this.homebridge.Characteristic.CurrentDoorState.OPEN)
return types_1.UnitMotorCmd.kOpen;
else if (state == this.homebridge.Characteristic.CurrentDoorState.CLOSED)
return types_1.UnitMotorCmd.kClose;
else if (state == this.homebridge.Characteristic.CurrentDoorState.STOPPED)
return types_1.UnitMotorCmd.kStop;
else
return 0;
}
getDoorState(next) {
try {
this.unit.reqState(unit => {
const hb = this.DT2HB(unit.status);
(0, logger_1.log)("accessory", "Get TargetDoorState of " + this.name + " = " + unit.status + " -> " + hb);
next(null, hb);
});
}
catch (err) {
next(err);
}
}
setDoorState(value, next) {
// homekit is giving OPEN, .STOPPED, .CLOSED
// for the smartbox -> 5=down, 4=up, 3=stop
this.targetState = value;
let cmd = this.HB2DT(value);
if (cmd) {
(0, logger_1.log)("accessory", "Set TargetDoorState of " + this.name + ", value =" + value + " -> cmd=" + cmd);
this.unit.setState(cmd)
.then(() => next())
.catch(err => next(err));
}
else {
(0, logger_1.log)("accessory", "Set TargetDoorState of " + this.name + " -> failed for : " + value);
next(new Error("TargetDoorState of " + this.name + " -> failed"));
}
}
getTargetDoorState(next) {
(0, logger_1.log)("accessory", "Characteristic.TargetDoorState.get was called of " + this.name + " = " + this.targetState);
next(null, this.targetState);
}
// in response to Duotecno status messages
updateState() {
const value = this.DT2HB(this.unit.status);
// log("accessory", "Received updateState -> Homekit GarageDoor for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status + " / " + this.unit.value + " -> passing to HB: " + value);
this.me.getCharacteristic(this.homebridge.Characteristic.CurrentDoorState).updateValue(value);
}
}
exports.GarageDoor = GarageDoor;
//# sourceMappingURL=garagedoor.js.map