@homebridge-plugins/homebridge-smarthq
Version:
The SmartHQ plugin allows you to interact with SmartHQ Devices in HomeKit and with Siri.
52 lines • 2.53 kB
JavaScript
import { ERD_TYPES } from '../../../index.js';
import { OpalDeviceBase } from '../OpalDeviceBase.js';
export class OpalFilterMaintenanceSvcManager extends OpalDeviceBase {
service;
serviceName = 'Opal Filter Maintenance';
configuredName = 'Filter Maintenance';
advancedOptionQueryStrs = ['device=opal&label=HKC_Filter_Maintenance_Notification_Path&indicator=oplHKCFilterMaintenanceNotificationPath'];
filterMaintenanceStatus = 0;
constructor(platform, accessory, device) {
super(platform, accessory, device);
this.service = this.createService();
}
async getFilterMaintenanceStatus() {
const currentFilterStatus = await this.readErd(ERD_TYPES.OIM_FILTER_STATUS);
this.setFilterMaintenanceStatus(Number.parseInt(currentFilterStatus));
}
setFilterMaintenanceStatus(updateValue) {
this.filterMaintenanceStatus = 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, 'filter-maintenance-status');
service
.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.onGet(() => this.configuredName)
.setValue(this.configuredName);
service
.getCharacteristic(this.platform.Characteristic.FilterChangeIndication)
.onGet(() => {
return this.filterMaintenanceStatus;
}).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?.oplHKCFilterMaintenanceNotificationPath;
if (notificationPath) {
await this.sendHomeKitControllerNotification(notificationPath);
}
}
});
return service;
}
getService() {
return this.service;
}
}
//# sourceMappingURL=OpalFilterMaintenanceSvcManager.js.map