homebridge-gree-ac 1.0.2 → 2.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 (46) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +176 -21
  3. package/README.md +189 -42
  4. package/config.schema.json +277 -0
  5. package/dist/commands.d.ts +121 -0
  6. package/dist/commands.d.ts.map +1 -0
  7. package/dist/commands.js +123 -0
  8. package/dist/commands.js.map +1 -0
  9. package/dist/crypto.d.ts +6 -0
  10. package/dist/crypto.d.ts.map +1 -0
  11. package/dist/crypto.js +19 -0
  12. package/dist/crypto.js.map +1 -0
  13. package/dist/index.d.ts +7 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +7 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/platform.d.ts +35 -0
  18. package/dist/platform.d.ts.map +1 -0
  19. package/dist/platform.js +205 -0
  20. package/dist/platform.js.map +1 -0
  21. package/dist/platformAccessory.d.ts +90 -0
  22. package/dist/platformAccessory.d.ts.map +1 -0
  23. package/dist/platformAccessory.js +912 -0
  24. package/dist/platformAccessory.js.map +1 -0
  25. package/dist/settings.d.ts +52 -0
  26. package/dist/settings.d.ts.map +1 -0
  27. package/dist/settings.js +51 -0
  28. package/dist/settings.js.map +1 -0
  29. package/dist/tsAccessory.d.ts +36 -0
  30. package/dist/tsAccessory.d.ts.map +1 -0
  31. package/dist/tsAccessory.js +65 -0
  32. package/dist/tsAccessory.js.map +1 -0
  33. package/greedevice.jpg +0 -0
  34. package/greemac.jpg +0 -0
  35. package/package.json +51 -23
  36. package/uiconfig.jpg +0 -0
  37. package/.idea/homebridge-gree-ac.iml +0 -12
  38. package/.idea/misc.xml +0 -6
  39. package/.idea/modules.xml +0 -8
  40. package/.idea/vcs.xml +0 -6
  41. package/.idea/workspace.xml +0 -208
  42. package/app/commandEnums.js +0 -135
  43. package/app/deviceFactory.js +0 -306
  44. package/app/encryptionService.js +0 -39
  45. package/example.config.json +0 -28
  46. package/index.js +0 -373
@@ -1,28 +0,0 @@
1
- {
2
- "bridge": {
3
- "name": "Homebridge",
4
- "username": "CC:22:3D:E3:CE:30",
5
- "port": 51826,
6
- "pin": "123-45-568"
7
- },
8
- "accessories": [
9
- {
10
- "accessory": "GreeAC",
11
- "host": "192.168.1.1",
12
- "name": "Office AC",
13
- "debug": "false",
14
- "updateInterval": 10000,
15
- "mqttUrl": "mqtt://127.0.0.1",
16
- "currentTempTopic": "home/office/temperature"
17
- },
18
- {
19
- "accessory": "GreeAC",
20
- "host": "192.168.1.2",
21
- "name": "Bedroom AC",
22
- "debug": "false",
23
- "updateInterval": 10000,
24
- "mqttUrl": "mqtt://127.0.0.1",
25
- "currentTempTopic": "home/bedroom/temperature"
26
- }
27
- ]
28
- }
package/index.js DELETED
@@ -1,373 +0,0 @@
1
- const commands = require('./app/commandEnums');
2
- var Service, Characteristic;
3
- var mqtt = require('mqtt');
4
-
5
-
6
- module.exports = function (homebridge) {
7
- Service = homebridge.hap.Service;
8
- Characteristic = homebridge.hap.Characteristic;
9
- homebridge.registerAccessory('homebridge-gree-ac', 'GreeAC', GreeAC);
10
- }
11
-
12
- function GreeAC(log, config) {
13
-
14
- this.log = log;
15
- this.name = config.name;
16
- this.host = config.host;
17
- this.debug = ((config.debug || "false") === "true");
18
- this.updateInterval = config.updateInterval || 10000;
19
- this.currentTempTopic = config['currentTempTopic'] || "hvac/temperature";
20
- this.mqttUrl = config['mqttUrl'];
21
- this.client_Id = 'mqttjs_' + Math.random().toString(16).substr(2, 8);
22
- this.model = config.acModel || "Gree AC";
23
-
24
- this.mqttOptions = {
25
- keepalive: 10,
26
- clientId: this.client_Id,
27
- protocolId: 'MQTT',
28
- protocolVersion: 4,
29
- clean: true,
30
- reconnectPeriod: 1000,
31
- connectTimeout: 30 * 1000,
32
- serialnumber: config["serial"] || this.client_Id,
33
- max_temperature: config["maxTemperature"] || 100,
34
- min_temperature: config["minTemperature"] || -50,
35
- username: config["username"],
36
- password: config["password"],
37
- will: {
38
- topic: 'WillMsg',
39
- payload: 'Connection Closed abnormally..!',
40
- qos: 0,
41
- retain: false
42
- },
43
- rejectUnauthorized: false
44
- };
45
-
46
- if (this.mqttUrl) {
47
- this.client = mqtt.connect(this.mqttUrl, this.mqttOptions);
48
- }
49
-
50
- this.TargetHeatingCoolingState = Characteristic.TargetHeatingCoolingState.OFF;
51
- this.TargetTemperature = 22;
52
- this.CurrentTemperature = 0;
53
- this.services = [];
54
-
55
- this.GreeACService = new Service.Thermostat(this.name);
56
- this.temperatureDisplayUnits = Characteristic.TemperatureDisplayUnits.CELSIUS;
57
-
58
- this.GreeACService
59
- .getCharacteristic(Characteristic.TemperatureDisplayUnits)
60
- .on('get', this.getTemperatureDisplayUnits.bind(this))
61
- .on('set', this.setTemperatureDisplayUnits.bind(this));
62
-
63
- this.GreeACService
64
- .getCharacteristic(Characteristic.TargetHeatingCoolingState)
65
- .on('set', this.setTargetHeatingCoolingState.bind(this))
66
- .on('get', this.getTargetHeatingCoolingState.bind(this));
67
-
68
- this.GreeACService
69
- .getCharacteristic(Characteristic.CurrentHeatingCoolingState)
70
- .on('get', this.getTargetHeatingCoolingState.bind(this));
71
-
72
- this.GreeACService
73
- .getCharacteristic(Characteristic.TargetTemperature)
74
- .setProps({
75
- maxValue: 30,
76
- minValue: 16,
77
- minStep: 1
78
- })
79
- .on('set', this.setTargetTemperature.bind(this))
80
- .on('get', this.getTargetTemperature.bind(this));
81
-
82
- this.GreeACService
83
- .getCharacteristic(Characteristic.CurrentTemperature)
84
- .setProps({
85
- maxValue: 30,
86
- minValue: 16,
87
- minStep: 1
88
- })
89
- .on('get', this.getCurrentTemperature.bind(this));
90
-
91
- this.services.push(this.GreeACService);
92
-
93
- this.serviceInfo = new Service.AccessoryInformation();
94
-
95
- this.serviceInfo
96
- .setCharacteristic(Characteristic.Name, this.name)
97
- .setCharacteristic(Characteristic.Manufacturer, 'Gree')
98
- .setCharacteristic(Characteristic.Model, this.model)
99
- .setCharacteristic(Characteristic.SerialNumber, this.host.replace(/./g, ""));
100
-
101
- this.services.push(this.serviceInfo);
102
-
103
- this.discover();
104
- }
105
-
106
- GreeAC.prototype = {
107
-
108
- getServices: function() {
109
-
110
- var informationService = new Service.AccessoryInformation();
111
-
112
- informationService
113
- .setCharacteristic(Characteristic.Name, this.name)
114
- .setCharacteristic(Characteristic.Manufacturer, 'Gree')
115
- .setCharacteristic(Characteristic.Model, this.model)
116
- .setCharacteristic(Characteristic.SerialNumber, this.host.replace(/./g, ""));
117
- return [informationService, this.GreeACService];
118
- },
119
-
120
- discover: function () {
121
-
122
- var accessory = this;
123
- var log = this.log;
124
- var host = this.host;
125
-
126
- const deviceOptions = {
127
- host: host,
128
- updateInterval: accessory.updateInterval,
129
- onStatus: (deviceModel) => {
130
- var device_power_status = deviceModel.props[commands.power.code];
131
- var device_mode_status = deviceModel.props[commands.mode.code];
132
- var device_temperature = deviceModel.props[commands.temperature.code];
133
- var device_swingvert = deviceModel.props[commands.swingVert.code] === 0 ? 0 : 1;
134
- accessory.TargetTemperature = parseFloat(device_temperature);
135
-
136
- if (device_power_status === commands.power.value.off) {
137
- accessory.TargetHeatingCoolingState = Characteristic.TargetHeatingCoolingState.OFF;
138
- } else if (device_mode_status === commands.mode.value.auto) {
139
- accessory.TargetHeatingCoolingState = Characteristic.TargetHeatingCoolingState.AUTO;
140
- } else if (device_mode_status === commands.mode.value.cool) {
141
- accessory.TargetHeatingCoolingState = Characteristic.TargetHeatingCoolingState.COOL;
142
- } else if (device_mode_status === commands.mode.value.heat) {
143
- accessory.TargetHeatingCoolingState = Characteristic.TargetHeatingCoolingState.HEAT;
144
- } else {
145
- accessory.TargetHeatingCoolingState = Characteristic.TargetHeatingCoolingState.AUTO;
146
- }
147
-
148
- accessory.GreeACService
149
- .getCharacteristic(Characteristic.TargetHeatingCoolingState)
150
- .updateValue(accessory.TargetHeatingCoolingState);
151
-
152
- accessory.GreeACService
153
- .getCharacteristic(Characteristic.TargetTemperature)
154
- .updateValue(accessory.TargetTemperature);
155
-
156
- if (accessory.debug === true) {
157
- log.info('Get mode: %s', device_mode_status.toString());
158
- log.info('Get temperature %s', device_temperature.toString());
159
- log.info('Get fanspeed %s', deviceModel.props[commands.fanSpeed.code].toString());
160
- log.info('Get swingvert %s', device_swingvert.toString());
161
- log.info('Get powerstatus %s', device_power_status.toString());
162
- }
163
- },
164
- onUpdate: (deviceModel) => {
165
- if (accessory.debug === true) {
166
- log.info('Status updated on %s', deviceModel.name)
167
- }
168
- },
169
- onConnected: (deviceModel) => {
170
- // var accesorry = this;
171
-
172
- if (deviceModel.bound == true) {
173
- log.info('Connected to %s with IP address %s', deviceModel.name, deviceModel.address);
174
- } else {
175
- log.info('Error connecting to %s with IP address %s', deviceModel.name, deviceModel.address);
176
- }
177
-
178
- accessory.client.subscribe(this.currentTempTopic);
179
- accessory.client.on('message', function (topic, message) {
180
- try {
181
- var data = JSON.parse(message);
182
- } catch (e) {
183
- return null;
184
- }
185
-
186
- if (data === null) {
187
- return null
188
- }
189
- // var that = this;
190
- accessory.temperature = parseFloat(data);
191
- if (!isNaN(accessory.temperature)) {
192
- if (accessory.debug === true) {
193
- accessory.log.info('Current room temperature is ' + accessory.temperature);
194
- }
195
- accessory.CurrentTemperature = parseFloat(accessory.temperature);
196
- accessory.GreeACService
197
- .getCharacteristic(Characteristic.CurrentTemperature)
198
- .updateValue(accessory.CurrentTemperature);
199
- }
200
- });
201
- },
202
- onError: (deviceModel) => {
203
- if (accessory.debug === true) {
204
- log.info('Error communicating with device %s with IP address %s', deviceModel.name, deviceModel.address);
205
- }
206
- },
207
- onDisconnected: (deviceModel) => {
208
- if (accessory.debug === true) {
209
- log.info('Disconnected from device %s with IP address %s', deviceModel.name, deviceModel.address);
210
- }
211
- }
212
- };
213
- log.info("Start discover device %s", deviceOptions.host);
214
- accessory.hvac = require('./app/deviceFactory').connect(deviceOptions);
215
- },
216
-
217
- setTemperatureDisplayUnits: function (value, callback) {
218
- var accessory = this;
219
- var log = this.log;
220
-
221
- if (accessory.debug === true) {
222
- log.info("setTemperatureDisplayUnits from %s to %s", accessory.temperatureDisplayUnits, value);
223
- }
224
- accessory.temperatureDisplayUnits = value;
225
- callback(null);
226
- },
227
-
228
- getTemperatureDisplayUnits: function (callback) {
229
- var accessory = this;
230
- var log = this.log;
231
- try {
232
- accessory.temperatureDisplayUnits = accessory.hvac.device.props[commands.temperatureUnit.code];
233
- if (accessory.debug === true) {
234
- log.info("getTemperatureDisplayUnits: ", accessory.temperatureDisplayUnits);
235
- }
236
- callback(null, accessory.temperatureDisplayUnits);
237
- } catch (err) {
238
- callback();
239
- }
240
- },
241
-
242
- getTargetHeatingCoolingState: function (callback) {
243
- var accessory = this;
244
- var log = this.log;
245
- var state = Characteristic.TargetHeatingCoolingState.AUTO;
246
- try {
247
- if (accessory.hvac.device.props[commands.power.code] === commands.power.value.off) {
248
- state = Characteristic.TargetHeatingCoolingState.OFF;
249
- } else if (accessory.hvac.device.props[commands.mode.code] === commands.mode.value.auto) {
250
- state = Characteristic.TargetHeatingCoolingState.AUTO;
251
- } else if (accessory.hvac.device.props[commands.mode.code] === commands.mode.value.cool) {
252
- state = Characteristic.TargetHeatingCoolingState.COOL;
253
- } else if (accessory.hvac.device.props[commands.mode.code] === commands.mode.value.heat) {
254
- state = Characteristic.TargetHeatingCoolingState.HEAT;
255
- }
256
-
257
- accessory.TargetHeatingCoolingState = state;
258
- callback(null, accessory.TargetHeatingCoolingState);
259
- } catch (err) {
260
- if (accessory.debug === true) {
261
- log.info("getTemperatureDisplayUnits: error communicating with device");
262
- }
263
- callback();
264
- }
265
- },
266
-
267
- setTargetHeatingCoolingState: function (TargetHeatingCoolingState, callback, context) {
268
- var accessory = this;
269
- var log = this.log;
270
-
271
- try {
272
- if (context !== 'fromSetValue') {
273
- this.TargetHeatingCoolingState = TargetHeatingCoolingState;
274
- if (accessory.TargetHeatingCoolingState === Characteristic.TargetHeatingCoolingState.OFF) {
275
- accessory.hvac.setPower(commands.power.value.off);
276
- if (accessory.debug === true) {
277
- log.info('setTargetHeatingCoolingState: Set mode power off');
278
- }
279
- } else {
280
- if (accessory.hvac.device.props[commands.power.code] === commands.power.value.off) {
281
- accessory.hvac.setPower(commands.power.value.on);
282
- if (accessory.debug === true) {
283
- log.info('setTargetHeatingCoolingState: Set mode power on');
284
- }
285
- }
286
-
287
- if (accessory.TargetHeatingCoolingState === Characteristic.TargetHeatingCoolingState.HEAT) {
288
- accessory.hvac.setMode(commands.mode.value['heat']);
289
- if (accessory.debug === true) {
290
- log.info('setTargetHeatingCoolingState: Set mode to HEAT');
291
- }
292
- }
293
-
294
- if (accessory.TargetHeatingCoolingState === Characteristic.TargetHeatingCoolingState.COOL) {
295
- accessory.hvac.setMode(commands.mode.value['cool']);
296
- if (accessory.debug === true) {
297
- log.info('setTargetHeatingCoolingState: Set mode to COOL');
298
- }
299
- }
300
-
301
- if (accessory.TargetHeatingCoolingState === Characteristic.TargetHeatingCoolingState.AUTO) {
302
- accessory.hvac.setMode(commands.mode.value['auto']);
303
- if (accessory.debug === true) {
304
- log.info('setTargetHeatingCoolingState: Set mode to AUTO');
305
- }
306
- }
307
- }
308
- }
309
- callback();
310
- } catch (err) {
311
- callback();
312
- }
313
- },
314
-
315
- getTargetTemperature: function (callback) {
316
- var accessory = this;
317
- var log = this.log;
318
- try {
319
- accessory.TargetTemperature = parseInt(accessory.hvac.device.props[commands.temperature.code]);
320
- callback(null, accessory.TargetTemperature);
321
- } catch (err) {
322
- callback();
323
- }
324
- },
325
-
326
- setTargetTemperature: function (TargetTemperature, callback, context) {
327
- var accessory = this;
328
- var log = this.log;
329
- if (context !== 'fromSetValue') {
330
- accessory.TargetTemperature = TargetTemperature;
331
- // if ac is off, then turn it on by setting to auto mode
332
- if (accessory.TargetHeatingCoolingState == Characteristic.TargetHeatingCoolingState.OFF) {
333
- accessory.hvac.setPower(commands.power.value.on);
334
- }
335
-
336
- // Update current temperature
337
- // this.GreeACService
338
- // .getCharacteristic(Characteristic.CurrentTemperature)
339
- // .updateValue(parseFloat(TargetTemperature));
340
- accessory.hvac.setTemp(parseInt(TargetTemperature));
341
- if (accessory.debug === true) {
342
- log.info('setTargetTemperature: Set temperature: ' + TargetTemperature);
343
- }
344
- }
345
- callback();
346
- },
347
-
348
- getCurrentTemperature: function (callback) {
349
- var accessory = this;
350
- var log = this.log;
351
- if (accessory.debug === true) {
352
- log.info("getCurrentTemperature: current temperature is %s", accessory.CurrentTemperature);
353
- }
354
- callback(null, parseFloat(accessory.CurrentTemperature));
355
- },
356
-
357
- identify: function (callback) {
358
- var accessory = this;
359
- var log = this.log;
360
- accessory.hvac.setTemp(22);
361
- if (accessory.debug === true) {
362
- log.info("identify: set temperature to 22");
363
- }
364
- callback();
365
- },
366
-
367
- getServices: function () {
368
- return this.services;
369
- }
370
-
371
- };
372
-
373
-