UNPKG

@homebridge-plugins/homebridge-smarthq

Version:

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

52 lines 2.41 kB
import { ERD_TYPES } from '../../../index.js'; import { OpalDeviceBase } from '../OpalDeviceBase.js'; export class OpalDescaleSvcManager extends OpalDeviceBase { service; advancedOptionQueryStrs = ['device=opal&label=HKC_Descale_Notification_Path&indicator=oplHKCDescaleNotificationPath']; serviceName = 'Opal Descale'; configuredName = 'Opal Descale'; descaleStatus = 0; constructor(platform, accessory, device) { super(platform, accessory, device); this.service = this.createService(); } async getDescaleStatus() { const currentDescaleStatus = await this.readErd(ERD_TYPES.OIM_NEEDS_DESCALING); this.setOpalDescaleStatus(Number.parseInt(currentDescaleStatus)); } setOpalDescaleStatus(updateValue) { this.descaleStatus = updateValue; // Stimulate on change handler for native notification this.service.getCharacteristic(this.platform.Characteristic.FilterChangeIndication).setValue(updateValue); } 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.FilterMaintenance, this.serviceName, 'descale-status'); service .getCharacteristic(this.platform.Characteristic.ConfiguredName) .onGet(() => this.configuredName) .setValue(this.configuredName); service .getCharacteristic(this.platform.Characteristic.FilterChangeIndication) .onGet(() => { return this.descaleStatus; }).on('change', async (chg) => { if (chg.oldValue === this.platform.Characteristic.FilterChangeIndication.FILTER_OK && chg.newValue === this.platform.Characteristic.FilterChangeIndication.CHANGE_FILTER) { const notificationPath = this.platform.config.deviceOptions?.opal?.oplHKCDescaleNotificationPath; if (notificationPath) { await this.sendHomeKitControllerNotification(notificationPath); } } }); return service; } getService() { return this.service; } } //# sourceMappingURL=OpalDescaleSvcManager.js.map