UNPKG

@ubreu/homebridge-eufy-security

Version:
71 lines 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeviceAccessory = void 0; const BaseAccessory_1 = require("./BaseAccessory"); const eufy_security_client_1 = require("eufy-security-client"); function isServiceInstance(serviceType) { // eslint-disable-next-line return typeof serviceType === 'object'; } 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.platform.log.debug(`${this.accessory.displayName} GET '${characteristic}' ${propertyName}: ${value}`); return value; } catch (error) { this.platform.log.debug(`${this.accessory.displayName} Error getting '${characteristic}' ${propertyName}: ${error}`); return false; } } async setPropertyValue(propertyName, value) { await this.platform.eufyClient.setDeviceProperty(this.SN, propertyName, value); } onPushNotification(characteristicType, serviceType, value, subType) { this.platform.log.debug(`${this.accessory.displayName} ON '${serviceType.name}': ${value}`); this.getService(serviceType) .getCharacteristic(characteristicType) .updateValue(value); } initSensorService(serviceType) { const propertiesToRegister = [ { property: 'battery', characteristicType: this.platform.Characteristic.BatteryLevel, propertyName: eufy_security_client_1.PropertyName.DeviceBattery, onSimpleValue: null, }, { property: 'batteryLow', characteristicType: this.platform.Characteristic.StatusLowBattery, propertyName: eufy_security_client_1.PropertyName.DeviceBatteryLow, onSimpleValue: 'low battery', }, { property: 'batteryIsCharging', characteristicType: this.platform.Characteristic.ChargingState, propertyName: eufy_security_client_1.PropertyName.DeviceBatteryIsCharging, onSimpleValue: null, }, ]; propertiesToRegister.forEach((propertyConfig) => { if (this.device.hasProperty(propertyConfig.property)) { this.registerCharacteristic({ serviceType: serviceType, characteristicType: propertyConfig.characteristicType, getValue: (data) => this.device.getPropertyValue(propertyConfig.propertyName), onSimpleValue: propertyConfig.onSimpleValue, }); } }); } } exports.DeviceAccessory = DeviceAccessory; //# sourceMappingURL=Device.js.map