homebridge-vwconnectid
Version:
Homebridge plugin for Volkswagen ID.x cars
59 lines • 3.22 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventMotionSensorAccessory = void 0;
class EventMotionSensorAccessory {
constructor(platform, accessory) {
this.platform = platform;
this.accessory = accessory;
this.accessory.getService(this.platform.Service.AccessoryInformation)
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'Volkswagen')
.setCharacteristic(this.platform.Characteristic.Model, this.platform.vwConn.vehicles.data.find(({ vin }) => vin === this.platform.config.weconnect.vin).model)
.setCharacteristic(this.platform.Characteristic.SerialNumber, this.platform.config.weconnect.vin);
this.service = this.accessory.getService(this.platform.Service.MotionSensor) ||
this.accessory.addService(this.platform.Service.MotionSensor);
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
this.service.getCharacteristic(this.platform.Characteristic.MotionDetected)
.onGet(this.getMotionDetected.bind(this));
this.platform.idStatusEmitter.on(accessory.context.device.event, (state) => {
if (typeof (state) == 'boolean') {
this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, state);
}
else if (typeof (state) == 'undefined') {
this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, true);
setTimeout(() => {
this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, false);
}, 10 * 1000);
}
});
}
async getMotionDetected() {
var _a, _b, _c;
let state = false;
if (this.accessory.context.device.event == 'carLocked') {
if (typeof ((_c = (_b = (_a = this.platform.vwConn.idData.access) === null || _a === void 0 ? void 0 : _a.accessStatus) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.doorLockStatus) === 'undefined') {
state = false;
}
else {
state = (this.platform.vwConn.idData.access.accessStatus.value.doorLockStatus == 'locked') ? true : false;
}
}
if (this.accessory.context.device.event == 'parked') {
state = this.platform.vwConn.idData.parking.data.carIsParked;
}
if (this.accessory.context.device.event == 'notParked') {
state = !this.platform.vwConn.idData.parking.data.carIsParked;
}
if (this.accessory.context.device.event == 'statusNotSafe') {
state = this.platform.vwConn.config.unSafe;
}
if (this.accessory.context.device.event == 'noExternalPower') {
state = this.platform.vwConn.config.noExternalPower;
}
if (this.accessory.context.device.event == 'backendError') {
state = this.platform.vwConn.config.backendError;
}
return state;
}
}
exports.EventMotionSensorAccessory = EventMotionSensorAccessory;
//# sourceMappingURL=eventMotionSensorAccessory.js.map