UNPKG

@homebridge-plugins/homebridge-smarthq

Version:

The SmartHQ plugin allows you to interact with SmartHQ Devices in HomeKit and with Siri.

47 lines 2.25 kB
import { ERD_TYPES } from '../../../index.js'; import { OpalDeviceBase } from '../OpalDeviceBase.js'; export class OpalPowerSvcManager extends OpalDeviceBase { service; serviceName = 'Opal Power'; configuredName = 'Power'; advancedOptionQueryStrs = ['device=opal&label=Auto_Shutoff_on_Blocking_Event&indicator=oplAutoShutoffOnBlockingEvent&type=boolean&defaultValue=false']; constructor(platform, accessory, device) { super(platform, accessory, device); this.service = this.createService(); } createService() { // Check if service already exists const existingService = this.accessory.getService(this.serviceName); // Remove existing service if it exists if (existingService) { this.accessory.removeService(existingService); } const service = this.accessory.addService(this.platform.Service.Switch, this.serviceName, 'opal-power'); service.setPrimaryService(); service .getCharacteristic(this.platform.Characteristic.ConfiguredName) .onGet(() => this.configuredName) .setValue(this.configuredName); service .getCharacteristic(this.platform.Characteristic.On) .onGet(() => this.readErd(ERD_TYPES.OIM_POWER).then(r => Number.parseInt(r) !== 0)) .onSet(value => this.writeErd(ERD_TYPES.OIM_POWER, value)); return service; } getService() { return this.service; } setOpalPowerState(newPowerState) { this.service.setCharacteristic(this.platform.Characteristic.On, newPowerState); } getOpalPowerState() { return this.service.getCharacteristic(this.platform.Characteristic.On).value; } turnOffOnProductionLimitSurpassed(currentProductionValue) { if (this.platform.config.deviceOptions?.opal?.opalProductionLimit && currentProductionValue >= this.platform.config.deviceOptions.opal.opalProductionLimit) { this.setOpalPowerState(false); this.platform.debugLog(`Auto-shutoff triggered: Production (${currentProductionValue}) > Limit (${this.platform.config.deviceOptions.opal.opalProductionLimit})`); } } } //# sourceMappingURL=OpalPowerSvcManager.js.map