homebridge-melcloud-control 3.8.12 → 3.8.14

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.
package/CHANGELOG.md CHANGED
@@ -16,6 +16,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
16
  - do not configure it manually, always using Config UI X
17
17
  - required Homebridge v2.0.0 and above
18
18
 
19
+ ## [3.8.14] - (26.06.2025)
20
+
21
+ ## Changes
22
+
23
+ - fix [#199](https://github.com/grzegorz914/homebridge-melcloud-control/issues/199)
24
+ - fix [#205](https://github.com/grzegorz914/homebridge-melcloud-control/issues/205)
25
+ - RESTFul code refactor
26
+
27
+ ## [3.8.13] - (26.06.2025)
28
+
29
+ ## Changes
30
+
31
+ - fix [#206](https://github.com/grzegorz914/homebridge-melcloud-control/issues/206)
32
+
19
33
  ## [3.8.6] - (24.05.2025)
20
34
 
21
35
  ## Changes
package/README.md CHANGED
@@ -299,10 +299,11 @@ Homebridge plugin for Air Conditioner, Heat Pump and Energy Recovery Ventilation
299
299
  * Port: last 4 numbers of `device Id`, displayed in HB log during start.
300
300
  * POST data as a JSON Object `{OperationMode: 8}`.
301
301
  * Header content type must be `application/json`.
302
+ * Path `status` response all available paths.
302
303
 
303
304
  | Method | URL | Path | Response | Type |
304
305
  | --- | --- | --- | --- | --- |
305
- | GET | `http//ip:port` | `Info`, `State` | `{"Power": true, "SetTemperature": 21.5}` | JSON object. |
306
+ | GET | `http//ip:port` | `info`, `state` | `{"Power": true, "SetTemperature": 21.5}` | JSON object. |
306
307
 
307
308
  | Method | URL | Key | Value | Type | Description |
308
309
  | --- | --- | --- | --- | --- | --- |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "3.8.12",
4
+ "version": "3.8.14",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/deviceata.js CHANGED
@@ -130,10 +130,10 @@ class DeviceAta extends EventEmitter {
130
130
  this.mqtt1 = new Mqtt({
131
131
  host: this.mqtt.host,
132
132
  port: this.mqtt.port || 1883,
133
- clientId: this.mqtt.clientId || `melcloud_${Math.random().toString(16).slice(3)}`,
134
- prefix: this.mqtt.prefix || `melcloud/${this.deviceTypeText}/${this.deviceName}`,
133
+ clientId: this.mqtt.clientId ? `melcloud_${this.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `melcloud_${Math.random().toString(16).slice(3)}`,
134
+ prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}${this.deviceTypeText}/${this.deviceName}` : `melcloud/${this.deviceTypeText}/${this.deviceName}`,
135
135
  user: this.mqtt.user,
136
- passwd: this.mqtt.pass,
136
+ passwd: this.mqtt.passwd,
137
137
  debug: this.mqtt.debug || false
138
138
  });
139
139
 
package/src/deviceatw.js CHANGED
@@ -135,10 +135,10 @@ class DeviceAtw extends EventEmitter {
135
135
  this.mqtt1 = new Mqtt({
136
136
  host: this.mqtt.host,
137
137
  port: this.mqtt.port || 1883,
138
- clientId: this.mqtt.clientId || `melcloud_${Math.random().toString(16).slice(3)}`,
139
- prefix: this.mqtt.prefix || `melcloud/${this.deviceTypeText}/${this.deviceName}`,
138
+ clientId: this.mqtt.clientId ? `melcloud_${this.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `melcloud_${Math.random().toString(16).slice(3)}`,
139
+ prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}${this.deviceTypeText}/${this.deviceName}` : `melcloud/${this.deviceTypeText}/${this.deviceName}`,
140
140
  user: this.mqtt.user,
141
- passwd: this.mqtt.pass,
141
+ passwd: this.mqtt.passwd,
142
142
  debug: this.mqtt.debug || false
143
143
  });
144
144
 
package/src/deviceerv.js CHANGED
@@ -128,10 +128,10 @@ class DeviceErv extends EventEmitter {
128
128
  this.mqtt1 = new Mqtt({
129
129
  host: this.mqtt.host,
130
130
  port: this.mqtt.port || 1883,
131
- clientId: this.mqtt.clientId || `melcloud_${Math.random().toString(16).slice(3)}`,
132
- prefix: this.mqtt.prefix || `melcloud/${this.deviceTypeText}/${this.deviceName}`,
131
+ clientId: this.mqtt.clientId ? `melcloud_${this.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `melcloud_${Math.random().toString(16).slice(3)}`,
132
+ prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}${this.deviceTypeText}/${this.deviceName}` : `melcloud/${this.deviceTypeText}/${this.deviceName}`,
133
133
  user: this.mqtt.user,
134
- passwd: this.mqtt.pass,
134
+ passwd: this.mqtt.passwd,
135
135
  debug: this.mqtt.debug || false
136
136
  });
137
137
 
package/src/restful.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import express, { json } from 'express';
2
2
  import EventEmitter from 'events';
3
3
 
4
+ const DEFAULT_MESSAGE = 'This data is not available at this time.';
5
+
4
6
  class RestFul extends EventEmitter {
5
7
  constructor(config) {
6
8
  super();
@@ -8,36 +10,53 @@ class RestFul extends EventEmitter {
8
10
  this.restFulDebug = config.debug;
9
11
 
10
12
  this.restFulData = {
11
- info: 'This data is not available at this time.',
12
- state: 'This data is not available at this time.'
13
+ info: DEFAULT_MESSAGE,
14
+ state: DEFAULT_MESSAGE
13
15
  };
14
16
 
15
17
  this.connect();
16
- };
18
+ }
17
19
 
18
20
  connect() {
19
21
  try {
20
- const restFul = express();
21
- restFul.set('json spaces', 2);
22
- restFul.use(json());
22
+ const app = express();
23
+ app.set('json spaces', 2);
24
+ app.use(json());
25
+
26
+ // Register GET routes for all keys
27
+ for (const key of Object.keys(this.restFulData)) {
28
+ app.get(`/${key}`, (req, res) => {
29
+ res.json(this.restFulData[key]);
30
+ });
31
+ }
23
32
 
24
- // GET Routes
25
- restFul.get('/info', (req, res) => { res.json(this.restFulData.info) });
26
- restFul.get('/state', (req, res) => { res.json(this.restFulData.state) });
33
+ // Health check route
34
+ app.get('/status', (req, res) => {
35
+ res.json({
36
+ status: 'online',
37
+ uptime: process.uptime(),
38
+ available_paths: Object.keys(this.restFulData).map(k => `/${k}`)
39
+ });
40
+ });
27
41
 
28
- // POST Route
29
- restFul.post('/', (req, res) => {
42
+ // POST route to update values
43
+ app.post('/', (req, res) => {
30
44
  try {
31
45
  const obj = req.body;
32
46
  if (!obj || typeof obj !== 'object' || Object.keys(obj).length === 0) {
33
- this.emit('warn', `RESTFul Invalid JSON payload`);
47
+ this.emit('warn', 'RESTFul Invalid JSON payload');
34
48
  return res.status(400).json({ error: 'RESTFul Invalid JSON payload' });
35
49
  }
50
+
36
51
  const key = Object.keys(obj)[0];
37
52
  const value = obj[key];
38
53
  this.emit('set', key, value);
54
+ this.update(key, value);
55
+
56
+ if (this.restFulDebug) {
57
+ this.emit('debug', `RESTFul post data: ${JSON.stringify(obj, null, 2)}`);
58
+ }
39
59
 
40
- const emitDebug = this.restFulDebug ? this.emit('debug', `RESTFul post data: ${JSON.stringify(obj, null, 2)}`) : false;
41
60
  res.json({ success: true, received: obj });
42
61
  } catch (error) {
43
62
  this.emit('warn', `RESTFul Parse error: ${error}`);
@@ -45,28 +64,27 @@ class RestFul extends EventEmitter {
45
64
  }
46
65
  });
47
66
 
48
- // Start server
49
- restFul.listen(this.restFulPort, () => {
67
+ // Start the server
68
+ app.listen(this.restFulPort, () => {
50
69
  this.emit('connected', `RESTful started on port: ${this.restFulPort}`);
51
70
  });
52
71
  } catch (error) {
53
- this.emit('warn', `RESTful Connect error: ${error}`)
72
+ this.emit('warn', `RESTful Connect error: ${error}`);
54
73
  }
55
- };
74
+ }
56
75
 
57
76
  update(path, data) {
58
- switch (path) {
59
- case 'info':
60
- this.restFulData.info = data;
61
- break;
62
- case 'state':
63
- this.restFulData.state = data;
64
- break;
65
- default:
66
- this.emit('warn', `Unknown RESTFul update path: ${path}, data: ${data}`)
67
- break;
68
- };
69
- const emitDebug = this.restFulDebug ? this.emit('debug', `RESTFul update path: ${path}, data: ${data}`) : false;
70
- };
71
- };
72
- export default RestFul;
77
+ if (this.restFulData.hasOwnProperty(path)) {
78
+ this.restFulData[path] = data;
79
+ } else {
80
+ this.emit('warn', `Unknown RESTFul update path: ${path}, data: ${JSON.stringify(data)}`);
81
+ return;
82
+ }
83
+
84
+ if (this.restFulDebug) {
85
+ this.emit('debug', `RESTFul update path: ${path}, data: ${JSON.stringify(data)}`);
86
+ }
87
+ }
88
+ }
89
+
90
+ export default RestFul;