UNPKG

@homebridge-plugins/homebridge-smarthq

Version:

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

55 lines 2.63 kB
import { OpalDeviceBase } from '../../OpalDeviceBase.js'; export class OpalIceBucketStatusSvcManager extends OpalDeviceBase { service; serviceName = 'Opal Ice Bucket Full Sensor'; configuredName = 'Bucket Full'; opalIceMaker; advancedOptionQueryStrs = ['device=opal&label=HKC_Ice_Bucket_Full_Notification_Path&indicator=oplHKCIceBucketFullNotificationPath']; IceBucketFullStatus = { ICE_BUCKET_NOT_FULL: 0, ICE_BUCKET_FULL: 1, }; iceBucketCurrentStatus = this.IceBucketFullStatus.ICE_BUCKET_NOT_FULL; 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-ice-bin-full-sensor'); service .getCharacteristic(this.platform.Characteristic.ConfiguredName) .onGet(() => this.configuredName) .setValue(this.configuredName); service .getCharacteristic(this.platform.Characteristic.ContactSensorState) .onGet(() => this.iceBucketCurrentStatus) .on('change', async (chg) => { if (chg.oldValue === this.IceBucketFullStatus.ICE_BUCKET_NOT_FULL && chg.newValue === this.IceBucketFullStatus.ICE_BUCKET_FULL) { const notificationPath = this.platform.config.deviceOptions?.opal?.oplHKCIceBucketFullNotificationPath; if (notificationPath) { await this.sendHomeKitControllerNotification(notificationPath); } } }); return service; } setIceBucketFullStatus(updateValue) { this.iceBucketCurrentStatus = updateValue; // Stimulate on change handler for native notification this.service.getCharacteristic(this.platform.Characteristic.ContactSensorState).setValue(updateValue); if (updateValue === this.IceBucketFullStatus.ICE_BUCKET_FULL && this.platform.config.deviceOptions?.opal?.oplAutoShutoffOnBlockingEvent === true) { this.opalIceMaker.powerManager.setOpalPowerState(false); } } getService() { return this.service; } } //# sourceMappingURL=OpalIceBucketStatusSvcManager.js.map