UNPKG

hottohts

Version:

TypeScript library for HottoH pellet stoves

785 lines 26.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Hottoh = void 0; /** * hottohts - High-level API for HottoH pellet stoves * * Provides a user-friendly interface for reading and controlling HottoH stoves. * All methods, constants, and logic are ported 1:1 from Hottohpy for deterministic parity. * * @module hottoht */ const client_1 = require("./client"); const const_1 = require("./const"); /** * High-level API for HottoH stoves. Use this class for all stove operations. * * Example: * const stove = new Hottoh('192.168.1.100', 5001); * stove.connect(); * // ... */ class Hottoh { constructor(address, port, id = 0) { this._isDisposed = false; this.port = port; this.address = address; this.client = new client_1.HottohRemoteClient(this.address, this.port, id); } /** * Connect to the stove and start polling */ connect() { if (this._isDisposed) { // If already disposed, recreate the client this.client = new client_1.HottohRemoteClient(this.address, this.port); this._isDisposed = false; } this.client.start(); } /** * Disconnect from the stove and stop polling */ disconnect() { this.client.stop(); } /** * Properly dispose all resources to prevent memory leaks * Call this when completely done with the Hottoh instance */ dispose() { if (this._isDisposed) return; this.disconnect(); this.client.dispose(); this._isDisposed = true; } isConnected() { return this.client.isConnected(); } _extractData(data) { return data.split(';'); } _getMac() { return "aabbccddeeff"; } setTemperature(value) { return new Promise((resolve, reject) => { try { this.client.sendCommand([ String(const_1.StoveCommands.PARAM_AMBIANCE_TEMPERATURE_1), String(value * 10), ]); resolve(true); } catch (err) { reject(err); } }); } // --- Internal data accessors (1:1 with Python) --- _getFirmwareVersion() { if (!this.client['_info']) return null; return this.client['_info'][const_1.StoveRegisters.INDEX_FW]; } _getWifiSignal() { if (!this.client['_info']) return null; return this.client['_info'][const_1.StoveRegisters.INDEX_WIFI]; } _getPageIndex() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_PAGE]; } _getManufacturer() { if (!this.client['_data']) return null; if (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_MANUFACTURER]) === const_1.StoveManufacturer.STOVE_MANUFACTURER_CMG) return "CMG"; if (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_MANUFACTURER]) === const_1.StoveManufacturer.STOVE_MANUFACTURER_EDILKAMIN) return "EdilKamin"; return this.client['_data'][const_1.StoveRegisters.INDEX_MANUFACTURER]; } _getIsBitmapVisible() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_BITMAP_VISIBLE]; } _getIsValid() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_VALID]; } _getStoveType() { if (!this.client['_data']) return null; return parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_STOVE_TYPE]); } _getStoveState() { if (!this.client['_data']) return "not_connected"; const state = parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_STOVE_STATE]); switch (state) { case const_1.StoveState.STATUS_OFF: return "switched_off"; case const_1.StoveState.STATUS_STARTING_1: return "starting_1_check"; case const_1.StoveState.STATUS_STARTING_2: return "starting_2_clean_all"; case const_1.StoveState.STATUS_STARTING_3: return "starting_3_loading"; case const_1.StoveState.STATUS_STARTING_4: return "starting_4_waiting"; case const_1.StoveState.STATUS_STARTING_5: return "starting_5_waiting"; case const_1.StoveState.STATUS_STARTING_6: return "starting_6_ignition"; case const_1.StoveState.STATUS_STARTING_7: return "starting_7_stabilization"; case const_1.StoveState.STATUS_POWER: return "power"; case const_1.StoveState.STATUS_STOPPING_1: return "stopping_1_wait_standby"; case const_1.StoveState.STATUS_STOPPING_2: return "stopping_2_wait_standby"; case const_1.StoveState.STATUS_ECO_STOP_1: return "eco_stop_1_standby"; case const_1.StoveState.STATUS_ECO_STOP_2: return "eco_stop_2"; case const_1.StoveState.STATUS_ECO_STOP_3: return "eco_stop_3"; case const_1.StoveState.STATUS_LOW_PELLET: return "low_pellet"; case const_1.StoveState.STATUS_END_PELLET: return "end_pellet"; case const_1.StoveState.STATUS_BLACK_OUT: return "black_out"; case const_1.StoveState.STATUS_INGNITION_FAILED: return "error_ignition_failed"; case const_1.StoveState.STATUS_ANTI_FREEZE: return "anti_freeze"; case const_1.StoveState.STATUS_COVER_OPEN: return "error_cover_open"; case const_1.StoveState.STATUS_NO_PELLET: return "error_no_pellet"; default: return this.client['_data'][const_1.StoveRegisters.INDEX_STOVE_STATE]; } } _getStoveIsOn() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_STOVE_ON] === "1" ? "on" : "off"; } _getEcoMode() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_ECO_MODE] === "1" ? "on" : "off"; } _getChronoMode() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_TIMER_ON] === "1" ? "on" : "off"; } _getTemperatureRoom1() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_AMBIENT_T1]) / 10).toString(); } _getSetTemperatureRoom1() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_AMBIENT_T1_SET]) / 10).toString(); } _getSetMaxTemperatureRoom1() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_AMBIENT_T1_SET_MAX]) / 10).toString(); } _getSetMinTemperatureRoom1() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_AMBIENT_T1_SET_MIN]) / 10).toString(); } _getTemperatureRoom2() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_AMBIENT_T2]) / 10).toString(); } _getSetTemperatureRoom2() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_AMBIENT_T2_SET]) / 10).toString(); } _getSetMaxTemperatureRoom2() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_AMBIENT_T2_SET_MAX]) / 10).toString(); } _getSetMinTemperatureRoom2() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_AMBIENT_T2_SET_MIN]) / 10).toString(); } _getTemperatureRoom3() { if (!this.client['_data2']) return null; return (parseInt(this.client['_data2'][const_1.StoveRegisters.INDEX_ROOM_TEMP_3]) / 10).toString(); } _getSetTemperatureRoom3() { if (!this.client['_data2']) return null; return (parseInt(this.client['_data2'][const_1.StoveRegisters.INDEX_ROOM_TEMP_3_SET]) / 10).toString(); } _getSetMaxTemperatureRoom3() { if (!this.client['_data2']) return null; return (parseInt(this.client['_data2'][const_1.StoveRegisters.INDEX_ROOM_TEMP_3_SET_MAX]) / 10).toString(); } _getSetMinTemperatureRoom3() { if (!this.client['_data2']) return null; return (parseInt(this.client['_data2'][const_1.StoveRegisters.INDEX_ROOM_TEMP_3_SET_MIN]) / 10).toString(); } _getTemperatureWater() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_WATER]) / 10).toString(); } _getSetTemperatureWater() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_WATER_SET]) / 10).toString(); } _getSetMaxTemperatureWater() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_WATER_SET_MAX]) / 10).toString(); } _getSetMinTemperatureWater() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_WATER_SET_MIN]) / 10).toString(); } _getSmokeTemperature() { if (!this.client['_data']) return null; return (parseInt(this.client['_data'][const_1.StoveRegisters.INDEX_SMOKE_T]) / 10).toString(); } _getPowerLevel() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_POWER_LEVEL]; } _getSetPowerLevel() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_POWER_SET]; } _getSetMaxPowerLevel() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_POWER_MAX]; } _getSetMinPowerLevel() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_POWER_MIN]; } _getSpeedFanSmoke() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_SMOKE]; } _getSpeedFan1() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_1]; } _getSetSpeedFan1() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_1_SET]; } _getSetMaxSpeedFan1() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_1_SET_MAX]; } _getSpeedFan2() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_2]; } _getSetSpeedFan2() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_2_SET]; } _getSetMaxSpeedFan2() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_2_SET_MAX]; } _getSpeedFan3() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_3]; } _getSetSpeedFan3() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_3_SET]; } _getSetMaxSpeedFan3() { if (!this.client['_data']) return null; return this.client['_data'][const_1.StoveRegisters.INDEX_FAN_3_SET_MAX]; } _getFlowSwitch() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_FLOW_SWITCH]; } _getGenericPump() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_GENERIC_PUMP]; } _getAirEx1() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_AIREX_1]; } _getAirEx2() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_AIREX_2]; } _getAirEx3() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_AIREX_3]; } _getPuffer() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_PUFFER]; } _getSetPuffer() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_PUFFER_SET]; } _getSetMinPuffer() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_PUFFER_SET_MIN]; } _getSetMaxPuffer() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_PUFFER_SET_MAX]; } _getBoiler() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_BOILER]; } _getSetBoiler() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_BOILER_SET]; } _getSetMinBoiler() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_BOILER_SET_MIN]; } _getSetMaxBoiler() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_BOILER_SET_MAX]; } _getDhw() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_DHW]; } _getSetDhw() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_DHW_SET]; } _getSetMinDhw() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_DHW_SET_MIN]; } _getSetMaxDhw() { if (!this.client['_data2']) return null; return this.client['_data2'][const_1.StoveRegisters.INDEX_DHW_SET_MAX]; } // --- Setters (1:1 with Python) --- setWaterTemperature(value) { try { return this.client.sendCommand([ String(const_1.StoveCommands.INCONNU_4), String(value * 10), ]); } catch (e) { throw e; } } setPowerLevel(value) { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_NIVEAU_PUISSANCE), String(value), ]); } catch (e) { throw e; } } setSpeedFan1(value) { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_NIVEAU_FAN_1), String(value), ]); } catch (e) { throw e; } } setSpeedFan2(value) { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_NIVEAU_FAN_2), String(value), ]); } catch (e) { throw e; } } setSpeedFan3(value) { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_NIVEAU_FAN_3), String(value), ]); } catch (e) { throw e; } } setEcoModeOn() { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_ECO_MODE), "1", ]); } catch (e) { throw e; } } setEcoModeOff() { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_ECO_MODE), "0", ]); } catch (e) { throw e; } } setChronoModeOn() { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_CHRONO_ON_OFF), "1", ]); } catch (e) { throw e; } } setChronoModeOff() { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_CHRONO_ON_OFF), "0", ]); } catch (e) { throw e; } } setOn() { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_ON_OFF), "1", ]); } catch (e) { throw e; } } setOff() { try { return this.client.sendCommand([ String(const_1.StoveCommands.PARAM_ON_OFF), "0", ]); } catch (e) { throw e; } } // --- High-level getters (1:1 with Python) --- getSmokeTemperature() { const v = this._getSmokeTemperature(); return v !== null ? parseFloat(v) : null; } getWaterTemperature() { const v = this._getTemperatureWater(); return v !== null ? parseFloat(v) : null; } getSetWaterTemperature() { const v = this._getSetTemperatureWater(); return v !== null ? parseFloat(v) : null; } getSetMinWaterTemperature() { const v = this._getSetMinTemperatureWater(); return v !== null ? parseFloat(v) : null; } getSetMaxWaterTemperature() { const v = this._getSetMaxTemperatureWater(); return v !== null ? parseFloat(v) : null; } getSpeedFanSmoke() { const v = this._getSpeedFanSmoke(); return v !== null ? parseFloat(v) : null; } getTemperatureRoom1() { const v = this._getTemperatureRoom1(); return v !== null ? parseFloat(v) : null; } getSetTemperatureRoom1() { const v = this._getSetTemperatureRoom1(); return v !== null ? parseFloat(v) : null; } getSetMinTemperatureRoom1() { const v = this._getSetMinTemperatureRoom1(); return v !== null ? parseFloat(v) : null; } getSetMaxTemperatureRoom1() { const v = this._getSetMaxTemperatureRoom1(); return v !== null ? parseFloat(v) : null; } getTemperatureRoom2() { const v = this._getTemperatureRoom2(); return v !== null ? parseFloat(v) : null; } getSetTemperatureRoom2() { const v = this._getSetTemperatureRoom2(); return v !== null ? parseFloat(v) : null; } getSetMinTemperatureRoom2() { const v = this._getSetMinTemperatureRoom2(); return v !== null ? parseFloat(v) : null; } getSetMaxTemperatureRoom2() { const v = this._getSetMaxTemperatureRoom2(); return v !== null ? parseFloat(v) : null; } getTemperatureRoom3() { const v = this._getTemperatureRoom3(); return v !== null ? parseFloat(v) : null; } getSetTemperatureRoom3() { const v = this._getSetTemperatureRoom3(); return v !== null ? parseFloat(v) : null; } getSetMinTemperatureRoom3() { const v = this._getSetMinTemperatureRoom3(); return v !== null ? parseFloat(v) : null; } getSetMaxTemperatureRoom3() { const v = this._getSetMaxTemperatureRoom3(); return v !== null ? parseFloat(v) : null; } getSpeedFan1() { const v = this._getSpeedFan1(); return v !== null ? parseInt(v) : null; } getSetSpeedFan1() { const v = this._getSetSpeedFan1(); return v !== null ? parseInt(v) : null; } getSetMaxSpeedFan1() { const v = this._getSetMaxSpeedFan1(); return v !== null ? parseInt(v) : null; } getSpeedFan2() { const v = this._getSpeedFan2(); return v !== null ? parseFloat(v) : null; } getSetSpeedFan2() { const v = this._getSetSpeedFan2(); return v !== null ? parseFloat(v) : null; } getSetMaxSpeedFan2() { const v = this._getSetMaxSpeedFan2(); return v !== null ? parseFloat(v) : null; } getSpeedFan3() { const v = this._getSpeedFan3(); return v !== null ? parseFloat(v) : null; } getSetSpeedFan3() { const v = this._getSetSpeedFan3(); return v !== null ? parseFloat(v) : null; } getSetMaxSpeedFan3() { const v = this._getSetMaxSpeedFan3(); return v !== null ? parseFloat(v) : null; } getPowerLevel() { const v = this._getPowerLevel(); return v !== null ? parseFloat(v) : null; } getSetPowerLevel() { const v = this._getSetPowerLevel(); return v !== null ? parseFloat(v) : null; } getSetMinPowerLevel() { const v = this._getSetMinPowerLevel(); return v !== null ? parseFloat(v) : null; } getSetMaxPowerLevel() { const v = this._getSetMaxPowerLevel(); return v !== null ? parseFloat(v) : null; } getAirEx1() { const v = this._getAirEx1(); return v !== null ? parseFloat(v) : null; } getAirEx2() { const v = this._getAirEx2(); return v !== null ? parseFloat(v) : null; } getAirEx3() { const v = this._getAirEx3(); return v !== null ? parseFloat(v) : null; } getAction() { const state = this._getStoveState(); if (["switched_off", "black_out", "eco_stop_2", "eco_stop_3"].includes(state || "")) return "off"; if (["starting_1_check"].includes(state || "")) return "check"; if (["starting_2_clean_all"].includes(state || "")) return "clean_all"; if (["starting_3_loading"].includes(state || "")) return "loading"; if (["starting_4_waiting", "starting_5_waiting"].includes(state || "")) return "waiting"; if (["starting_6_ignition"].includes(state || "")) return "ignition"; if (["starting_7_stabilization"].includes(state || "")) return "stabilization"; if (["power"].includes(state || "")) return "heating"; if (["stopping_1_wait_standby", "stopping_2_wait_standby"].includes(state || "")) return "stopping"; if (["eco_stop_1_standby", "standby"].includes(state || "")) return "idle"; return state; } getIsOn() { return this._getStoveIsOn() === "on"; } getEcoMode() { return this._getEcoMode() === "on"; } getChronoMode() { return this._getChronoMode() === "on"; } getMode() { return this._getStoveIsOn(); } getName() { const m = this.getManufacturer(); if (m === null) return null; return "Stove " + m; } getFirmware() { return this._getFirmwareVersion(); } getWifi() { return this._getWifiSignal(); } getManufacturer() { return this._getManufacturer(); } getWaterPump() { const v = this._getGenericPump(); if (v === null) return null; return parseInt(v) !== 0; } // --- Bitfield/feature methods (1:1 with Python) --- _getStoveTypeBitArray() { const type = this._getStoveType(); if (type === null) return Array(16).fill(false); // Convert to 16-bit boolean array (Python BitArray equivalent) const bits = []; for (let i = 15; i >= 0; i--) { bits.push(((type >> i) & 1) === 1); } return bits; } isBoilerEnabled() { return this._getStoveTypeBitArray()[6]; // Python: type[9], but JS is MSB first } isDomesticHotWaterEnabled() { return this._getStoveTypeBitArray()[5]; // Python: type[10] } getFanNumber() { const bits = this._getStoveTypeBitArray(); // Python: nb = type[12:14]; nb.int // JS: bits[2] (MSB), bits[3] (LSB) return (bits[2] ? 2 : 0) + (bits[3] ? 1 : 0); } isTempRoom1Enabled() { return this._getStoveTypeBitArray()[0]; // Python: type[15] } isTempRoom2Enabled() { return this._getStoveTypeBitArray()[7]; // Python: type[8] } isTempRoom3Enabled() { return this._getStoveTypeBitArray()[8]; // Python: type[7] } isTempWaterEnabled() { return this._getStoveTypeBitArray()[1]; // Python: type[14] } isPumpEnabled() { return this._getStoveTypeBitArray()[11]; // Python: type[4] } isFlowSwitchEnabled() { return this._getStoveTypeBitArray()[10]; // Python: type[5] } isPufferEnabled() { return this._getStoveTypeBitArray()[9]; // Python: type[6] } isBoilerTempEnabled() { return this._getStoveTypeBitArray()[4]; // Python: type[11] } isDhwEnabled() { return this._getStoveTypeBitArray()[3]; // Python: type[12] } isAirEx1Enabled() { return this._getStoveTypeBitArray()[12]; // Python: type[3] } isAirEx2Enabled() { return this._getStoveTypeBitArray()[13]; // Python: type[2] } isAirEx3Enabled() { return this._getStoveTypeBitArray()[14]; // Python: type[1] } isGenericPumpEnabled() { return this._getStoveTypeBitArray()[15]; // Python: type[0] } } exports.Hottoh = Hottoh; //# sourceMappingURL=hottoht.js.map