homebridge-edomoticz 2.1.39 → 2.1.40

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 CHANGED
File without changes
package/InstallGuide CHANGED
File without changes
package/LICENSE CHANGED
File without changes
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:
@@ -123,12 +124,6 @@ The dimFix variable relates to an early issue between HomeKit and Domoticz regar
123
124
 
124
125
  <details><summary><b>Advanced Configuration</b></summary>
125
126
 
126
- ### Dim Offset
127
- The dimFix variable relates to an early issue between HomeKit and Domoticz regarding scaling of dimmer values. If you find that you can never set your dimmers to 100%, then set this variable to 1. If you find that, when you set your dimmers, this starts a never ending loop of brightness increasing by 1%, then you MUST omit this variable or set it to 0.
128
-
129
- ### Use legacy blind support
130
- 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
127
  ### MQTT
133
128
  By default, the plugin will grab hardware information regarding MQTT from Domoticz if `mqtt` is 1 or true in the configuration file.
134
129
  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
  }
@@ -451,7 +455,7 @@ eDomoticzAccessory.prototype = {
451
455
  value = (value == 0) ? 0.0001 : value;
452
456
  } else if (this.subType == "Waterflow" || (this.name.indexOf("Gas") > -1 && this.Type == "General" && this.subType == "kWh")) {
453
457
  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") {
458
+ } 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
459
  value = (s.Counter !== undefined) ? Helper.cleanFloat(s.Counter) : Helper.cleanFloat(s.Data);
456
460
  } else if (this.subType == "Text") {
457
461
  value = s.Data.toString();
@@ -735,11 +739,8 @@ eDomoticzAccessory.prototype = {
735
739
  });
736
740
  return;
737
741
  }
738
- if (this.platform.config.legacyBlinds == 1) {
739
- var command = (shouldOpen ? "On" : "Off");
740
- } else {
741
- var command = (shouldOpen ? "Close" : "Open");
742
- }
742
+
743
+ var command = (shouldOpen ? "On" : "Off");
743
744
  Domoticz.updateDeviceStatus(this, "switchlight", {
744
745
  "switchcmd": command
745
746
  }, function (success) {
@@ -986,9 +987,9 @@ eDomoticzAccessory.prototype = {
986
987
  callback();
987
988
  return;
988
989
  }
989
-
990
- if (this.hwId.toString() in tvInputAccessories) {
991
- Domoticz.updateDeviceStatus(tvInputAccessories[this.hwId.toString()], "switchlight", {
990
+
991
+ if (this.descript in tvInputAccessories) {
992
+ Domoticz.updateDeviceStatus(tvInputAccessories[this.descript], "switchlight", {
992
993
  "switchcmd": "Set Level",
993
994
  "level": identifier * 10
994
995
  }, function (success) {
@@ -1003,8 +1004,8 @@ eDomoticzAccessory.prototype = {
1003
1004
  callback(null, cachedValue);
1004
1005
  }
1005
1006
 
1006
- if (this.hwId.toString() in tvInputAccessories) {
1007
- Domoticz.deviceStatus(tvInputAccessories[this.hwId.toString()], function (json) {
1007
+ if (this.descript in tvInputAccessories) {
1008
+ Domoticz.deviceStatus(tvInputAccessories[this.descript], function (json) {
1008
1009
  var value = 0;
1009
1010
  var sArray = Helper.sortByKey(json.result, "Name");
1010
1011
  sArray.map(function (s) {
@@ -1020,7 +1021,7 @@ eDomoticzAccessory.prototype = {
1020
1021
  } else if (typeof cachedValue === 'undefined') {
1021
1022
  this.cachedValues[Characteristic.ActiveIdentifier.UUID] = 0;
1022
1023
  callback(null, 0);
1023
- }
1024
+ }
1024
1025
  },
1025
1026
  handleMQTTMessage: function (message, callback) {
1026
1027
  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 +1035,7 @@ eDomoticzAccessory.prototype = {
1034
1035
  if (this.isSwitch) {
1035
1036
  switch (true) {
1036
1037
  case this.swTypeVal == Constants.DeviceTypeSwitch || this.swTypeVal == Constants.DeviceTypePushOn:
1037
- {
1038
+ {
1038
1039
  var service = false;
1039
1040
  if (this.image !== undefined && this.swTypeVal !== Constants.DeviceTypePushOn) {
1040
1041
  if (this.image.indexOf("Fan") > -1) {
@@ -1167,7 +1168,7 @@ eDomoticzAccessory.prototype = {
1167
1168
  callback(characteristic, Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1168
1169
  break;
1169
1170
  }
1170
- case this.swTypeVal == Constants.DeviceTypeSelector && this.image != "TV":
1171
+ case this.swTypeVal == Constants.DeviceTypeSelector && this.image !== "TV":
1171
1172
  {
1172
1173
  var service = this.getService(Service.StatelessProgrammableSwitch);
1173
1174
  var characteristic = this.getCharacteristic(service, Characteristic.ProgrammableSwitchEvent);
@@ -1188,16 +1189,21 @@ eDomoticzAccessory.prototype = {
1188
1189
  }
1189
1190
  case this.swTypeVal == Constants.DeviceTypeSelector && this.image == "TV":
1190
1191
  {
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);
1192
+ var tvAccessory = tvAccessories[this.descript];
1193
+ if (typeof tvAccessory !== undefined) {
1194
+ var tvService = tvAccessory.getService(Service.Television);
1195
+ var characteristic = tvAccessory.getCharacteristic(tvService, Characteristic.ActiveIdentifier);
1196
+ var identifier = parseInt(message.svalue1) / 10;
1197
+ var oldIdentifier = tvAccessory.cachedValues[Characteristic.ActiveIdentifier.UUID];
1198
+
1199
+ if (identifier != oldIdentifier) {
1200
+ tvAccessory.cachedValues[Characteristic.ActiveIdentifier.UUID] = identifier;
1201
+ callback(characteristic, identifier);
1202
+ }
1203
+ } else {
1204
+ callback();
1200
1205
  }
1206
+
1201
1207
  }
1202
1208
  break;
1203
1209
  case this.swTypeVal == Constants.DeviceTypeDoorLock:
@@ -1318,6 +1324,7 @@ eDomoticzAccessory.prototype = {
1318
1324
  }
1319
1325
  }
1320
1326
  }
1327
+
1321
1328
  var lastActivity = false;
1322
1329
  if (this.cachedValues["lastActivity"]) {
1323
1330
  lastActivity = this.cachedValues["lastActivity"];
@@ -1354,29 +1361,36 @@ eDomoticzAccessory.prototype = {
1354
1361
  case this.swTypeVal == Constants.DeviceTypeSecuritySystem:
1355
1362
  {
1356
1363
  var systemState = Characteristic.SecuritySystemCurrentState.STAY_ARM;
1364
+ var targetState = Characteristic.SecuritySystemTargetState.STAY_ARM;
1357
1365
  switch (message.nvalue) {
1358
1366
  case 0: //Disarm
1359
1367
  case 1: //Normal Delay
1360
1368
  case 13: //Disarm
1361
1369
  systemState = Characteristic.SecuritySystemCurrentState.DISARMED;
1370
+ targetState = Characteristic.SecuritySystemTargetState.DISARM;
1362
1371
  break;
1363
1372
  case 9: //Arm Away
1364
1373
  case 10: //Arm Away Delayed
1365
1374
  systemState = Characteristic.SecuritySystemCurrentState.AWAY_ARM;
1375
+ targetState = Characteristic.SecuritySystemTargetState.AWAY_ARM;
1366
1376
  break;
1367
1377
  case 11: //Arm Home
1368
1378
  case 12: //Arm Home Delayed
1369
1379
  systemState = Characteristic.SecuritySystemCurrentState.STAY_ARM;
1380
+ targetState = Characteristic.SecuritySystemTargetState.STAY_ARM;
1370
1381
  break;
1371
1382
  case 6:
1372
1383
  systemState = Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED;
1384
+ targetState = Characteristic.SecuritySystemTargetState.STAY_ARM;
1373
1385
  break;
1374
1386
  default:
1375
- case 2: //Alarm
1387
+ case 2:
1388
+ systemState = Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED;
1389
+ targetState = Characteristic.SecuritySystemTargetState.STAY_ARM;
1390
+ break;
1376
1391
  case 3: //Alarm Delayed
1377
1392
  case 4: //Motion
1378
1393
  case 5: //No Motion
1379
- case 6: //Panic
1380
1394
  case 7: //Panic End
1381
1395
  case 8:
1382
1396
  }
@@ -1386,7 +1400,7 @@ eDomoticzAccessory.prototype = {
1386
1400
  var currentStateCharacteristic = this.getCharacteristic(service, Characteristic.SecuritySystemCurrentState);
1387
1401
  var targetStateCharacteristic = this.getCharacteristic(service, Characteristic.SecuritySystemTargetState);
1388
1402
  callback(currentStateCharacteristic, systemState);
1389
- callback(targetStateCharacteristic, systemState);
1403
+ callback(targetStateCharacteristic, targetState);
1390
1404
  break;
1391
1405
  }
1392
1406
 
@@ -1760,12 +1774,7 @@ eDomoticzAccessory.prototype = {
1760
1774
  this.gracefullyAddCharacteristic(service, Characteristic.Hue).on('set', this.setHueValue.bind(this, 'Hue')).on('get', this.getHueValue.bind(this, 'Hue'));
1761
1775
  this.gracefullyAddCharacteristic(service, Characteristic.Saturation).on('set', this.setHueValue.bind(this, 'Saturation')).on('get', this.getHueValue.bind(this, 'Saturation'));
1762
1776
  } 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
- //}
1777
+ this.gracefullyAddCharacteristic(service, Characteristic.ColorTemperature).on('set', this.setColorTempValue.bind(this, 'ColorTemperature')).on('get', this.getColorTempValue.bind(this, 'ColorTemperature'));
1769
1778
  }
1770
1779
  }
1771
1780
  this.services.push(service);
@@ -1807,8 +1816,8 @@ eDomoticzAccessory.prototype = {
1807
1816
  this.getCharacteristic(tvService, Characteristic.RemoteKey)
1808
1817
  .on('set', this.sendTelevisionRemoteKey.bind(this));
1809
1818
  this.services.push(tvService);
1810
- tvAccessories[this.hwId.toString()] = this;
1811
-
1819
+ tvAccessories[this.descript] = this;
1820
+
1812
1821
  // TV volume.
1813
1822
  var tvSpeakerService = this.getService(Service.TelevisionSpeaker);
1814
1823
  if (!tvSpeakerService) {
@@ -1823,19 +1832,19 @@ eDomoticzAccessory.prototype = {
1823
1832
  .on('get', this.getTelevisionMuteState.bind(this));
1824
1833
  tvService.addLinkedService(tvSpeakerService);
1825
1834
  this.services.push(tvSpeakerService);
1826
-
1827
- if (this.hwId.toString() in tvInputAccessories) {
1828
- this.createTvInputService(tvInputAccessories[this.hwId.toString()]);
1829
- }
1830
-
1835
+
1836
+ if (this.descript in tvInputAccessories) {
1837
+ this.createTvInputService(tvInputAccessories[this.descript]);
1838
+ }
1839
+
1831
1840
  break;
1832
1841
  }
1833
1842
  case this.swTypeVal == Constants.DeviceTypeSelector && this.image == "TV":
1834
1843
  {
1835
- tvInputAccessories[this.hwId.toString()] = this;
1844
+ tvInputAccessories[this.descript] = this;
1836
1845
 
1837
- if (this.hwId.toString() in tvAccessories) {
1838
- tvAccessories[this.hwId.toString()].createTvInputService(this);
1846
+ if (this.descript in tvAccessories) {
1847
+ tvAccessories[this.descript].createTvInputService(this);
1839
1848
  }
1840
1849
 
1841
1850
  break;
@@ -2269,58 +2278,59 @@ eDomoticzAccessory.prototype = {
2269
2278
  },
2270
2279
  createTvInputService: function (domoticzInputSourceAccessory) {
2271
2280
  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;
2281
+ if (typeof tvService !== undefined) {
2282
+ Domoticz.deviceStatus(domoticzInputSourceAccessory, function (json) {
2283
+ var sArray = Helper.sortByKey(json.result, "Name");
2284
+ sArray.map(function (s) {
2285
+ var inputs = new Buffer(s.LevelNames, 'base64').toString("utf8").split("|");
2286
+ if (inputs.length > 0 && inputs[0] == "Off") {
2287
+ inputs.shift();
2296
2288
  }
2297
2289
 
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);
2290
+ inputs.forEach((input, index) => {
2291
+ var inputType;
2292
+ switch (true) {
2293
+ case input.match(/^TV|Live$/i):
2294
+ inputType = Characteristic.InputSourceType.TUNER;
2295
+ break;
2296
+ case input.match(/hdmi/i):
2297
+ inputType = Characteristic.InputSourceType.HDMI;
2298
+ break;
2299
+ case input.match(/ypbpr/i):
2300
+ inputType = Characteristic.InputSourceType.COMPONENT_VIDEO;
2301
+ break;
2302
+ default:
2303
+ inputType = Characteristic.InputSourceType.APPLICATION;
2304
+ break;
2305
+ }
2310
2306
 
2311
- if(this.published) {
2312
- this.publishService(inputService);
2313
- }
2314
- });
2307
+ var inputService = this.getService(Service.InputSource, input);
2308
+ if (!inputService) {
2309
+ inputService = new Service.InputSource(input.replace(/\s/g, '').toLowerCase(), input);
2310
+ }
2311
+ inputService
2312
+ .setCharacteristic(Characteristic.Identifier, index + 1)
2313
+ .setCharacteristic(Characteristic.ConfiguredName, input)
2314
+ .setCharacteristic(Characteristic.IsConfigured, Characteristic.IsConfigured.CONFIGURED)
2315
+ .setCharacteristic(Characteristic.InputSourceType, inputType)
2316
+ .setCharacteristic(Characteristic.CurrentVisibilityState, Characteristic.CurrentVisibilityState.SHOWN);
2317
+ tvService.addLinkedService(inputService);
2318
+ this.services.push(inputService);
2319
+
2320
+ if(this.published) {
2321
+ this.publishService(inputService);
2322
+ }
2323
+ });
2324
+ }.bind(this));
2315
2325
  }.bind(this));
2316
- }.bind(this));
2326
+ }
2317
2327
  },
2318
2328
  removed: function() { // This accessory has been removed.
2319
- if (this.hwId.toString() in tvAccessories) {
2320
- delete tvAccessories[this.hwId.toString()];
2329
+ if (this.descript in tvAccessories) {
2330
+ delete tvAccessories[this.descript];
2321
2331
  }
2322
- if (this.hwId.toString() in tvInputAccessories) {
2323
- delete tvInputAccessories[this.hwId.toString()];
2332
+ if (this.descript in tvInputAccessories) {
2333
+ delete tvInputAccessories[this.descript];
2324
2334
  }
2325
2335
  }
2326
2336
  };
package/lib/helper.js CHANGED
File without changes
package/lib/mqtt.js CHANGED
File without changes
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.40",
4
4
  "description": "homebridge-plugin for Domoticz https://github.com/nfarina/homebridge",
5
5
  "main": "index.js",
6
6
  "scripts": {