UNPKG

@homebridge-plugins/homebridge-smarthq

Version:

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

84 lines 4.03 kB
import { deviceBase } from './device.js'; export class SmartHQClothesWasher extends deviceBase { ClothesWasher; constructor(platform, accessory, device) { super(platform, accessory, device); this.debugLog(`Clothes Washer Features: ${JSON.stringify(accessory.context.device.features)}`); // Initialize ClothesWasher state (restore from cache if available) this.ClothesWasher = { On: accessory.context.ClothesWasher?.On ?? false, }; // Washer Running State (Valve) const washerValve = this.accessory.getService('Washer') ?? this.accessory.addService(this.platform.Service.Valve, 'Washer', 'Washer'); washerValve.setCharacteristic(this.platform.Characteristic.Name, 'Washer'); washerValve.setCharacteristic(this.platform.Characteristic.ValveType, this.platform.Characteristic.ValveType.GENERIC_VALVE); washerValve .getCharacteristic(this.platform.Characteristic.Active) .onGet(async () => { try { return this.ClothesWasher?.On ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE; } catch (error) { this.warnLog(`Washer Active error: ${error?.message ?? error}`); return this.platform.Characteristic.Active.INACTIVE; } }) .onSet(this.handleSetOn.bind(this)); washerValve .getCharacteristic(this.platform.Characteristic.InUse) .onGet(async () => { try { return this.ClothesWasher?.On ? this.platform.Characteristic.InUse.IN_USE : this.platform.Characteristic.InUse.NOT_IN_USE; } catch (error) { this.warnLog(`Washer InUse error: ${error?.message ?? error}`); return this.platform.Characteristic.InUse.NOT_IN_USE; } }); // Door Lock const doorLock = this.accessory.getService('Washer Door Lock') ?? this.accessory.addService(this.platform.Service.LockMechanism, 'Washer Door Lock', 'WasherDoorLock'); doorLock.setCharacteristic(this.platform.Characteristic.Name, 'Washer Door Lock'); doorLock .getCharacteristic(this.platform.Characteristic.LockCurrentState) .onGet(async () => { try { // TODO: Implement door lock state when ERD available return this.platform.Characteristic.LockCurrentState.UNSECURED; } catch (error) { this.warnLog(`Washer Door Lock error: ${error?.message ?? error}`); return this.platform.Characteristic.LockCurrentState.UNSECURED; } }); doorLock .getCharacteristic(this.platform.Characteristic.LockTargetState) .onGet(async () => this.platform.Characteristic.LockTargetState.UNSECURED) .onSet(async (value) => { this.debugLog(`Washer Door Lock set to: ${value}`); }); } async handleGetOn() { try { // TODO: Replace with actual ERD code for washer On state if available // const erdValue = await this.readErd(ERD_TYPES.CLOTHES_WASHER_ON) // return Number.parseInt(erdValue) !== 0 return this.ClothesWasher?.On ?? false; } catch (error) { this.warnLog(`ClothesWasher handleGetOn error: ${error?.message ?? error}`); return false; } } async handleSetOn(value) { try { // TODO: Replace with actual ERD code for washer On state if available // await this.writeErd(ERD_TYPES.CLOTHES_WASHER_ON, value as boolean) this.ClothesWasher.On = value; this.accessory.context.ClothesWasher = this.ClothesWasher; } catch (error) { this.warnLog(`ClothesWasher handleSetOn error: ${error?.message ?? error}`); } } } //# sourceMappingURL=clothesWasher.js.map