homebridge-tesy-heater-api-v4 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/index.js +137 -0
  4. package/package.json +20 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 mpopof
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # homebridge-tesy-heater-api-v4
2
+ this is a clone/upgrade to https://github.com/benov84/homebridge-tesy-heater#readme for the newer tesy api
3
+
4
+ # Homebridge Tesy Heater (v2)
5
+
6
+ Homebridge plugin for Tesy smart heaters using the new v4 API.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ #git clone https://github.com/YOUR-USERNAME/homebridge-tesy-heater.git
12
+ git clone https://github.com/mpopof/homebridge-tesy-heater-api-v4
13
+ cd homebridge-tesy-heater-api-v4
14
+ npm install
15
+ sudo npm link
package/index.js ADDED
@@ -0,0 +1,137 @@
1
+ const axios = require("axios");
2
+ const _http_base = require("homebridge-http-base");
3
+ const PullTimer = _http_base.PullTimer;
4
+
5
+ let Service, Characteristic;
6
+
7
+ module.exports = function (homebridge) {
8
+ Service = homebridge.hap.Service;
9
+ Characteristic = homebridge.hap.Characteristic;
10
+ homebridge.registerAccessory("homebridge-tesy-heater-v2", "TesyHeater", TesyHeater);
11
+ };
12
+
13
+ class TesyHeater {
14
+ constructor(log, config) {
15
+ this.log = log;
16
+ this.name = config.name;
17
+ this.manufacturer = config.manufacturer || "Tesy";
18
+ this.model = config.model || "Convector (Heater)";
19
+ this.device_id = config.device_id;
20
+ this.pullInterval = config.pullInterval || 10000;
21
+ this.maxTemp = config.maxTemp || 30;
22
+ this.minTemp = config.minTemp || 10;
23
+ this.username = config.username || null;
24
+ this.password = config.password || null;
25
+ this.session = "";
26
+ this.alt = "";
27
+
28
+ if (this.username && this.password) {
29
+ this.authenticate();
30
+ }
31
+
32
+ this.service = new Service.HeaterCooler(this.name);
33
+ this.pullTimer = new PullTimer(
34
+ this.log,
35
+ this.pullInterval,
36
+ this.refreshTesyHeaterStatus.bind(this),
37
+ () => {}
38
+ );
39
+ this.pullTimer.start();
40
+ }
41
+
42
+ async authenticate() {
43
+ try {
44
+ const response = await axios.post("https://v4.mytesy.com/auth/login", {
45
+ email: this.username,
46
+ password: this.password,
47
+ });
48
+ this.session = response.data.session_token;
49
+ this.alt = response.data.alt_key;
50
+ this.log.info("Successfully authenticated with Tesy API");
51
+ } catch (error) {
52
+ this.log.error("Authentication failed:", error.response?.data || error.message);
53
+ }
54
+ }
55
+
56
+ async refreshTesyHeaterStatus() {
57
+ this.log.debug("Refreshing heater status");
58
+ try {
59
+ const response = await axios.post("https://v4.mytesy.com/devices/status", {
60
+ session_token: this.session,
61
+ device_id: this.device_id,
62
+ });
63
+
64
+ const status = response.data.device_status;
65
+ this.updateDeviceStatus(status);
66
+ } catch (error) {
67
+ this.log.error("Failed to refresh heater status:", error.response?.data || error.message);
68
+ }
69
+ }
70
+
71
+ updateDeviceStatus(status) {
72
+ const newCurrentTemperature = parseFloat(status.temperature);
73
+ this.service.getCharacteristic(Characteristic.CurrentTemperature).updateValue(newCurrentTemperature);
74
+
75
+ const newHeatingThresholdTemperature = parseFloat(status.target_temperature);
76
+ this.service.getCharacteristic(Characteristic.HeatingThresholdTemperature).updateValue(newHeatingThresholdTemperature);
77
+
78
+ const isActive = status.power === "on" ? Characteristic.Active.ACTIVE : Characteristic.Active.INACTIVE;
79
+ this.service.getCharacteristic(Characteristic.Active).updateValue(isActive);
80
+ }
81
+
82
+ async setActive(value, callback) {
83
+ this.log.info("Setting heater state:", value);
84
+ try {
85
+ await axios.post("https://v4.mytesy.com/devices/set", {
86
+ session_token: this.session,
87
+ device_id: this.device_id,
88
+ command: "power",
89
+ value: value === 0 ? "off" : "on",
90
+ });
91
+ callback(null, value);
92
+ } catch (error) {
93
+ this.log.error("Failed to set heater state:", error.response?.data || error.message);
94
+ callback(error);
95
+ }
96
+ }
97
+
98
+ async setHeatingThresholdTemperature(value, callback) {
99
+ this.log.info("Setting target temperature to:", value);
100
+ try {
101
+ await axios.post("https://v4.mytesy.com/devices/set", {
102
+ session_token: this.session,
103
+ device_id: this.device_id,
104
+ command: "target_temperature",
105
+ value: value,
106
+ });
107
+ callback(null, value);
108
+ } catch (error) {
109
+ this.log.error("Failed to set target temperature:", error.response?.data || error.message);
110
+ callback(error);
111
+ }
112
+ }
113
+
114
+ getServices() {
115
+ this.informationService = new Service.AccessoryInformation();
116
+ this.informationService
117
+ .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
118
+ .setCharacteristic(Characteristic.Model, this.model)
119
+ .setCharacteristic(Characteristic.SerialNumber, this.device_id);
120
+
121
+ this.service.getCharacteristic(Characteristic.Active)
122
+ .on("set", this.setActive.bind(this));
123
+
124
+ this.service.getCharacteristic(Characteristic.CurrentTemperature)
125
+ .setProps({ minStep: 0.1 });
126
+
127
+ this.service.getCharacteristic(Characteristic.HeatingThresholdTemperature)
128
+ .setProps({
129
+ minValue: this.minTemp,
130
+ maxValue: this.maxTemp,
131
+ minStep: 0.5,
132
+ })
133
+ .on("set", this.setHeatingThresholdTemperature.bind(this));
134
+
135
+ return [this.informationService, this.service];
136
+ }
137
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "homebridge-tesy-heater-api-v4",
3
+ "version": "0.0.1",
4
+ "description": "Homebridge plugin for Tesy Heater (updated APIv4)",
5
+ "main": "index.js",
6
+ "keywords": [
7
+ "homebridge-plugin",
8
+ "homebridge",
9
+ "tesy",
10
+ "heater"
11
+ ],
12
+ "engines": {
13
+ "node": ">=16.0.0",
14
+ "homebridge": ">=1.6.0"
15
+ },
16
+ "dependencies": {
17
+ "axios": "^1.7.0",
18
+ "homebridge-http-base": "^1.0.0"
19
+ }
20
+ }