homebridge-eufy-security
Version:
Control Eufy Security from homebridge.
71 lines • 2.9 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceAccessory = void 0;
const BaseAccessory_1 = require("./BaseAccessory");
const eufy_security_client_1 = require("eufy-security-client");
const utils_1 = require("../utils/utils");
class DeviceAccessory extends BaseAccessory_1.BaseAccessory {
constructor(platform, accessory, device) {
super(platform, accessory, device);
}
/**
* Get the current value of the "propertyName" characteristic
*/
getPropertyValue(characteristic, propertyName) {
try {
const value = this.device.getPropertyValue(propertyName);
this.log.debug(`GET '${characteristic}' ${propertyName}: ${value}`);
return value;
}
catch (error) {
this.log.debug(`Error getting '${characteristic}' ${propertyName}: ${error}`);
return false;
}
}
async setPropertyValue(propertyName, value) {
await this.platform.eufyClient.setDeviceProperty(this.SN, propertyName, value);
}
onPushNotification(characteristicType, serviceType, value) {
this.log.debug(`ON '${serviceType.name}': ${value}`);
this.getService(serviceType)
.getCharacteristic(characteristicType)
.updateValue(value);
}
initSensorService() {
const propertiesToRegister = [
{
property: 'battery',
characteristicType: utils_1.CHAR.BatteryLevel,
propertyName: eufy_security_client_1.PropertyName.DeviceBattery,
onSimpleValue: null,
fallback: 100,
},
{
property: 'batteryLow',
characteristicType: utils_1.CHAR.StatusLowBattery,
propertyName: eufy_security_client_1.PropertyName.DeviceBatteryLow,
onSimpleValue: 'low battery',
fallback: false,
},
{
property: 'batteryIsCharging',
characteristicType: utils_1.CHAR.ChargingState,
propertyName: eufy_security_client_1.PropertyName.DeviceBatteryIsCharging,
onSimpleValue: null,
fallback: false,
},
];
propertiesToRegister.forEach((propertyConfig) => {
if (this.device.hasProperty(propertyConfig.property)) {
this.registerCharacteristic({
serviceType: utils_1.SERV.Battery,
characteristicType: propertyConfig.characteristicType,
getValue: () => this.device.getPropertyValue(propertyConfig.propertyName) || propertyConfig.fallback,
onSimpleValue: propertyConfig.onSimpleValue,
});
}
});
}
}
exports.DeviceAccessory = DeviceAccessory;
//# sourceMappingURL=Device.js.map
;