homebridge-melcloud-control 4.3.0-beta.13 → 4.3.0-beta.15

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/melcloudata.js +12 -12
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.3.0-beta.13",
4
+ "version": "4.3.0-beta.15",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -27,8 +27,8 @@ class MelCloudAta extends EventEmitter {
27
27
  this.deviceData = {};
28
28
  this.headers = {};
29
29
  this.hash = null;
30
- this.start = true;
31
30
  this.socket = null;
31
+ this.socketConnected = false;
32
32
 
33
33
  //lock flag
34
34
  this.locks = false;
@@ -81,12 +81,8 @@ class MelCloudAta extends EventEmitter {
81
81
  deviceData.Device.VaneVerticalDirection = AirConditioner.VaneVerticalDirectionMapStringToEnum[deviceData.Device.VaneVerticalDirection] ?? deviceData.Device.VaneVerticalDirection;
82
82
  deviceData.Device.VaneHorizontalDirection = AirConditioner.VaneHorizontalDirectionMapStringToEnum[deviceData.Device.VaneHorizontalDirection] ?? deviceData.Device.VaneHorizontalDirection;
83
83
 
84
- //read default temps
85
- const temps = await this.functions.readData(this.defaultTempsFile, true);
86
- deviceData.Device.DefaultHeatingSetTemperature = temps?.defaultHeatingSetTemperature ?? 20;
87
- deviceData.Device.DefaultCoolingSetTemperature = temps?.defaultCoolingSetTemperature ?? 24;
88
84
 
89
- if (this.start) {
85
+ if (!this.socketConnected) {
90
86
  const socket = new WebSocket(`wss://ws.melcloudhome.com/?hash=${devicesData.Hash}`, {
91
87
  headers: {
92
88
  'Origin': 'https://melcloudhome.com',
@@ -107,7 +103,6 @@ class MelCloudAta extends EventEmitter {
107
103
  this.socket = socket;
108
104
  this.socketConnected = true;
109
105
  this.emit('success', `Socket Connect Success`);
110
- this.start = false;
111
106
 
112
107
  // start heartbeat
113
108
  this.heartbeat = setInterval(() => {
@@ -124,22 +119,27 @@ class MelCloudAta extends EventEmitter {
124
119
  const parsedMessage = JSON.parse(message);
125
120
  const messageType = parsedMessage[0].messageType;
126
121
  const messageData = parsedMessage[0].Data;
122
+ const unitId = messageData.id;
123
+ const unitType = messageData.unitType;
127
124
  const stringifyMessage = JSON.stringify(parsedMessage, null, 2);
128
125
  if (!this.logDebug) this.emit('warn', `Incoming message:', ${stringifyMessage}`);
129
126
 
130
- switch (messageType) {
131
- case 'unitStateChanged':
132
- const unitId = messageData.id;
133
- const unitType = messageData.unitType;
127
+ switch (unitId) {
128
+ case this.deviceId:
134
129
  const settings = messageData.settings[0];
135
130
  const name = settings.name;
136
131
  const value = settings.value;
137
- if (this.deviceId === unitId) deviceData.Device[name] = value;
132
+ deviceData.Device[name] = value;
138
133
  break;
139
134
  }
140
135
  });
141
136
  }
142
137
 
138
+ //read default temps
139
+ const temps = await this.functions.readData(this.defaultTempsFile, true);
140
+ deviceData.Device.DefaultHeatingSetTemperature = temps?.defaultHeatingSetTemperature ?? 20;
141
+ deviceData.Device.DefaultCoolingSetTemperature = temps?.defaultCoolingSetTemperature ?? 24;
142
+
143
143
  }
144
144
  if (this.logDebug) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
145
145