homebridge-edomoticz 2.1.39 → 2.1.45

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/README.md CHANGED
@@ -26,6 +26,7 @@ This is a plugin for [Homebridge](https://github.com/nfarina/homebridge) and [Ho
26
26
  - Lock Mechanisms (inverted)
27
27
  - Temperature sensors (only temperature characteristic in case of T+H / T+H+B)
28
28
  - Thermostat SetPoints
29
+ - TV
29
30
  </details>
30
31
 
31
32
  ## Provides:
@@ -129,6 +130,7 @@ The dimFix variable relates to an early issue between HomeKit and Domoticz regar
129
130
  ### Use legacy blind support
130
131
  If you use blinds, set this option to 1 if you use an older version of domoticz (until 2022-beta.14535). If using a more recent version, set to 0. When set to 0, the new reverse state and position will be used
131
132
 
133
+
132
134
  ### MQTT
133
135
  By default, the plugin will grab hardware information regarding MQTT from Domoticz if `mqtt` is 1 or true in the configuration file.
134
136
  Advanced users can override their MQTT configuration as follows:
@@ -26,6 +26,12 @@
26
26
  "default": "8080",
27
27
  "required": true
28
28
  },
29
+ "webroot": {
30
+ "title": "Webroot",
31
+ "type": "string",
32
+ "default": "",
33
+ "required": false
34
+ },
29
35
  "roomid": {
30
36
  "title": "Room ID",
31
37
  "type": "integer",
@@ -74,6 +80,7 @@
74
80
  "items": [
75
81
  "server",
76
82
  "port",
83
+ "webroot",
77
84
  "roomid"
78
85
  ]
79
86
  }, {
package/index.js CHANGED
@@ -9,31 +9,6 @@
9
9
  // [http://twitter.com/marcisshadow]
10
10
  // [http://domoticz.com/forum/memberlist.php?mode=viewprofile&u=10884]
11
11
  //
12
- // ** Remember to add platform to config.json **
13
- //
14
- // Example ~/.homebridge/config.json content:
15
- //
16
- // {
17
- // "bridge": {
18
- // "name": "Homebridge",
19
- // "username": "CC:21:3E:E4:DE:33", // << Randomize this...
20
- // "port": 51826,
21
- // "pin": "031-45-154",
22
- // },
23
- //
24
- // "platforms": [{
25
- // "platform": "eDomoticz",
26
- // "name": "eDomoticz",
27
- // "server": "127.0.0.1", // or "user:pass@ip"
28
- // "port": "8080",
29
- // "roomid": 0 , // 0 = all sensors, otherwise, room idx as shown at http://server:port/#/Roomplan
30
- // "ssl": 0,
31
- // "mqtt": true
32
- // }],
33
- //
34
- // "accessories":[]
35
- // }
36
- //
37
12
  var Domoticz = require('./lib/domoticz.js').Domoticz;
38
13
  var Mqtt = require('./lib/mqtt.js').Mqtt;
39
14
  var eDomoticzAccessory = require('./lib/domoticz_accessory.js');
@@ -45,43 +20,44 @@ const util = require('util');
45
20
  module.exports = function(homebridge) {
46
21
  Service = homebridge.hap.Service;
47
22
  Characteristic = homebridge.hap.Characteristic;
23
+ Categories = homebridge.hap.Accessory.Categories;
48
24
  Types = homebridge.hapLegacyTypes;
49
25
  UUID = homebridge.hap.uuid;
50
26
 
51
- Helper.fixInheritance(eDomoticzServices.TotalConsumption, Characteristic);
52
- Helper.fixInheritance(eDomoticzServices.CurrentConsumption, Characteristic);
53
- Helper.fixInheritance(eDomoticzServices.GasConsumption, Characteristic);
54
- Helper.fixInheritance(eDomoticzServices.TempOverride, Characteristic);
55
- Helper.fixInheritance(eDomoticzServices.MeterDeviceService, Service);
56
- Helper.fixInheritance(eDomoticzServices.GasDeviceService, Service);
57
- Helper.fixInheritance(eDomoticzServices.Ampere, Characteristic);
58
- Helper.fixInheritance(eDomoticzServices.AMPDeviceService, Service);
59
- Helper.fixInheritance(eDomoticzServices.Volt, Characteristic);
60
- Helper.fixInheritance(eDomoticzServices.VOLTDeviceService, Service);
61
- Helper.fixInheritance(eDomoticzServices.CurrentUsage, Characteristic);
62
- Helper.fixInheritance(eDomoticzServices.UsageDeviceService, Service);
63
- Helper.fixInheritance(eDomoticzServices.TodayConsumption, Characteristic);
64
- Helper.fixInheritance(eDomoticzServices.Barometer, Characteristic);
65
- Helper.fixInheritance(eDomoticzServices.WaterFlow, Characteristic);
66
- Helper.fixInheritance(eDomoticzServices.TotalWaterFlow, Characteristic);
67
- Helper.fixInheritance(eDomoticzServices.WaterDeviceService, Service);
68
- Helper.fixInheritance(eDomoticzServices.WeatherService, Service);
69
- Helper.fixInheritance(eDomoticzServices.WindSpeed, Characteristic);
70
- Helper.fixInheritance(eDomoticzServices.WindChill, Characteristic);
71
- Helper.fixInheritance(eDomoticzServices.WindDirection, Characteristic);
72
- Helper.fixInheritance(eDomoticzServices.WindDeviceService, Service);
73
- Helper.fixInheritance(eDomoticzServices.Rainfall, Characteristic);
74
- Helper.fixInheritance(eDomoticzServices.RainDeviceService, Service);
75
- Helper.fixInheritance(eDomoticzServices.Visibility, Characteristic);
76
- Helper.fixInheritance(eDomoticzServices.VisibilityDeviceService, Service);
77
- Helper.fixInheritance(eDomoticzServices.SolRad, Characteristic);
78
- Helper.fixInheritance(eDomoticzServices.SolRadDeviceService, Service);
79
- Helper.fixInheritance(eDomoticzServices.LocationService, Service);
80
- Helper.fixInheritance(eDomoticzServices.Location, Characteristic);
81
- Helper.fixInheritance(eDomoticzServices.InfotextDeviceService, Service);
82
- Helper.fixInheritance(eDomoticzServices.Infotext, Characteristic);
83
- Helper.fixInheritance(eDomoticzServices.UVDeviceService, Service);
84
- Helper.fixInheritance(eDomoticzServices.UVIndex, Characteristic);
27
+ util.inherits(eDomoticzServices.TotalConsumption, Characteristic);
28
+ util.inherits(eDomoticzServices.CurrentConsumption, Characteristic);
29
+ util.inherits(eDomoticzServices.GasConsumption, Characteristic);
30
+ util.inherits(eDomoticzServices.TempOverride, Characteristic);
31
+ util.inherits(eDomoticzServices.MeterDeviceService, Service);
32
+ util.inherits(eDomoticzServices.GasDeviceService, Service);
33
+ util.inherits(eDomoticzServices.Ampere, Characteristic);
34
+ util.inherits(eDomoticzServices.AMPDeviceService, Service);
35
+ util.inherits(eDomoticzServices.Volt, Characteristic);
36
+ util.inherits(eDomoticzServices.VOLTDeviceService, Service);
37
+ util.inherits(eDomoticzServices.CurrentUsage, Characteristic);
38
+ util.inherits(eDomoticzServices.UsageDeviceService, Service);
39
+ util.inherits(eDomoticzServices.TodayConsumption, Characteristic);
40
+ util.inherits(eDomoticzServices.Barometer, Characteristic);
41
+ util.inherits(eDomoticzServices.WaterFlow, Characteristic);
42
+ util.inherits(eDomoticzServices.TotalWaterFlow, Characteristic);
43
+ util.inherits(eDomoticzServices.WaterDeviceService, Service);
44
+ util.inherits(eDomoticzServices.WeatherService, Service);
45
+ util.inherits(eDomoticzServices.WindSpeed, Characteristic);
46
+ util.inherits(eDomoticzServices.WindChill, Characteristic);
47
+ util.inherits(eDomoticzServices.WindDirection, Characteristic);
48
+ util.inherits(eDomoticzServices.WindDeviceService, Service);
49
+ util.inherits(eDomoticzServices.Rainfall, Characteristic);
50
+ util.inherits(eDomoticzServices.RainDeviceService, Service);
51
+ util.inherits(eDomoticzServices.Visibility, Characteristic);
52
+ util.inherits(eDomoticzServices.VisibilityDeviceService, Service);
53
+ util.inherits(eDomoticzServices.SolRad, Characteristic);
54
+ util.inherits(eDomoticzServices.SolRadDeviceService, Service);
55
+ util.inherits(eDomoticzServices.LocationService, Service);
56
+ util.inherits(eDomoticzServices.Location, Characteristic);
57
+ util.inherits(eDomoticzServices.InfotextDeviceService, Service);
58
+ util.inherits(eDomoticzServices.Infotext, Characteristic);
59
+ util.inherits(eDomoticzServices.UVDeviceService, Service);
60
+ util.inherits(eDomoticzServices.UVIndex, Characteristic);
85
61
 
86
62
  //homebridge.registerAccessory("homebridge-edomoticz", "eDomoticz", eDomoticzAccessory);
87
63
  homebridge.registerPlatform("homebridge-edomoticz", "eDomoticz", eDomoticzPlatform, true);
@@ -109,9 +85,10 @@ function eDomoticzPlatform(log, config, api) {
109
85
 
110
86
  this.ssl = (config.ssl == 1);
111
87
  this.port = config.port;
88
+ this.webroot = config.webroot;
112
89
  this.room = config.roomid;
113
90
  this.api = api;
114
- this.apiBaseURL = "http" + (this.ssl ? "s" : "") + "://" + this.server + ":" + this.port + "/json.htm?";
91
+ this.apiBaseURL = "http" + (this.ssl ? "s" : "") + "://" + this.server + ":" + this.port + ((this.webroot === undefined) ? "" : "/" + this.webroot ) + "/json.htm?";
115
92
  this.mqtt = false;
116
93
  } catch (e) {
117
94
  this.forceLog(e);
@@ -149,20 +126,19 @@ eDomoticzPlatform.prototype = {
149
126
  var excludedDevices = (typeof this.config.excludedDevices !== 'undefined') ? this.config.excludedDevices : [];
150
127
 
151
128
  Domoticz.devices(this.apiBaseURL, this.room, function(devices) {
152
- var removedAccessories = [];
129
+ var removedAccessories = [],
130
+ externalAccessories = [];
153
131
 
154
132
 
155
133
  for (var i = 0; i < devices.length; i++) {
156
134
  var device = devices[i], exclude = !1;
157
135
  if (!(excludedDevices.indexOf(device.idx) <= -1)) {
158
136
  exclude = !0;
159
- this.forceLog(device.Name + ' (idx:' + device.idx + ') excluded via config array');
160
- //continue;
137
+ this.log(device.Name + ' (idx:' + device.idx + ') excluded via config array');
161
138
  }
162
139
 
163
140
  if (device.Image == undefined) {
164
141
  device.Image = 'Switch';
165
- //this.forceLog(device.Name);
166
142
  }
167
143
 
168
144
  var existingAccessory = this.accessories.find(function(existingAccessory) {
@@ -191,20 +167,35 @@ eDomoticzPlatform.prototype = {
191
167
  // Generate a new accessory
192
168
  var uuid = UUID.generate(device.idx + "_" + device.Name);
193
169
  this.forceLog("Device: " + device.Name + " (" + device.idx + ")");
194
- var accessory = new eDomoticzAccessory(this, false, false, device.Used, device.idx, device.Name, uuid, device.HaveDimmer, device.MaxDimLevel, device.SubType, device.Type, device.BatteryLevel, device.SwitchType, device.SwitchTypeVal, device.HardwareID, device.HardwareTypeVal, device.Image, this.eve, device.HaveTimeout);
170
+ var accessory = new eDomoticzAccessory(this, false, false, device.Used, device.idx, device.Name, uuid, device.HaveDimmer, device.MaxDimLevel, device.SubType, device.Type, device.BatteryLevel, device.SwitchType, device.SwitchTypeVal, device.HardwareID, device.HardwareTypeVal, device.Image, this.eve, device.HaveTimeout, device.Description);
195
171
  this.accessories.push(accessory);
196
172
 
197
173
  // Register the accessories
198
174
  try {
199
- this.api.registerPlatformAccessories("homebridge-edomoticz", "eDomoticz", [accessory.platformAccessory]);
175
+ accessory.platformAccessory.context = {
176
+ device: device,
177
+ uuid: uuid,
178
+ eve: this.eve
179
+ };
180
+ if ((device.SwitchTypeVal == Constants.DeviceTypeMedia) || (device.SwitchTypeVal == Constants.DeviceTypeSelector && device.Image == "TV")) {
181
+ externalAccessories.push(accessory);
182
+ } else {
183
+ this.api.registerPlatformAccessories("homebridge-edomoticz", "eDomoticz", [accessory.platformAccessory]);
184
+ }
185
+
200
186
  } catch (e) {
201
187
  this.forceLog("Could not register platform accessory! (" + accessory.name + ")\n" + e);
202
188
  }
203
- accessory.platformAccessory.context = {
204
- device: device,
205
- uuid: uuid,
206
- eve: this.eve
207
- };
189
+
190
+ }
191
+ }
192
+ // Publish external (ie: TV) accessories now that they're fully assembled
193
+ for (var ei = 0; ei < externalAccessories.length; ei++) {
194
+ var externalAccessory = externalAccessories[ei];
195
+ if (externalAccessory.subType !== 'Selector Switch')
196
+ {
197
+ this.api.publishExternalAccessories("homebridge-edomoticz", [externalAccessory.platformAccessory]);
198
+ this.forceLog("External Device: " + externalAccessory.platformAccessory.context.device.Name + " (" + externalAccessory.platformAccessory.context.device.idx + ")");
208
199
  }
209
200
  }
210
201
 
@@ -231,7 +222,6 @@ eDomoticzPlatform.prototype = {
231
222
  var index = this.accessories.indexOf(removedAccessory);
232
223
  this.accessories.splice(index, 1);
233
224
  }
234
-
235
225
  this.isSynchronizingAccessories = false;
236
226
  }.bind(this), function(response, err) {
237
227
  Helper.LogConnectionError(this, response, err);
@@ -254,7 +244,7 @@ eDomoticzPlatform.prototype = {
254
244
  var eve = platformAccessory.context.eve;
255
245
 
256
246
  // Generate the already cached accessory again
257
- var accessory = new eDomoticzAccessory(this, platformAccessory, false, device.Used, device.idx, device.Name, uuid, device.HaveDimmer, device.MaxDimLevel, device.SubType, device.Type, device.BatteryLevel, device.SwitchType, device.SwitchTypeVal, device.HardwareID, device.HardwareTypeVal, device.Image, eve);
247
+ var accessory = new eDomoticzAccessory(this, platformAccessory, false, device.Used, device.idx, device.Name, uuid, device.HaveDimmer, device.MaxDimLevel, device.SubType, device.Type, device.BatteryLevel, device.SwitchType, device.SwitchTypeVal, device.HardwareID, device.HardwareTypeVal, device.Image, eve, device.HaveTimeout, device.Description);
258
248
  this.accessories.push(accessory);
259
249
  }
260
250
  };
package/lib/constants.js CHANGED
@@ -1,5 +1,6 @@
1
1
  global.Service;
2
2
  global.Characteristic;
3
+ global.Categories;
3
4
  global.Types;
4
5
  global.UUID;
5
6
 
@@ -18,7 +19,7 @@ module.exports = {
18
19
  DeviceTypeBlindsVenetianUS: 14,
19
20
  DeviceTypeBlindsVenetianEU: 15,
20
21
  DeviceTypeBlindsPercentageInverted: 16,
21
- DeviceTypeMedia: 17, // Only supported as on/off switch at the moment.
22
+ DeviceTypeMedia: 17,
22
23
  DeviceTypeSelector: 18,
23
24
  DeviceTypeDoorLock: 19,
24
25
  DeviceTypeDoorLockInverted: 20,
package/lib/domoticz.js CHANGED
@@ -48,6 +48,7 @@ Domoticz.settings = function(accessory, completion, error) {
48
48
  Helper.LogConnectionError(this.platform, response, err);
49
49
  if (typeof error !== 'undefined' && error !== false) {
50
50
  error();
51
+ callback();
51
52
  }
52
53
  }
53
54
  }.bind(accessory));
@@ -207,6 +208,7 @@ Domoticz.updateWithURL = function(accessory, url, completion) {
207
208
  }
208
209
  else {
209
210
  Helper.LogConnectionError(this.platform, response, err);
211
+ callback();
210
212
  }
211
213
 
212
214
  if (typeof completion !== 'undefined' && completion !== false) {
@@ -9,7 +9,7 @@ module.exports = eDomoticzAccessory;
9
9
  var tvAccessories = {};
10
10
  var tvInputAccessories = {};
11
11
 
12
- function eDomoticzAccessory(platform, platformAccessory, IsScene, status, idx, name, uuid, haveDimmer, maxDimLevel, subType, Type, batteryRef, swType, swTypeVal, hwId, hwType, image, eve, hwtimeout) {
12
+ function eDomoticzAccessory(platform, platformAccessory, IsScene, status, idx, name, uuid, haveDimmer, maxDimLevel, subType, Type, batteryRef, swType, swTypeVal, hwId, hwType, image, eve, hwtimeout, descript) {
13
13
 
14
14
  if ((haveDimmer) || (swType == "Dimmer")) {
15
15
  if ((hwType !== 51) && (swType !== "On/Off")) {
@@ -53,6 +53,7 @@ function eDomoticzAccessory(platform, platformAccessory, IsScene, status, idx, n
53
53
  this.cachedValues = {};
54
54
  this.hwId = hwId;
55
55
  this.hwType = hwType;
56
+ this.descript = descript;
56
57
  this.powerOnBySetLevelTime = 0;
57
58
 
58
59
  // Initialize default values, e.g. to get the "factor"
@@ -84,6 +85,9 @@ function eDomoticzAccessory(platform, platformAccessory, IsScene, status, idx, n
84
85
  this.platformAccessory = new platform.api.platformAccessory(this.name, uuid);
85
86
  }
86
87
  this.platformAccessory.reachable = true;
88
+ if (this.swTypeVal == Constants.DeviceTypeMedia) {
89
+ this.platformAccessory.category = Categories.TELEVISION;
90
+ }
87
91
  this.publishServices();
88
92
  }
89
93
 
@@ -154,7 +158,7 @@ eDomoticzAccessory.prototype = {
154
158
 
155
159
  return service.addCharacteristic(new characteristicType());
156
160
  },
157
- setPowerState: function (powerOn, callback, context) {
161
+ setPowerState: function (powerOn, callback, context) {
158
162
  if (context && context == "eDomoticz-MQTT"
159
163
  || (this.cachedValues[Characteristic.On.UUID] == powerOn && powerOn) // Prevents message loop while dimming lights.
160
164
  || (this.powerOnBySetLevelTime > 0 && (performance.now() - this.powerOnBySetLevelTime) < 500 && powerOn) // Ignore a power ON right after a setlevel to allow turning ON a light using a dimmer.
@@ -172,7 +176,7 @@ eDomoticzAccessory.prototype = {
172
176
  callback();
173
177
  }.bind(this));
174
178
  },
175
- getPowerState: function (callback) {
179
+ getPowerState: function (callback) {
176
180
  var cachedValue = this.cachedValues[Characteristic.On.UUID];
177
181
  if (typeof cachedValue !== 'undefined') {
178
182
  callback(null, cachedValue);
@@ -188,7 +192,7 @@ eDomoticzAccessory.prototype = {
188
192
  value = (s.Status == "Off") ? false : true;
189
193
  }
190
194
  }.bind(this));
191
-
195
+
192
196
  if (typeof cachedValue === 'undefined') {
193
197
  callback(null, value);
194
198
  }
@@ -221,7 +225,7 @@ eDomoticzAccessory.prototype = {
221
225
  sArray.map(function (s) {
222
226
  value = (s.Status == "Off") ? false : true;
223
227
  }.bind(this));
224
-
228
+
225
229
  if (typeof cachedValue === 'undefined') {
226
230
  callback(null, value);
227
231
  }
@@ -349,8 +353,13 @@ eDomoticzAccessory.prototype = {
349
353
  }
350
354
  if (this.hueValue !== undefined && this.saturationValue !== undefined && this.hueSemaphore !== undefined && this.hueSemaphore > 0) {
351
355
  this.hueSemaphore = undefined;
356
+ var c = this.cachedValues[Characteristic.Brightness.UUID],
357
+ b = 100; // retain current brightness...
358
+ if (typeof c !== 'undefined') {
359
+ b = this.platform.config.dimFix == 1 ? Math.floor(c / this.factor) + 1 : Math.floor(c / this.factor);
360
+ }
352
361
  Domoticz.updateDeviceStatus(this, "setcolbrightnessvalue", {
353
- "hex": Helper.HSVtoRGB([this.hueValue, this.saturationValue, 100])
362
+ "hex": Helper.HSVtoRGB([this.hueValue, this.saturationValue, b])
354
363
  }, function (success) {
355
364
  callback();
356
365
  }.bind(this));
@@ -451,7 +460,7 @@ eDomoticzAccessory.prototype = {
451
460
  value = (value == 0) ? 0.0001 : value;
452
461
  } else if (this.subType == "Waterflow" || (this.name.indexOf("Gas") > -1 && this.Type == "General" && this.subType == "kWh")) {
453
462
  value = Helper.cleanFloat(s.Data);
454
- } else if (this.subType == "RFXMeter counter" || this.subType == "Percentage" || this.subType == "kWh" || this.subType == "Energy" || this.subType == "Solar Radiation" || this.subType == "UVN800" || this.subType == "UVN128,UV138" || this.subType == "Visibility") {
463
+ } else if (this.subType == "RFXMeter counter" || this.subType == "Percentage" || this.subType == "kWh" || this.subType == "Energy" || this.subType == "Solar Radiation" || this.subType == "UVN800" || this.subType == "UVN128,UV138" || this.subType == "Visibility") {
455
464
  value = (s.Counter !== undefined) ? Helper.cleanFloat(s.Counter) : Helper.cleanFloat(s.Data);
456
465
  } else if (this.subType == "Text") {
457
466
  value = s.Data.toString();
@@ -735,11 +744,13 @@ eDomoticzAccessory.prototype = {
735
744
  });
736
745
  return;
737
746
  }
747
+
738
748
  if (this.platform.config.legacyBlinds == 1) {
739
749
  var command = (shouldOpen ? "On" : "Off");
740
750
  } else {
741
751
  var command = (shouldOpen ? "Close" : "Open");
742
752
  }
753
+
743
754
  Domoticz.updateDeviceStatus(this, "switchlight", {
744
755
  "switchcmd": command
745
756
  }, function (success) {
@@ -986,9 +997,9 @@ eDomoticzAccessory.prototype = {
986
997
  callback();
987
998
  return;
988
999
  }
989
-
990
- if (this.hwId.toString() in tvInputAccessories) {
991
- Domoticz.updateDeviceStatus(tvInputAccessories[this.hwId.toString()], "switchlight", {
1000
+
1001
+ if (this.descript in tvInputAccessories) {
1002
+ Domoticz.updateDeviceStatus(tvInputAccessories[this.descript], "switchlight", {
992
1003
  "switchcmd": "Set Level",
993
1004
  "level": identifier * 10
994
1005
  }, function (success) {
@@ -1003,8 +1014,8 @@ eDomoticzAccessory.prototype = {
1003
1014
  callback(null, cachedValue);
1004
1015
  }
1005
1016
 
1006
- if (this.hwId.toString() in tvInputAccessories) {
1007
- Domoticz.deviceStatus(tvInputAccessories[this.hwId.toString()], function (json) {
1017
+ if (this.descript in tvInputAccessories) {
1018
+ Domoticz.deviceStatus(tvInputAccessories[this.descript], function (json) {
1008
1019
  var value = 0;
1009
1020
  var sArray = Helper.sortByKey(json.result, "Name");
1010
1021
  sArray.map(function (s) {
@@ -1020,7 +1031,7 @@ eDomoticzAccessory.prototype = {
1020
1031
  } else if (typeof cachedValue === 'undefined') {
1021
1032
  this.cachedValues[Characteristic.ActiveIdentifier.UUID] = 0;
1022
1033
  callback(null, 0);
1023
- }
1034
+ }
1024
1035
  },
1025
1036
  handleMQTTMessage: function (message, callback) {
1026
1037
  this.platform.log("MQTT Message received for %s.\nName:\t\t%s\nDevice:\t\t%s,%s\nIs Switch:\t%s\nSwitchTypeVal:\t%s\nMQTT Message:\n%s", this.name, this.name, this.Type, this.subType, this.isSwitch, this.swTypeVal, JSON.stringify(message, null, 4));
@@ -1034,7 +1045,7 @@ eDomoticzAccessory.prototype = {
1034
1045
  if (this.isSwitch) {
1035
1046
  switch (true) {
1036
1047
  case this.swTypeVal == Constants.DeviceTypeSwitch || this.swTypeVal == Constants.DeviceTypePushOn:
1037
- {
1048
+ {
1038
1049
  var service = false;
1039
1050
  if (this.image !== undefined && this.swTypeVal !== Constants.DeviceTypePushOn) {
1040
1051
  if (this.image.indexOf("Fan") > -1) {
@@ -1167,7 +1178,7 @@ eDomoticzAccessory.prototype = {
1167
1178
  callback(characteristic, Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1168
1179
  break;
1169
1180
  }
1170
- case this.swTypeVal == Constants.DeviceTypeSelector && this.image != "TV":
1181
+ case this.swTypeVal == Constants.DeviceTypeSelector && this.image !== "TV":
1171
1182
  {
1172
1183
  var service = this.getService(Service.StatelessProgrammableSwitch);
1173
1184
  var characteristic = this.getCharacteristic(service, Characteristic.ProgrammableSwitchEvent);
@@ -1188,16 +1199,21 @@ eDomoticzAccessory.prototype = {
1188
1199
  }
1189
1200
  case this.swTypeVal == Constants.DeviceTypeSelector && this.image == "TV":
1190
1201
  {
1191
- var tvAccessory = tvAccessories[this.hwId.toString()];
1192
- var tvService = tvAccessory.getService(Service.Television);
1193
- var characteristic = tvAccessory.getCharacteristic(tvService, Characteristic.ActiveIdentifier);
1194
- var identifier = parseInt(message.svalue1) / 10;
1195
- var oldIdentifier = tvAccessory.cachedValues[Characteristic.ActiveIdentifier.UUID];
1196
-
1197
- if (identifier != oldIdentifier) {
1198
- tvAccessory.cachedValues[Characteristic.ActiveIdentifier.UUID] = identifier;
1199
- callback(characteristic, identifier);
1202
+ var tvAccessory = tvAccessories[this.descript];
1203
+ if (typeof tvAccessory !== undefined) {
1204
+ var tvService = tvAccessory.getService(Service.Television);
1205
+ var characteristic = tvAccessory.getCharacteristic(tvService, Characteristic.ActiveIdentifier);
1206
+ var identifier = parseInt(message.svalue1) / 10;
1207
+ var oldIdentifier = tvAccessory.cachedValues[Characteristic.ActiveIdentifier.UUID];
1208
+
1209
+ if (identifier != oldIdentifier) {
1210
+ tvAccessory.cachedValues[Characteristic.ActiveIdentifier.UUID] = identifier;
1211
+ callback(characteristic, identifier);
1212
+ }
1213
+ } else {
1214
+ callback();
1200
1215
  }
1216
+
1201
1217
  }
1202
1218
  break;
1203
1219
  case this.swTypeVal == Constants.DeviceTypeDoorLock:
@@ -1309,15 +1325,21 @@ eDomoticzAccessory.prototype = {
1309
1325
  position = message.svalue1 * this.factor;
1310
1326
  }
1311
1327
  } else if ((this.swTypeVal == Constants.DeviceTypeBlindsVenetianUS || this.swTypeVal == Constants.DeviceTypeBlindsVenetianEU) && message.nvalue > 1) {
1312
- position = (message.nvalue == 15 ? 100 : 0);
1328
+ //position = (message.nvalue == 15 ? 100 : 0);
1329
+ if (message.ReverseState == 'true') {
1330
+ position = ((message.nvalue == 16 || message.nvalue == 18) ? 100 : 0);
1331
+ } else {
1332
+ position = ((message.nvalue == 15 || message.nvalue == 17) ? 100 : 0);
1333
+ }
1313
1334
  } else {
1314
1335
  if (message.ReverseState == 'true') {
1315
- position = (message.nvalue == 0 ? 100 : 0);
1336
+ position = (message.nvalue == 1 ? 0 : 100);
1316
1337
  } else {
1317
1338
  position = (message.nvalue == 1 ? 100 : 0);
1318
1339
  }
1319
1340
  }
1320
1341
  }
1342
+
1321
1343
  var lastActivity = false;
1322
1344
  if (this.cachedValues["lastActivity"]) {
1323
1345
  lastActivity = this.cachedValues["lastActivity"];
@@ -1354,29 +1376,36 @@ eDomoticzAccessory.prototype = {
1354
1376
  case this.swTypeVal == Constants.DeviceTypeSecuritySystem:
1355
1377
  {
1356
1378
  var systemState = Characteristic.SecuritySystemCurrentState.STAY_ARM;
1379
+ var targetState = Characteristic.SecuritySystemTargetState.STAY_ARM;
1357
1380
  switch (message.nvalue) {
1358
1381
  case 0: //Disarm
1359
1382
  case 1: //Normal Delay
1360
1383
  case 13: //Disarm
1361
1384
  systemState = Characteristic.SecuritySystemCurrentState.DISARMED;
1385
+ targetState = Characteristic.SecuritySystemTargetState.DISARM;
1362
1386
  break;
1363
1387
  case 9: //Arm Away
1364
1388
  case 10: //Arm Away Delayed
1365
1389
  systemState = Characteristic.SecuritySystemCurrentState.AWAY_ARM;
1390
+ targetState = Characteristic.SecuritySystemTargetState.AWAY_ARM;
1366
1391
  break;
1367
1392
  case 11: //Arm Home
1368
1393
  case 12: //Arm Home Delayed
1369
1394
  systemState = Characteristic.SecuritySystemCurrentState.STAY_ARM;
1395
+ targetState = Characteristic.SecuritySystemTargetState.STAY_ARM;
1370
1396
  break;
1371
1397
  case 6:
1372
1398
  systemState = Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED;
1399
+ targetState = Characteristic.SecuritySystemTargetState.STAY_ARM;
1373
1400
  break;
1374
1401
  default:
1375
- case 2: //Alarm
1402
+ case 2:
1403
+ systemState = Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED;
1404
+ targetState = Characteristic.SecuritySystemTargetState.STAY_ARM;
1405
+ break;
1376
1406
  case 3: //Alarm Delayed
1377
1407
  case 4: //Motion
1378
1408
  case 5: //No Motion
1379
- case 6: //Panic
1380
1409
  case 7: //Panic End
1381
1410
  case 8:
1382
1411
  }
@@ -1386,7 +1415,7 @@ eDomoticzAccessory.prototype = {
1386
1415
  var currentStateCharacteristic = this.getCharacteristic(service, Characteristic.SecuritySystemCurrentState);
1387
1416
  var targetStateCharacteristic = this.getCharacteristic(service, Characteristic.SecuritySystemTargetState);
1388
1417
  callback(currentStateCharacteristic, systemState);
1389
- callback(targetStateCharacteristic, systemState);
1418
+ callback(targetStateCharacteristic, targetState);
1390
1419
  break;
1391
1420
  }
1392
1421
 
@@ -1760,12 +1789,7 @@ eDomoticzAccessory.prototype = {
1760
1789
  this.gracefullyAddCharacteristic(service, Characteristic.Hue).on('set', this.setHueValue.bind(this, 'Hue')).on('get', this.getHueValue.bind(this, 'Hue'));
1761
1790
  this.gracefullyAddCharacteristic(service, Characteristic.Saturation).on('set', this.setHueValue.bind(this, 'Saturation')).on('get', this.getHueValue.bind(this, 'Saturation'));
1762
1791
  } else if (this.subType == 'WW') {
1763
- //var col = (this.Color == "" || typeof this.Color === undefined) ? !1 : !0;
1764
- //if (col == !0) {
1765
- this.gracefullyAddCharacteristic(service, Characteristic.ColorTemperature).on('set', this.setColorTempValue.bind(this, 'ColorTemperature')).on('get', this.getColorTempValue.bind(this, 'ColorTemperature'));
1766
- //} else {
1767
- // this.platform.forceLog(this.name +' claims to be a WW light but provides no Color object. Treating as plain old Dimmer.');
1768
- //}
1792
+ this.gracefullyAddCharacteristic(service, Characteristic.ColorTemperature).on('set', this.setColorTempValue.bind(this, 'ColorTemperature')).on('get', this.getColorTempValue.bind(this, 'ColorTemperature'));
1769
1793
  }
1770
1794
  }
1771
1795
  this.services.push(service);
@@ -1807,8 +1831,8 @@ eDomoticzAccessory.prototype = {
1807
1831
  this.getCharacteristic(tvService, Characteristic.RemoteKey)
1808
1832
  .on('set', this.sendTelevisionRemoteKey.bind(this));
1809
1833
  this.services.push(tvService);
1810
- tvAccessories[this.hwId.toString()] = this;
1811
-
1834
+ tvAccessories[this.descript] = this;
1835
+
1812
1836
  // TV volume.
1813
1837
  var tvSpeakerService = this.getService(Service.TelevisionSpeaker);
1814
1838
  if (!tvSpeakerService) {
@@ -1823,19 +1847,19 @@ eDomoticzAccessory.prototype = {
1823
1847
  .on('get', this.getTelevisionMuteState.bind(this));
1824
1848
  tvService.addLinkedService(tvSpeakerService);
1825
1849
  this.services.push(tvSpeakerService);
1826
-
1827
- if (this.hwId.toString() in tvInputAccessories) {
1828
- this.createTvInputService(tvInputAccessories[this.hwId.toString()]);
1829
- }
1830
-
1850
+
1851
+ if (this.descript in tvInputAccessories) {
1852
+ this.createTvInputService(tvInputAccessories[this.descript]);
1853
+ }
1854
+
1831
1855
  break;
1832
1856
  }
1833
1857
  case this.swTypeVal == Constants.DeviceTypeSelector && this.image == "TV":
1834
1858
  {
1835
- tvInputAccessories[this.hwId.toString()] = this;
1859
+ tvInputAccessories[this.descript] = this;
1836
1860
 
1837
- if (this.hwId.toString() in tvAccessories) {
1838
- tvAccessories[this.hwId.toString()].createTvInputService(this);
1861
+ if (this.descript in tvAccessories) {
1862
+ tvAccessories[this.descript].createTvInputService(this);
1839
1863
  }
1840
1864
 
1841
1865
  break;
@@ -2269,58 +2293,59 @@ eDomoticzAccessory.prototype = {
2269
2293
  },
2270
2294
  createTvInputService: function (domoticzInputSourceAccessory) {
2271
2295
  var tvService = this.services[1];
2272
-
2273
- Domoticz.deviceStatus(domoticzInputSourceAccessory, function (json) {
2274
- var sArray = Helper.sortByKey(json.result, "Name");
2275
- sArray.map(function (s) {
2276
- var inputs = new Buffer(s.LevelNames, 'base64').toString("utf8").split("|");
2277
- if(inputs.length > 0 && inputs[0] == "Off") {
2278
- inputs.shift();
2279
- }
2280
-
2281
- inputs.forEach((input, index) => {
2282
- var inputType;
2283
- switch (true) {
2284
- case input.match(/^TV|Live$/i):
2285
- inputType = Characteristic.InputSourceType.TUNER;
2286
- break;
2287
- case input.match(/hdmi/i):
2288
- inputType = Characteristic.InputSourceType.HDMI;
2289
- break;
2290
- case input.match(/ypbpr/i):
2291
- inputType = Characteristic.InputSourceType.COMPONENT_VIDEO;
2292
- break;
2293
- default:
2294
- inputType = Characteristic.InputSourceType.APPLICATION;
2295
- break;
2296
+ if (typeof tvService !== undefined) {
2297
+ Domoticz.deviceStatus(domoticzInputSourceAccessory, function (json) {
2298
+ var sArray = Helper.sortByKey(json.result, "Name");
2299
+ sArray.map(function (s) {
2300
+ var inputs = new Buffer(s.LevelNames, 'base64').toString("utf8").split("|");
2301
+ if (inputs.length > 0 && inputs[0] == "Off") {
2302
+ inputs.shift();
2296
2303
  }
2297
2304
 
2298
- var inputService = this.getService(Service.InputSource, input);
2299
- if (!inputService) {
2300
- inputService = new Service.InputSource(input.replace(/\s/g, '').toLowerCase(), input);
2301
- }
2302
- inputService
2303
- .setCharacteristic(Characteristic.Identifier, index + 1)
2304
- .setCharacteristic(Characteristic.ConfiguredName, input)
2305
- .setCharacteristic(Characteristic.IsConfigured, Characteristic.IsConfigured.CONFIGURED)
2306
- .setCharacteristic(Characteristic.InputSourceType, inputType)
2307
- .setCharacteristic(Characteristic.CurrentVisibilityState, Characteristic.CurrentVisibilityState.SHOWN);
2308
- tvService.addLinkedService(inputService);
2309
- this.services.push(inputService);
2305
+ inputs.forEach((input, index) => {
2306
+ var inputType;
2307
+ switch (true) {
2308
+ case input.match(/^TV|Live$/i):
2309
+ inputType = Characteristic.InputSourceType.TUNER;
2310
+ break;
2311
+ case input.match(/hdmi/i):
2312
+ inputType = Characteristic.InputSourceType.HDMI;
2313
+ break;
2314
+ case input.match(/ypbpr/i):
2315
+ inputType = Characteristic.InputSourceType.COMPONENT_VIDEO;
2316
+ break;
2317
+ default:
2318
+ inputType = Characteristic.InputSourceType.APPLICATION;
2319
+ break;
2320
+ }
2310
2321
 
2311
- if(this.published) {
2312
- this.publishService(inputService);
2313
- }
2314
- });
2322
+ var inputService = this.getService(Service.InputSource, input);
2323
+ if (!inputService) {
2324
+ inputService = new Service.InputSource(input.replace(/\s/g, '').toLowerCase(), input);
2325
+ }
2326
+ inputService
2327
+ .setCharacteristic(Characteristic.Identifier, index + 1)
2328
+ .setCharacteristic(Characteristic.ConfiguredName, input)
2329
+ .setCharacteristic(Characteristic.IsConfigured, Characteristic.IsConfigured.CONFIGURED)
2330
+ .setCharacteristic(Characteristic.InputSourceType, inputType)
2331
+ .setCharacteristic(Characteristic.CurrentVisibilityState, Characteristic.CurrentVisibilityState.SHOWN);
2332
+ tvService.addLinkedService(inputService);
2333
+ this.services.push(inputService);
2334
+
2335
+ if(this.published) {
2336
+ this.publishService(inputService);
2337
+ }
2338
+ });
2339
+ }.bind(this));
2315
2340
  }.bind(this));
2316
- }.bind(this));
2341
+ }
2317
2342
  },
2318
2343
  removed: function() { // This accessory has been removed.
2319
- if (this.hwId.toString() in tvAccessories) {
2320
- delete tvAccessories[this.hwId.toString()];
2344
+ if (this.descript in tvAccessories) {
2345
+ delete tvAccessories[this.descript];
2321
2346
  }
2322
- if (this.hwId.toString() in tvInputAccessories) {
2323
- delete tvInputAccessories[this.hwId.toString()];
2347
+ if (this.descript in tvInputAccessories) {
2348
+ delete tvInputAccessories[this.descript];
2324
2349
  }
2325
2350
  }
2326
2351
  };
package/lib/services.js CHANGED
@@ -20,6 +20,7 @@ eDomoticzServices.TotalConsumption = function() {
20
20
  unit: 'kWh'
21
21
  });
22
22
  this.value = this.getDefaultValue();
23
+ this.UUID = charUUID;
23
24
  };
24
25
  eDomoticzServices.TodayConsumption = function() {
25
26
  var charUUID = UUID.generate('eDomoticz:customchar:TodayConsumption');
@@ -30,6 +31,7 @@ eDomoticzServices.TodayConsumption = function() {
30
31
  unit: 'kWh'
31
32
  });
32
33
  this.value = this.getDefaultValue();
34
+ this.UUID = charUUID;
33
35
  };
34
36
  eDomoticzServices.CurrentConsumption = function() {
35
37
  var charUUID = 'E863F10D-079E-48FF-8F27-9C2605A29F52'; //UUID.generate('eDomoticz:customchar:CurrentConsumption');
@@ -40,6 +42,7 @@ eDomoticzServices.CurrentConsumption = function() {
40
42
  unit: 'W'
41
43
  });
42
44
  this.value = this.getDefaultValue();
45
+ this.UUID = charUUID;
43
46
  };
44
47
  eDomoticzServices.Ampere = function() {
45
48
  var charUUID = 'E863F126-079E-48FF-8F27-9C2605A29F52'; //AMPERE
@@ -50,6 +53,7 @@ eDomoticzServices.Ampere = function() {
50
53
  unit: 'A'
51
54
  });
52
55
  this.value = this.getDefaultValue();
56
+ this.UUID = charUUID;
53
57
  };
54
58
  eDomoticzServices.Volt = function() {
55
59
  var charUUID = 'E863F10A-079E-48FF-8F27-9C2605A29F52'; //VOLT
@@ -60,6 +64,7 @@ eDomoticzServices.Volt = function() {
60
64
  unit: 'V'
61
65
  });
62
66
  this.value = this.getDefaultValue();
67
+ this.UUID = charUUID;
63
68
  };
64
69
  eDomoticzServices.GasConsumption = function() {
65
70
  var charUUID = UUID.generate('eDomoticz:customchar:CurrentConsumption');
@@ -69,6 +74,7 @@ eDomoticzServices.GasConsumption = function() {
69
74
  perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
70
75
  });
71
76
  this.value = this.getDefaultValue();
77
+ this.UUID = charUUID;
72
78
  };
73
79
  eDomoticzServices.WaterFlow = function() {
74
80
  var charUUID = UUID.generate('eDomoticz:customchar:WaterFlow');
@@ -79,6 +85,7 @@ eDomoticzServices.WaterFlow = function() {
79
85
  unit: 'm3'
80
86
  });
81
87
  this.value = this.getDefaultValue();
88
+ this.UUID = charUUID;
82
89
  };
83
90
  eDomoticzServices.TotalWaterFlow = function() {
84
91
  var charUUID = UUID.generate('eDomoticz:customchar:TotalWaterFlow');
@@ -89,6 +96,7 @@ eDomoticzServices.TotalWaterFlow = function() {
89
96
  unit: 'l'
90
97
  });
91
98
  this.value = this.getDefaultValue();
99
+ this.UUID = charUUID;
92
100
  };
93
101
  // Custom SetPoint Minutes characteristic for TempOverride modes
94
102
  eDomoticzServices.TempOverride = function() {
@@ -103,6 +111,7 @@ eDomoticzServices.TempOverride = function() {
103
111
  perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
104
112
  });
105
113
  this.value = this.getDefaultValue();
114
+ this.UUID = charUUID;
106
115
  };
107
116
  // Ampere Meter
108
117
  eDomoticzServices.AMPDeviceService = function(displayName, subtype) {
@@ -152,6 +161,7 @@ eDomoticzServices.CurrentUsage = function() {
152
161
  minStep:0.1
153
162
  });
154
163
  this.value = this.getDefaultValue();
164
+ this.UUID = charUUID;
155
165
  };
156
166
  // The Usage Meter itself
157
167
  eDomoticzServices.UsageDeviceService = function(displayName, subtype) {
@@ -168,6 +178,7 @@ eDomoticzServices.Location = function() {
168
178
  perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
169
179
  });
170
180
  this.value = this.getDefaultValue();
181
+ this.UUID = charUUID;
171
182
  };
172
183
  eDomoticzServices.LocationService = function(displayName, subtype) {
173
184
  var serviceUUID = UUID.generate('eDomoticz:location:customservice');
@@ -187,6 +198,7 @@ eDomoticzServices.WindSpeed = function() {
187
198
  minStep:0.1
188
199
  });
189
200
  this.value = this.getDefaultValue();
201
+ this.UUID = charUUID;
190
202
  };
191
203
  // DarkSkies WindChill Characteristic
192
204
  eDomoticzServices.WindChill = function() {
@@ -201,6 +213,7 @@ eDomoticzServices.WindChill = function() {
201
213
  minStep:0.1
202
214
  });
203
215
  this.value = this.getDefaultValue();
216
+ this.UUID = charUUID;
204
217
  };
205
218
  // DarkSkies WindDirection Characteristic
206
219
  eDomoticzServices.WindDirection = function() {
@@ -215,6 +228,7 @@ eDomoticzServices.WindDirection = function() {
215
228
  minStep:1
216
229
  });
217
230
  this.value = this.getDefaultValue();
231
+ this.UUID = charUUID;
218
232
  };
219
233
  // DarkSkies Virtual Wind Sensor
220
234
  eDomoticzServices.WindDeviceService = function(displayName, subtype) {
@@ -238,6 +252,7 @@ eDomoticzServices.Rainfall = function() {
238
252
  minStep:0.1
239
253
  });
240
254
  this.value = this.getDefaultValue();
255
+ this.UUID = charUUID;
241
256
  };
242
257
  // DarkSkies Rain Meter itself
243
258
  eDomoticzServices.RainDeviceService = function(displayName, subtype) {
@@ -258,6 +273,7 @@ eDomoticzServices.Visibility = function() {
258
273
  minStep:0.1
259
274
  });
260
275
  this.value = this.getDefaultValue();
276
+ this.UUID = charUUID;
261
277
  };
262
278
  // DarkSkies Visibility Meter itself
263
279
  eDomoticzServices.VisibilityDeviceService = function(displayName, subtype) {
@@ -278,6 +294,7 @@ eDomoticzServices.UVIndex = function() {
278
294
  minStep:0.1
279
295
  });
280
296
  this.value = this.getDefaultValue();
297
+ this.UUID = charUUID;
281
298
  };
282
299
 
283
300
  // DarkSkies UV Index Meter itself
@@ -299,6 +316,7 @@ eDomoticzServices.SolRad = function() {
299
316
  minStep:0.1
300
317
  });
301
318
  this.value = this.getDefaultValue();
319
+ this.UUID = charUUID;
302
320
  };
303
321
  // DarkSkies Solar Radiation Meter itself
304
322
  eDomoticzServices.SolRadDeviceService = function(displayName, subtype) {
@@ -319,6 +337,7 @@ eDomoticzServices.Barometer = function() {
319
337
  minStep: 0.1
320
338
  });
321
339
  this.value = this.getDefaultValue();
340
+ this.UUID = charUUID;
322
341
  };
323
342
  // Weather Service
324
343
  eDomoticzServices.WeatherService = function(displayName, subtype) {
@@ -337,6 +356,7 @@ eDomoticzServices.Infotext = function() {
337
356
  perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
338
357
  });
339
358
  this.value = this.getDefaultValue();
359
+ this.UUID = charUUID;
340
360
  };
341
361
  // DarkSkies Visibility Meter itself
342
362
  eDomoticzServices.InfotextDeviceService = function(displayName, subtype) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-edomoticz",
3
- "version": "2.1.39",
3
+ "version": "2.1.45",
4
4
  "description": "homebridge-plugin for Domoticz https://github.com/nfarina/homebridge",
5
5
  "main": "index.js",
6
6
  "scripts": {