UNPKG

homebridge-econet-rheem

Version:

Homebridge plugin based on pyeconet for control of Rheem water heaters

102 lines 3.69 kB
import { EquipmentType } from './constants.js'; import { Equipment } from './equipment.js'; import { RecoverySimulator } from './recoverySimulator.js'; import { getValue } from './types.js'; import strings from '../lang/en.js'; import { fromCelsius } from '../tools/temperature.js'; const DEFAULT_LOWER_LIMIT = 35; const DEFAULT_UPPER_LIMIT = 65; const DEFAULT_SETPOINT = 50; export class WaterHeater extends Equipment { storageFilePath; enabled = true; lower_limit = 0; upper_limit = 0; set_point = 0; availability_icon = null; recoverySimulator = null; constructor(api, data, storageFilePath) { super(api, data); this.storageFilePath = storageFilePath; this.running = data['@RUNNING'] ? data['@RUNNING']?.replace(/\s/g, '').length > 0 : false; this.enabled = data['@ENABLED']?.value === 1; this.lower_limit = data['@SETPOINT']?.constraints.lowerLimit ?? fromCelsius(DEFAULT_LOWER_LIMIT, this.units); this.upper_limit = data['@SETPOINT']?.constraints.upperLimit ?? fromCelsius(DEFAULT_UPPER_LIMIT, this.units); this.set_point = data['@SETPOINT']?.value ?? fromCelsius(DEFAULT_SETPOINT, this.units); this.availability_icon = data['@HOTWATER'] ?? ''; this.didUpdate(); } get type() { return EquipmentType.WATER_HEATER; } get isEnabled() { return this.enabled; } get limits() { return [this.lower_limit, this.upper_limit]; } get availability() { const icon = this.availability_icon; if (icon == null) { return 100; } if (icon.includes('empty') || icon.includes('zero')) { return 0; } if (icon.includes('ten')) { return 10; } if (icon.includes('fourty')) { return 40; } if (icon.includes('hundred') || icon.includes('hundread')) { return 100; } return 100; } currentTemp(inputTemp) { if (!inputTemp) { return this.set_point; } return this.recoverySimulator?.currentTemp(inputTemp) || this.set_point; } get setPoint() { return this.set_point; } didUpdate() { if (!this.recoverySimulator) { this.recoverySimulator = new RecoverySimulator(this, () => { super.didUpdate(); }); } this.recoverySimulator.handleUpdate(this); super.didUpdate(); } updateFromMQTT(data) { super.updateFromMQTT(data); if (data['@ENABLED'] !== undefined) { this.enabled = getValue(data['@ENABLED']) === 1; this.log.ifVerbose(strings.enabledState, this.deviceName, this.enabled); } if (data['@SETPOINT'] !== undefined) { this.set_point = data['@SETPOINT']; this.log.ifVerbose(strings.setpointState, this.deviceName, this.set_point); } if (data['@HOTWATER'] !== undefined) { this.availability_icon = data['@HOTWATER']; this.log.ifVerbose(strings.availabilityState, this.deviceName, this.availability_icon); } if (data['@RUNNING'] !== undefined) { this.running = data['@RUNNING'].replace(/\s/g, '').length > 0; this.log.ifVerbose(strings.runningState, this.deviceName, this.running); } this.didUpdate(); } setEnabled(enabled) { this.publish({ '@ENABLED': enabled ? 1 : 0 }, this.deviceId, this.serialNumber); } setSetPoint(setPoint) { this.publish({ '@SETPOINT': setPoint }, this.deviceId, this.serialNumber); } } //# sourceMappingURL=waterHeater.js.map