UNPKG

@homebridge-plugins/homebridge-smarthq

Version:

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

55 lines 2.56 kB
import { OpalDeviceBase } from '../../OpalDeviceBase.js'; export class OpalAddWaterStatusSvcManager extends OpalDeviceBase { service; opalIceMaker; serviceName = 'Opal Add Water Sensor'; configuredName = 'Add Water'; advancedOptionQueryStrs = ['device=opal&label=HKC_Add_Water_Notification_Path&indicator=oplHKCAddWaterNotificationPath']; AddWaterCurrentStatus = { WATER_OK: 0, ADD_WATER: 1, }; addWaterCurrentStatus = this.AddWaterCurrentStatus.WATER_OK; constructor(opalIceMaker, platform, accessory, device) { super(platform, accessory, device); this.opalIceMaker = opalIceMaker; 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.ContactSensor, this.serviceName, 'opal-add-water-sensor'); service .getCharacteristic(this.platform.Characteristic.ConfiguredName) .onGet(() => this.configuredName) .setValue(this.configuredName); service .getCharacteristic(this.platform.Characteristic.ContactSensorState) .onGet(() => this.addWaterCurrentStatus) .on('change', async (chg) => { if (chg.oldValue === this.AddWaterCurrentStatus.WATER_OK && chg.newValue === this.AddWaterCurrentStatus.ADD_WATER) { const notificationPath = this.platform.config.deviceOptions?.opal?.oplHKCAddWaterNotificationPath; if (notificationPath) { await this.sendHomeKitControllerNotification(notificationPath); } } }); return service; } setAddWaterCurrentStatus(updateValue) { this.addWaterCurrentStatus = updateValue; // Stimulate on change handler for native notification this.service.getCharacteristic(this.platform.Characteristic.ContactSensorState).setValue(updateValue); if (updateValue === this.AddWaterCurrentStatus.ADD_WATER && this.platform.config.deviceOptions?.opal?.oplAutoShutoffOnBlockingEvent === true) { this.opalIceMaker.powerManager.setOpalPowerState(false); } } getService() { return this.service; } } //# sourceMappingURL=OpalAddWaterStatusSvcManager.js.map