homebridge-smartsystem 7.1.6 → 7.1.8

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 +14 -49
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-smartsystem",
3
3
  "displayname": "Duotecno Bridge",
4
- "version": "7.1.6",
4
+ "version": "7.1.8",
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",
@@ -762,11 +762,11 @@ class SmartApp extends webapp_1.WebApp {
762
762
  const devices = this.getDeviceList();
763
763
  if (ws.readyState === WebSocket.OPEN) {
764
764
  const json = JSON.stringify(devices);
765
- (0, logger_1.log)("smartapp", "sendDeviceList -> " + json);
765
+ (0, logger_1.debug)("smartapp", "sendDeviceList -> " + json);
766
766
  ws.send(json);
767
767
  }
768
768
  else {
769
- (0, logger_1.log)("smartapp", "sendDeviceList -> WebSocket not open (state=" + ws.readyState + ")");
769
+ (0, logger_1.err)("smartapp", "sendDeviceList -> WebSocket not open (state=" + ws.readyState + ")");
770
770
  }
771
771
  }
772
772
  getDeviceList() {
@@ -776,7 +776,6 @@ class SmartApp extends webapp_1.WebApp {
776
776
  if (device.unit) {
777
777
  relayState = device.unit.status > 0;
778
778
  }
779
- (0, logger_1.log)("smartapp", `getDeviceList: device "${device.name}" (id=${device.id}) powerSource=${device.powerSource} powerChannel="${device.powerChannel}" relay=${relayState}`);
780
779
  // Get power measurements based on power source
781
780
  let power = 0;
782
781
  let energy = 0;
@@ -815,7 +814,7 @@ class SmartApp extends webapp_1.WebApp {
815
814
  power = relayState ? (device.estimatedPower || 0) : 0;
816
815
  measured = false;
817
816
  }
818
- (0, logger_1.log)("smartapp", `getDeviceList: -> power=${power} measured=${measured}`);
817
+ (0, logger_1.debug)("smartapp", `getDeviceList: device "${device.name}" (id=${device.id}) powerSource=${device.powerSource} powerChannel="${device.powerChannel}" relay=${relayState} power=${power} measured=${measured}`);
819
818
  return {
820
819
  id: device.id,
821
820
  name: device.name,
@@ -832,22 +831,9 @@ class SmartApp extends webapp_1.WebApp {
832
831
  if (!this.power.smappee)
833
832
  return null;
834
833
  try {
835
- // Channel format could be "0", "0+1", "0+1+2", etc.
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}]`);
839
- let totalPower = 0;
840
- for (const ch of channels) {
841
- const binding = this.power.smappee.bindings.find(b => b.channel === ch.toString());
842
- if (binding && binding.value !== undefined) {
843
- (0, logger_1.log)("smartapp", `getPowerFromSmappee: matched ch=${ch} -> value=${binding.value}`);
844
- totalPower += binding.value;
845
- }
846
- else {
847
- (0, logger_1.log)("smartapp", `getPowerFromSmappee: no match for ch=${ch}`);
848
- }
849
- }
850
- return totalPower;
834
+ const power = this.power.smappee.evalPower(channel);
835
+ //log("smartapp", `getPowerFromSmappee: channel="${channel}" -> power=${power}`);
836
+ return power;
851
837
  }
852
838
  catch (e) {
853
839
  (0, logger_1.err)("smartapp", `Error getting Smappee power for channel ${channel}: ${e.message}`);
@@ -858,16 +844,9 @@ class SmartApp extends webapp_1.WebApp {
858
844
  if (!this.power.p1)
859
845
  return null;
860
846
  try {
861
- // P1 meter typically has single power value
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);
865
- if (binding && binding.value !== undefined) {
866
- (0, logger_1.log)("smartapp", `getPowerFromP1: matched ch=${channel} -> value=${binding.value}`);
867
- return binding.value;
868
- }
869
- (0, logger_1.log)("smartapp", `getPowerFromP1: no match for channel "${channel}"`);
870
- return null;
847
+ const power = this.power.p1.evalPower(channel);
848
+ //log("smartapp", `getPowerFromP1: channel="${channel}" -> power=${power}`);
849
+ return power;
871
850
  }
872
851
  catch (e) {
873
852
  (0, logger_1.err)("smartapp", `Error getting P1 power for channel ${channel}: ${e.message}`);
@@ -878,22 +857,9 @@ class SmartApp extends webapp_1.WebApp {
878
857
  if (!this.power.shelly)
879
858
  return null;
880
859
  try {
881
- // Shelly channel format similar to Smappee
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}]`);
885
- let totalPower = 0;
886
- for (const ch of channels) {
887
- const binding = this.power.shelly.bindings.find(b => b.channel === ch.toString());
888
- if (binding && binding.value !== undefined) {
889
- (0, logger_1.log)("smartapp", `getPowerFromShelly: matched ch=${ch} -> value=${binding.value}`);
890
- totalPower += binding.value;
891
- }
892
- else {
893
- (0, logger_1.log)("smartapp", `getPowerFromShelly: no match for ch=${ch}`);
894
- }
895
- }
896
- return totalPower;
860
+ const power = this.power.shelly.evalPower(channel);
861
+ //log("smartapp", `getPowerFromShelly: channel="${channel}" -> power=${power}`);
862
+ return power;
897
863
  }
898
864
  catch (e) {
899
865
  (0, logger_1.err)("smartapp", `Error getting Shelly power for channel ${channel}: ${e.message}`);
@@ -902,7 +868,7 @@ class SmartApp extends webapp_1.WebApp {
902
868
  }
903
869
  handleDeviceMessage(ws, data) {
904
870
  return __awaiter(this, void 0, void 0, function* () {
905
- (0, logger_1.log)("smartapp", "handleDeviceMessage: received -> " + JSON.stringify(data));
871
+ //log("smartapp", "handleDeviceMessage: received -> " + JSON.stringify(data));
906
872
  if (!Array.isArray(data)) {
907
873
  (0, logger_1.err)("smartapp", "WebSocket message must be an array");
908
874
  return;
@@ -910,7 +876,6 @@ class SmartApp extends webapp_1.WebApp {
910
876
  // Process relay control commands if any
911
877
  for (const cmd of data) {
912
878
  if (cmd.id && cmd.relay !== undefined) {
913
- (0, logger_1.log)("smartapp", `handleDeviceMessage: relay command id=${cmd.id} state=${cmd.relay}`);
914
879
  yield this.setDeviceRelay(cmd.id, cmd.relay);
915
880
  }
916
881
  }
@@ -923,7 +888,6 @@ class SmartApp extends webapp_1.WebApp {
923
888
  // Convert ID to node/unit (id = node * 256 + unit)
924
889
  const node = Math.floor(id / 256);
925
890
  const unit = id % 256;
926
- (0, logger_1.log)("smartapp", `Setting device ${id} (node=${node}, unit=${unit}) to ${state}`);
927
891
  // Get the first master
928
892
  const master = this.system.masters[0];
929
893
  if (!master) {
@@ -942,6 +906,7 @@ class SmartApp extends webapp_1.WebApp {
942
906
  return;
943
907
  }
944
908
  // Set the unit state
909
+ (0, logger_1.debug)("smartapp", `Setting device ${id} (node=${node}, unit=${unit}) to ${state}`);
945
910
  yield master.setUnitStatus(unitObj, state);
946
911
  });
947
912
  }