@uboness/homebridge-unifi-access
Version:
Homebridge Unifi Access Plugin
98 lines • 5.01 kB
JavaScript
;
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Door = void 0;
const Device_js_1 = require("./Device.js");
var Door;
(function (Door) {
Door.create = async (platform, client, accessory, device) => {
const asGarageDoor = accessory.context.asGarageDoor;
if (asGarageDoor) {
return GarageDoor.create(platform, client, accessory, device);
}
return Lock.create(platform, client, accessory, device);
};
})(Door = exports.Door || (exports.Door = {}));
class Lock extends Device_js_1.Device {
constructor(platform, client, accessory, device) {
var _c;
super(platform, client, accessory, device, (_c = accessory.getService(platform.Service.LockMechanism)) !== null && _c !== void 0 ? _c : accessory.addService(platform.Service.LockMechanism));
this.targetState = this.primaryService.getCharacteristic(platform.Characteristic.LockTargetState)
.setValue(this.device.locked ? platform.Characteristic.LockTargetState.SECURED : platform.Characteristic.LockTargetState.UNSECURED)
.onSet(async (value, context) => {
if (!(context === null || context === void 0 ? void 0 : context.fromUnifi)) {
const locked = value === platform.Characteristic.LockTargetState.SECURED;
if (!locked) {
await client.unlockDoor(device.id);
}
}
});
this.currentState = this.primaryService.getCharacteristic(platform.Characteristic.LockCurrentState)
.setValue(platform.Characteristic.LockCurrentState.SECURED);
}
update(door) {
this.device.locked = door.locked;
}
async doClose() {
}
onMessage(msg, platform) {
if (msg.type === 'door-update' && msg.id === this.device.id) {
if (msg.locked !== undefined) {
this.device.locked = msg.locked;
const currestState = msg.locked ? platform.Characteristic.LockCurrentState.SECURED : platform.Characteristic.LockCurrentState.UNSECURED;
this.currentState.setValue(currestState, { fromUnifi: true });
const targetState = msg.locked ? platform.Characteristic.LockTargetState.SECURED : platform.Characteristic.LockTargetState.UNSECURED;
this.targetState.setValue(targetState, { fromUnifi: true });
}
this.statusFault.setValue(!msg.available);
}
}
}
_a = Lock;
Lock.create = async (platform, client, accessory, device) => {
return new Lock(platform, client, accessory, device);
};
class GarageDoor extends Device_js_1.Device {
constructor(platform, client, accessory, device) {
var _c;
super(platform, client, accessory, device, (_c = accessory.getService(platform.Service.GarageDoorOpener)) !== null && _c !== void 0 ? _c : accessory.addService(platform.Service.GarageDoorOpener));
this.targetState = this.primaryService.getCharacteristic(platform.Characteristic.TargetDoorState)
.setValue(this.device.locked ? platform.Characteristic.TargetDoorState.CLOSED : platform.Characteristic.TargetDoorState.OPEN)
.onSet(async (value, context) => {
const locked = value === platform.Characteristic.TargetDoorState.CLOSED;
if (!(context === null || context === void 0 ? void 0 : context.fromUnifi)) {
if (!locked) {
setTimeout(() => this.currentState.setValue(platform.Characteristic.CurrentDoorState.OPENING), 5);
await client.unlockDoor(device.id);
}
}
if (locked) {
setTimeout(() => this.currentState.setValue(platform.Characteristic.CurrentDoorState.CLOSED), 5);
}
});
this.currentState = this.primaryService.getCharacteristic(platform.Characteristic.CurrentDoorState)
.setValue(platform.Characteristic.CurrentDoorState.CLOSED);
}
update(door) {
this.device.locked = door.locked;
}
async doClose() {
}
onMessage(msg, platform) {
if (msg.type === 'door-update' && msg.id === this.device.id) {
if (msg.locked !== undefined) {
this.device.locked = msg.locked;
const currestState = msg.locked ? platform.Characteristic.CurrentDoorState.CLOSED : platform.Characteristic.CurrentDoorState.OPEN;
this.currentState.setValue(currestState, { fromUnifi: true });
const targetState = msg.locked ? platform.Characteristic.TargetDoorState.CLOSED : platform.Characteristic.TargetDoorState.OPEN;
this.targetState.setValue(targetState, { fromUnifi: true });
}
this.statusFault.setValue(!msg.available);
}
}
}
_b = GarageDoor;
GarageDoor.create = async (platform, client, accessory, device) => {
return new GarageDoor(platform, client, accessory, device);
};
//# sourceMappingURL=Door.js.map