homebridge-smartsystem 7.1.4 → 7.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server/smartapp.js +29 -6
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-smartsystem",
3
3
  "displayname": "Duotecno Bridge",
4
- "version": "7.1.4",
4
+ "version": "7.1.6",
5
5
  "description": "SmartServer (Proxy TCP sockets to the cloud, Smappee MQTT, Duotecno IP Nodes, Homekit interface)",
6
6
  "main": "index.js",
7
7
  "author": "Johan Coppieters",
@@ -760,10 +760,13 @@ class SmartApp extends webapp_1.WebApp {
760
760
  //////////////////////
761
761
  sendDeviceList(ws) {
762
762
  const devices = this.getDeviceList();
763
- console.log("Sending device list to WebSocket client: " + JSON.stringify(devices));
764
763
  if (ws.readyState === WebSocket.OPEN) {
765
- (0, logger_1.debug)("smartapp", devices);
766
- ws.send(JSON.stringify(devices));
764
+ const json = JSON.stringify(devices);
765
+ (0, logger_1.log)("smartapp", "sendDeviceList -> " + json);
766
+ ws.send(json);
767
+ }
768
+ else {
769
+ (0, logger_1.log)("smartapp", "sendDeviceList -> WebSocket not open (state=" + ws.readyState + ")");
767
770
  }
768
771
  }
769
772
  getDeviceList() {
@@ -773,6 +776,7 @@ class SmartApp extends webapp_1.WebApp {
773
776
  if (device.unit) {
774
777
  relayState = device.unit.status > 0;
775
778
  }
779
+ (0, logger_1.log)("smartapp", `getDeviceList: device "${device.name}" (id=${device.id}) powerSource=${device.powerSource} powerChannel="${device.powerChannel}" relay=${relayState}`);
776
780
  // Get power measurements based on power source
777
781
  let power = 0;
778
782
  let energy = 0;
@@ -811,6 +815,7 @@ class SmartApp extends webapp_1.WebApp {
811
815
  power = relayState ? (device.estimatedPower || 0) : 0;
812
816
  measured = false;
813
817
  }
818
+ (0, logger_1.log)("smartapp", `getDeviceList: -> power=${power} measured=${measured}`);
814
819
  return {
815
820
  id: device.id,
816
821
  name: device.name,
@@ -829,12 +834,18 @@ class SmartApp extends webapp_1.WebApp {
829
834
  try {
830
835
  // Channel format could be "0", "0+1", "0+1+2", etc.
831
836
  const channels = channel.split('+').map(c => parseInt(c.trim()));
837
+ const available = this.power.smappee.bindings.map(b => `ch=${b.channel}(${b.value})`).join(', ');
838
+ (0, logger_1.log)("smartapp", `getPowerFromSmappee: looking for channel(s) [${channels}], available bindings: [${available}]`);
832
839
  let totalPower = 0;
833
840
  for (const ch of channels) {
834
- const binding = this.power.smappee.bindings.find(b => b.channel.includes(ch.toString()));
841
+ const binding = this.power.smappee.bindings.find(b => b.channel === ch.toString());
835
842
  if (binding && binding.value !== undefined) {
843
+ (0, logger_1.log)("smartapp", `getPowerFromSmappee: matched ch=${ch} -> value=${binding.value}`);
836
844
  totalPower += binding.value;
837
845
  }
846
+ else {
847
+ (0, logger_1.log)("smartapp", `getPowerFromSmappee: no match for ch=${ch}`);
848
+ }
838
849
  }
839
850
  return totalPower;
840
851
  }
@@ -848,10 +859,14 @@ class SmartApp extends webapp_1.WebApp {
848
859
  return null;
849
860
  try {
850
861
  // P1 meter typically has single power value
851
- const binding = this.power.p1.bindings.find(b => b.channel.includes(channel));
862
+ const available = this.power.p1.bindings.map(b => `ch=${b.channel}(${b.value})`).join(', ');
863
+ (0, logger_1.log)("smartapp", `getPowerFromP1: looking for channel "${channel}", available bindings: [${available}]`);
864
+ const binding = this.power.p1.bindings.find(b => b.channel === channel);
852
865
  if (binding && binding.value !== undefined) {
866
+ (0, logger_1.log)("smartapp", `getPowerFromP1: matched ch=${channel} -> value=${binding.value}`);
853
867
  return binding.value;
854
868
  }
869
+ (0, logger_1.log)("smartapp", `getPowerFromP1: no match for channel "${channel}"`);
855
870
  return null;
856
871
  }
857
872
  catch (e) {
@@ -865,12 +880,18 @@ class SmartApp extends webapp_1.WebApp {
865
880
  try {
866
881
  // Shelly channel format similar to Smappee
867
882
  const channels = channel.split('+').map(c => parseInt(c.trim()));
883
+ const available = this.power.shelly.bindings.map(b => `ch=${b.channel}(${b.value})`).join(', ');
884
+ (0, logger_1.log)("smartapp", `getPowerFromShelly: looking for channel(s) [${channels}], available bindings: [${available}]`);
868
885
  let totalPower = 0;
869
886
  for (const ch of channels) {
870
- const binding = this.power.shelly.bindings.find(b => b.channel.includes(ch.toString()));
887
+ const binding = this.power.shelly.bindings.find(b => b.channel === ch.toString());
871
888
  if (binding && binding.value !== undefined) {
889
+ (0, logger_1.log)("smartapp", `getPowerFromShelly: matched ch=${ch} -> value=${binding.value}`);
872
890
  totalPower += binding.value;
873
891
  }
892
+ else {
893
+ (0, logger_1.log)("smartapp", `getPowerFromShelly: no match for ch=${ch}`);
894
+ }
874
895
  }
875
896
  return totalPower;
876
897
  }
@@ -881,6 +902,7 @@ class SmartApp extends webapp_1.WebApp {
881
902
  }
882
903
  handleDeviceMessage(ws, data) {
883
904
  return __awaiter(this, void 0, void 0, function* () {
905
+ (0, logger_1.log)("smartapp", "handleDeviceMessage: received -> " + JSON.stringify(data));
884
906
  if (!Array.isArray(data)) {
885
907
  (0, logger_1.err)("smartapp", "WebSocket message must be an array");
886
908
  return;
@@ -888,6 +910,7 @@ class SmartApp extends webapp_1.WebApp {
888
910
  // Process relay control commands if any
889
911
  for (const cmd of data) {
890
912
  if (cmd.id && cmd.relay !== undefined) {
913
+ (0, logger_1.log)("smartapp", `handleDeviceMessage: relay command id=${cmd.id} state=${cmd.relay}`);
891
914
  yield this.setDeviceRelay(cmd.id, cmd.relay);
892
915
  }
893
916
  }