@victronenergy/mfd-modules 10.4.2 → 11.1.0

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 (234) hide show
  1. package/README.md +1 -1
  2. package/dist/src/Modules/AcLoads/AcLoads.provider.d.ts.map +1 -1
  3. package/dist/src/Modules/AcLoads/AcLoads.provider.js +19 -19
  4. package/dist/src/Modules/AcLoads/AcLoads.provider.js.map +1 -1
  5. package/dist/src/Modules/AcMode/AcMode.provider.d.ts.map +1 -1
  6. package/dist/src/Modules/AcMode/AcMode.provider.js +19 -31
  7. package/dist/src/Modules/AcMode/AcMode.provider.js.map +1 -1
  8. package/dist/src/Modules/ActiveSource/ActiveInValues.provider.js +17 -17
  9. package/dist/src/Modules/ActiveSource/ActiveInValues.provider.js.map +1 -1
  10. package/dist/src/Modules/ActiveSource/ActiveSource.provider.js +11 -11
  11. package/dist/src/Modules/ActiveSource/ActiveSource.provider.js.map +1 -1
  12. package/dist/src/Modules/Alternators/Alternator.provider.d.ts.map +1 -1
  13. package/dist/src/Modules/Alternators/Alternator.provider.js +7 -8
  14. package/dist/src/Modules/Alternators/Alternator.provider.js.map +1 -1
  15. package/dist/src/Modules/Alternators/Alternators.provider.d.ts.map +1 -1
  16. package/dist/src/Modules/Alternators/Alternators.provider.js +16 -14
  17. package/dist/src/Modules/Alternators/Alternators.provider.js.map +1 -1
  18. package/dist/src/Modules/Alternators/Alternators.store.d.ts.map +1 -1
  19. package/dist/src/Modules/Alternators/Alternators.store.js +7 -10
  20. package/dist/src/Modules/Alternators/Alternators.store.js.map +1 -1
  21. package/dist/src/Modules/App/App.provider.js +47 -47
  22. package/dist/src/Modules/App/App.provider.js.map +1 -1
  23. package/dist/src/Modules/App/App.store.d.ts +2 -2
  24. package/dist/src/Modules/App/App.store.d.ts.map +1 -1
  25. package/dist/src/Modules/App/App.store.js +67 -110
  26. package/dist/src/Modules/App/App.store.js.map +1 -1
  27. package/dist/src/Modules/Battery/Batteries.provider.d.ts.map +1 -1
  28. package/dist/src/Modules/Battery/Batteries.provider.js +16 -14
  29. package/dist/src/Modules/Battery/Batteries.provider.js.map +1 -1
  30. package/dist/src/Modules/Battery/Batteries.store.d.ts.map +1 -1
  31. package/dist/src/Modules/Battery/Batteries.store.js +7 -10
  32. package/dist/src/Modules/Battery/Batteries.store.js.map +1 -1
  33. package/dist/src/Modules/Battery/SystemBatteries.provider.js +5 -5
  34. package/dist/src/Modules/Battery/SystemBatteries.provider.js.map +1 -1
  35. package/dist/src/Modules/Chargers/Charger.provider.js +23 -33
  36. package/dist/src/Modules/Chargers/Charger.provider.js.map +1 -1
  37. package/dist/src/Modules/Chargers/Chargers.provider.d.ts.map +1 -1
  38. package/dist/src/Modules/Chargers/Chargers.provider.js +16 -15
  39. package/dist/src/Modules/Chargers/Chargers.provider.js.map +1 -1
  40. package/dist/src/Modules/Chargers/Chargers.store.d.ts.map +1 -1
  41. package/dist/src/Modules/Chargers/Chargers.store.js +7 -10
  42. package/dist/src/Modules/Chargers/Chargers.store.js.map +1 -1
  43. package/dist/src/Modules/DcLoads/DcLoads.provider.d.ts.map +1 -1
  44. package/dist/src/Modules/DcLoads/DcLoads.provider.js +9 -20
  45. package/dist/src/Modules/DcLoads/DcLoads.provider.js.map +1 -1
  46. package/dist/src/Modules/Generators/ConnectedGenset.provider.d.ts.map +1 -1
  47. package/dist/src/Modules/Generators/ConnectedGenset.provider.js +36 -47
  48. package/dist/src/Modules/Generators/ConnectedGenset.provider.js.map +1 -1
  49. package/dist/src/Modules/Generators/ConnectedGensets.provider.d.ts.map +1 -1
  50. package/dist/src/Modules/Generators/ConnectedGensets.provider.js +16 -14
  51. package/dist/src/Modules/Generators/ConnectedGensets.provider.js.map +1 -1
  52. package/dist/src/Modules/Generators/ConnectedGensets.store.d.ts.map +1 -1
  53. package/dist/src/Modules/Generators/ConnectedGensets.store.js +8 -11
  54. package/dist/src/Modules/Generators/ConnectedGensets.store.js.map +1 -1
  55. package/dist/src/Modules/Generators/GeneratorConnectedGenset.provider.js +17 -27
  56. package/dist/src/Modules/Generators/GeneratorConnectedGenset.provider.js.map +1 -1
  57. package/dist/src/Modules/Generators/GeneratorRelay.provider.d.ts +2 -2
  58. package/dist/src/Modules/Generators/GeneratorRelay.provider.d.ts.map +1 -1
  59. package/dist/src/Modules/Generators/GeneratorRelay.provider.js +24 -34
  60. package/dist/src/Modules/Generators/GeneratorRelay.provider.js.map +1 -1
  61. package/dist/src/Modules/Header/Header.provider.js +4 -4
  62. package/dist/src/Modules/Header/Header.provider.js.map +1 -1
  63. package/dist/src/Modules/InverterCharger/InputLimit.provider.js +6 -17
  64. package/dist/src/Modules/InverterCharger/InputLimit.provider.js.map +1 -1
  65. package/dist/src/Modules/InverterCharger/InputLimitSelector.provider.d.ts.map +1 -1
  66. package/dist/src/Modules/InverterCharger/InputLimitSelector.provider.js +12 -26
  67. package/dist/src/Modules/InverterCharger/InputLimitSelector.provider.js.map +1 -1
  68. package/dist/src/Modules/InverterCharger/InverterCharger.provider.d.ts.map +1 -1
  69. package/dist/src/Modules/InverterCharger/InverterCharger.provider.js +16 -27
  70. package/dist/src/Modules/InverterCharger/InverterCharger.provider.js.map +1 -1
  71. package/dist/src/Modules/Inverters/Inverter.provider.d.ts.map +1 -1
  72. package/dist/src/Modules/Inverters/Inverter.provider.js +19 -30
  73. package/dist/src/Modules/Inverters/Inverter.provider.js.map +1 -1
  74. package/dist/src/Modules/Inverters/Inverters.provider.d.ts.map +1 -1
  75. package/dist/src/Modules/Inverters/Inverters.provider.js +14 -13
  76. package/dist/src/Modules/Inverters/Inverters.provider.js.map +1 -1
  77. package/dist/src/Modules/Inverters/Inverters.store.d.ts.map +1 -1
  78. package/dist/src/Modules/Inverters/Inverters.store.js +7 -10
  79. package/dist/src/Modules/Inverters/Inverters.store.js.map +1 -1
  80. package/dist/src/Modules/Inverters/index.js.map +1 -1
  81. package/dist/src/Modules/Language/Language.provider.d.ts +1 -1
  82. package/dist/src/Modules/Language/Language.provider.d.ts.map +1 -1
  83. package/dist/src/Modules/Language/Language.provider.js +21 -56
  84. package/dist/src/Modules/Language/Language.provider.js.map +1 -1
  85. package/dist/src/Modules/Mqtt/Mqtt.constants.js +1 -1
  86. package/dist/src/Modules/Mqtt/Mqtt.constants.js.map +1 -1
  87. package/dist/src/Modules/Mqtt/Mqtt.provider.d.ts +2 -2
  88. package/dist/src/Modules/Mqtt/Mqtt.provider.d.ts.map +1 -1
  89. package/dist/src/Modules/Mqtt/Mqtt.provider.js +4 -4
  90. package/dist/src/Modules/Mqtt/Mqtt.provider.js.map +1 -1
  91. package/dist/src/Modules/Mqtt/Mqtt.store.d.ts +3 -3
  92. package/dist/src/Modules/Mqtt/Mqtt.store.d.ts.map +1 -1
  93. package/dist/src/Modules/Mqtt/Mqtt.store.js +169 -193
  94. package/dist/src/Modules/Mqtt/Mqtt.store.js.map +1 -1
  95. package/dist/src/Modules/Mqtt/Mqtt.types.d.ts +1 -1
  96. package/dist/src/Modules/Mqtt/Mqtt.types.d.ts.map +1 -1
  97. package/dist/src/Modules/Mqtt/Mqtt.types.js +0 -1
  98. package/dist/src/Modules/Mqtt/Mqtt.types.js.map +1 -1
  99. package/dist/src/Modules/PvCharger/PvCharger.provider.js +8 -8
  100. package/dist/src/Modules/PvCharger/PvCharger.provider.js.map +1 -1
  101. package/dist/src/Modules/ShorePowerInput/ShorePowerInput.provider.d.ts +4 -1
  102. package/dist/src/Modules/ShorePowerInput/ShorePowerInput.provider.d.ts.map +1 -1
  103. package/dist/src/Modules/ShorePowerInput/ShorePowerInput.provider.js +24 -35
  104. package/dist/src/Modules/ShorePowerInput/ShorePowerInput.provider.js.map +1 -1
  105. package/dist/src/Modules/ShorePowerInput/index.d.ts +0 -1
  106. package/dist/src/Modules/ShorePowerInput/index.d.ts.map +1 -1
  107. package/dist/src/Modules/ShorePowerInput/index.js +0 -1
  108. package/dist/src/Modules/ShorePowerInput/index.js.map +1 -1
  109. package/dist/src/Modules/SwitchingPane/GenericInput.provider.d.ts +27 -0
  110. package/dist/src/Modules/SwitchingPane/GenericInput.provider.d.ts.map +1 -0
  111. package/dist/src/Modules/SwitchingPane/GenericInput.provider.js +32 -0
  112. package/dist/src/Modules/SwitchingPane/GenericInput.provider.js.map +1 -0
  113. package/dist/src/Modules/{SwitchableOutputs → SwitchingPane}/SwitchableOutput.provider.d.ts +28 -9
  114. package/dist/src/Modules/SwitchingPane/SwitchableOutput.provider.d.ts.map +1 -0
  115. package/dist/src/Modules/SwitchingPane/SwitchableOutput.provider.js +59 -0
  116. package/dist/src/Modules/SwitchingPane/SwitchableOutput.provider.js.map +1 -0
  117. package/dist/src/Modules/SwitchingPane/SwitchingDevice.provider.d.ts.map +1 -0
  118. package/dist/src/Modules/SwitchingPane/SwitchingDevice.provider.js +48 -0
  119. package/dist/src/Modules/SwitchingPane/SwitchingDevice.provider.js.map +1 -0
  120. package/dist/src/Modules/SwitchingPane/SwitchingDevices.store.d.ts.map +1 -0
  121. package/dist/src/Modules/{SwitchableOutputs → SwitchingPane}/SwitchingDevices.store.js +7 -10
  122. package/dist/src/Modules/SwitchingPane/SwitchingDevices.store.js.map +1 -0
  123. package/dist/src/Modules/SwitchingPane/SwitchingPane.provider.d.ts +2 -0
  124. package/dist/src/Modules/SwitchingPane/SwitchingPane.provider.d.ts.map +1 -0
  125. package/dist/src/Modules/SwitchingPane/SwitchingPane.provider.js +274 -0
  126. package/dist/src/Modules/SwitchingPane/SwitchingPane.provider.js.map +1 -0
  127. package/dist/src/Modules/SwitchingPane/SwitchingPane.store.d.ts +53 -0
  128. package/dist/src/Modules/SwitchingPane/SwitchingPane.store.d.ts.map +1 -0
  129. package/dist/src/Modules/SwitchingPane/SwitchingPane.store.js +178 -0
  130. package/dist/src/Modules/SwitchingPane/SwitchingPane.store.js.map +1 -0
  131. package/dist/src/Modules/SwitchingPane/index.d.ts +7 -0
  132. package/dist/src/Modules/SwitchingPane/index.d.ts.map +1 -0
  133. package/dist/src/Modules/SwitchingPane/index.js +7 -0
  134. package/dist/src/Modules/SwitchingPane/index.js.map +1 -0
  135. package/dist/src/Modules/SystemState/SystemState.provider.js +5 -5
  136. package/dist/src/Modules/SystemState/SystemState.provider.js.map +1 -1
  137. package/dist/src/Modules/Tanks/Tank.provider.d.ts.map +1 -1
  138. package/dist/src/Modules/Tanks/Tank.provider.js +11 -11
  139. package/dist/src/Modules/Tanks/Tank.provider.js.map +1 -1
  140. package/dist/src/Modules/Tanks/Tanks.provider.d.ts.map +1 -1
  141. package/dist/src/Modules/Tanks/Tanks.provider.js +19 -18
  142. package/dist/src/Modules/Tanks/Tanks.provider.js.map +1 -1
  143. package/dist/src/Modules/Tanks/Tanks.store.d.ts.map +1 -1
  144. package/dist/src/Modules/Tanks/Tanks.store.js +7 -10
  145. package/dist/src/Modules/Tanks/Tanks.store.js.map +1 -1
  146. package/dist/src/Modules/Temperatures/Temperature.provider.d.ts.map +1 -1
  147. package/dist/src/Modules/Temperatures/Temperature.provider.js +29 -29
  148. package/dist/src/Modules/Temperatures/Temperature.provider.js.map +1 -1
  149. package/dist/src/Modules/Temperatures/Temperatures.provider.d.ts.map +1 -1
  150. package/dist/src/Modules/Temperatures/Temperatures.provider.js +18 -17
  151. package/dist/src/Modules/Temperatures/Temperatures.provider.js.map +1 -1
  152. package/dist/src/Modules/Temperatures/Temperatures.store.d.ts.map +1 -1
  153. package/dist/src/Modules/Temperatures/Temperatures.store.js +7 -10
  154. package/dist/src/Modules/Temperatures/Temperatures.store.js.map +1 -1
  155. package/dist/src/Modules/Temperatures/index.d.ts +3 -3
  156. package/dist/src/Modules/Temperatures/index.js +3 -3
  157. package/dist/src/Modules/Temperatures/index.js.map +1 -1
  158. package/dist/src/Modules/Theme/Theme.provider.js +6 -6
  159. package/dist/src/Modules/Theme/Theme.provider.js.map +1 -1
  160. package/dist/src/Modules/Theme/Theme.store.d.ts.map +1 -1
  161. package/dist/src/Modules/Theme/Theme.store.js +35 -38
  162. package/dist/src/Modules/Theme/Theme.store.js.map +1 -1
  163. package/dist/src/Modules/Vebus/Vebus.provider.d.ts.map +1 -1
  164. package/dist/src/Modules/Vebus/Vebus.provider.js +39 -48
  165. package/dist/src/Modules/Vebus/Vebus.provider.js.map +1 -1
  166. package/dist/src/Modules/Vebus/Vebus.store.d.ts.map +1 -1
  167. package/dist/src/Modules/Vebus/Vebus.store.js +11 -14
  168. package/dist/src/Modules/Vebus/Vebus.store.js.map +1 -1
  169. package/dist/src/Modules/Vrm/Vrm.store.d.ts.map +1 -1
  170. package/dist/src/Modules/Vrm/Vrm.store.js +85 -154
  171. package/dist/src/Modules/Vrm/Vrm.store.js.map +1 -1
  172. package/dist/src/Modules/Vrm/Vrm.types.js +0 -1
  173. package/dist/src/Modules/WindGenerators/WindGenerator.provider.d.ts.map +1 -1
  174. package/dist/src/Modules/WindGenerators/WindGenerator.provider.js +6 -7
  175. package/dist/src/Modules/WindGenerators/WindGenerator.provider.js.map +1 -1
  176. package/dist/src/Modules/WindGenerators/WindGenerators.provider.d.ts.map +1 -1
  177. package/dist/src/Modules/WindGenerators/WindGenerators.provider.js +21 -19
  178. package/dist/src/Modules/WindGenerators/WindGenerators.provider.js.map +1 -1
  179. package/dist/src/Modules/WindGenerators/WindGenerators.store.d.ts.map +1 -1
  180. package/dist/src/Modules/WindGenerators/WindGenerators.store.js +7 -10
  181. package/dist/src/Modules/WindGenerators/WindGenerators.store.js.map +1 -1
  182. package/dist/src/index.d.ts +2 -1
  183. package/dist/src/index.d.ts.map +1 -1
  184. package/dist/src/index.js +2 -1
  185. package/dist/src/index.js.map +1 -1
  186. package/dist/src/utils/constants.d.ts +57 -3
  187. package/dist/src/utils/constants.d.ts.map +1 -1
  188. package/dist/src/utils/constants.js +86 -30
  189. package/dist/src/utils/constants.js.map +1 -1
  190. package/dist/src/utils/hsvw.d.ts.map +1 -1
  191. package/dist/src/utils/hsvw.js +24 -25
  192. package/dist/src/utils/hsvw.js.map +1 -1
  193. package/dist/src/utils/logger.d.ts +5 -8
  194. package/dist/src/utils/logger.d.ts.map +1 -1
  195. package/dist/src/utils/logger.js +11 -23
  196. package/dist/src/utils/logger.js.map +1 -1
  197. package/dist/src/utils/storage.d.ts.map +1 -1
  198. package/dist/src/utils/storage.js +7 -6
  199. package/dist/src/utils/storage.js.map +1 -1
  200. package/dist/src/utils/util.d.ts +6 -15
  201. package/dist/src/utils/util.d.ts.map +1 -1
  202. package/dist/src/utils/util.js +8 -100
  203. package/dist/src/utils/util.js.map +1 -1
  204. package/package.json +26 -15
  205. package/dist/eslint.config.d.mts +0 -13
  206. package/dist/eslint.config.d.mts.map +0 -1
  207. package/dist/eslint.config.mjs +0 -28
  208. package/dist/eslint.config.mjs.map +0 -1
  209. package/dist/src/Modules/ShorePowerInput/ShorePowerInput.store.d.ts +0 -11
  210. package/dist/src/Modules/ShorePowerInput/ShorePowerInput.store.d.ts.map +0 -1
  211. package/dist/src/Modules/ShorePowerInput/ShorePowerInput.store.js +0 -37
  212. package/dist/src/Modules/ShorePowerInput/ShorePowerInput.store.js.map +0 -1
  213. package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.d.ts.map +0 -1
  214. package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.js +0 -67
  215. package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.js.map +0 -1
  216. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.d.ts +0 -2
  217. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.d.ts.map +0 -1
  218. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js +0 -168
  219. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js.map +0 -1
  220. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.d.ts +0 -38
  221. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.d.ts.map +0 -1
  222. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.js +0 -116
  223. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.js.map +0 -1
  224. package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.d.ts.map +0 -1
  225. package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.js +0 -50
  226. package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.js.map +0 -1
  227. package/dist/src/Modules/SwitchableOutputs/SwitchingDevices.store.d.ts.map +0 -1
  228. package/dist/src/Modules/SwitchableOutputs/SwitchingDevices.store.js.map +0 -1
  229. package/dist/src/Modules/SwitchableOutputs/index.d.ts +0 -6
  230. package/dist/src/Modules/SwitchableOutputs/index.d.ts.map +0 -1
  231. package/dist/src/Modules/SwitchableOutputs/index.js +0 -6
  232. package/dist/src/Modules/SwitchableOutputs/index.js.map +0 -1
  233. /package/dist/src/Modules/{SwitchableOutputs → SwitchingPane}/SwitchingDevice.provider.d.ts +0 -0
  234. /package/dist/src/Modules/{SwitchableOutputs → SwitchingPane}/SwitchingDevices.store.d.ts +0 -0
@@ -6,10 +6,9 @@ import Logger from "../../utils/logger";
6
6
  import { getMessageJson } from "../../utils/util";
7
7
  import { useMemo } from "react";
8
8
  import { assign } from "lodash-es";
9
- var store;
10
- var MqttStore = /** @class */ (function () {
11
- function MqttStore() {
12
- var _this = this;
9
+ let store;
10
+ export class MqttStore {
11
+ constructor() {
13
12
  Object.defineProperty(this, "client", {
14
13
  enumerable: true,
15
14
  configurable: true,
@@ -103,10 +102,10 @@ var MqttStore = /** @class */ (function () {
103
102
  enumerable: true,
104
103
  configurable: true,
105
104
  writable: true,
106
- value: computedFn(function (topic) {
105
+ value: computedFn((topic) => {
107
106
  // Logger.log(`DEBUG: messageFromTopic: ${JSON.stringify(topic)}`)
108
107
  // trace()
109
- return topic ? _this.messages[topic] : undefined;
108
+ return topic ? this.messages[topic] : undefined;
110
109
  }, { name: "Mqtt.store.messageFromTopic", equals: comparer.identity })
111
110
  });
112
111
  /**
@@ -132,23 +131,22 @@ var MqttStore = /** @class */ (function () {
132
131
  enumerable: true,
133
132
  configurable: true,
134
133
  writable: true,
135
- value: computedFn(function (topics) {
134
+ value: computedFn((topics) => {
136
135
  // Logger.log(`DEBUG: messagesByTopics: ${JSON.stringify(topics)}`)
137
136
  // trace()
138
137
  if (!topics) {
139
138
  return {};
140
139
  }
141
- var result = {};
142
- Object.entries(topics).forEach(function (_a) {
143
- var label = _a[0], topic = _a[1];
140
+ const result = {};
141
+ Object.entries(topics).forEach(([label, topic]) => {
144
142
  if (Array.isArray(topic)) {
145
- result[label] = topic.map(function (t) { return _this.messageFromTopic(t); });
143
+ result[label] = topic.map((t) => this.messageFromTopic(t));
146
144
  }
147
145
  else if (topic === undefined) {
148
146
  result[label] = undefined;
149
147
  }
150
148
  else {
151
- result[label] = _this.messageFromTopic(topic);
149
+ result[label] = this.messageFromTopic(topic);
152
150
  }
153
151
  });
154
152
  return result;
@@ -176,47 +174,47 @@ var MqttStore = /** @class */ (function () {
176
174
  enumerable: true,
177
175
  configurable: true,
178
176
  writable: true,
179
- value: computedFn(function (wildcard) {
177
+ value: computedFn((wildcard) => {
180
178
  // Logger.log(`DEBUG: messagesByWildcard: ${JSON.stringify(wildcard)}`)
181
179
  // trace()
182
180
  if (wildcard === undefined || wildcard === "" || wildcard === null)
183
181
  return {};
184
- var topicRegex = new RegExp(wildcard.replace(/\+/g, "\\w*")); // + in mqtt is anything -> .*
185
- return Object.fromEntries(Object.keys(_this.messages)
186
- .filter(function (topic) { return topic.match(topicRegex); })
187
- .map(function (topic) { return [topic, _this.messages[topic]]; })
182
+ const topicRegex = new RegExp(wildcard.replace(/\+/g, "\\w*")); // + in mqtt is anything -> .*
183
+ return Object.fromEntries(Object.keys(this.messages)
184
+ .filter((topic) => topic.match(topicRegex))
185
+ .map((topic) => [topic, this.messages[topic]])
188
186
  // Filter out empty results
189
- .filter(function (_a) {
190
- var _ = _a[0], message = _a[1];
191
- return message !== undefined &&
192
- message !== null &&
193
- (!Array.isArray(message) ||
194
- (message.length !== 0 && !message.every(function (v) { return v === undefined || v === null; })));
195
- }));
187
+ .filter(([_key, message]) => message !== undefined &&
188
+ message !== null &&
189
+ (!Array.isArray(message) ||
190
+ (message.length !== 0 && !message.every((v) => v === undefined || v === null)))));
196
191
  }, { name: "Mqtt.store.messagesByWildcard", equals: comparer.identity })
197
192
  });
198
193
  Object.defineProperty(this, "subscribeToTopic", {
199
194
  enumerable: true,
200
195
  configurable: true,
201
196
  writable: true,
202
- value: function (topic) {
197
+ value: (topic) => {
203
198
  var _a;
204
199
  if (!topic)
205
200
  return;
206
201
  if (topic.includes("undefined"))
207
202
  return;
208
- if (!_this.topicsSubscribed.has(topic)) {
209
- Logger.log("Subscribing to ".concat(topic));
210
- (_a = _this.client) === null || _a === void 0 ? void 0 : _a.subscribe(topic, function (err, granted) {
203
+ if (!this.topicsSubscribed.has(topic)) {
204
+ Logger.log(`Subscribing to ${topic}`);
205
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.subscribe(topic, (err, granted) => {
211
206
  if (err) {
212
207
  Logger.error(err);
213
208
  return;
214
209
  }
215
- granted !== undefined && granted[0]
216
- ? Logger.log("Subscribed to ".concat(granted[0].topic, " with Qos ").concat(granted[0].qos))
217
- : Logger.log("Subscribed to ".concat(topic, " with Qos unknown"));
210
+ if (granted !== undefined && granted[0]) {
211
+ Logger.log(`Subscribed to ${granted[0].topic} with Qos ${granted[0].qos}`);
212
+ }
213
+ else {
214
+ Logger.log(`Subscribed to ${topic} with Qos unknown`);
215
+ }
218
216
  });
219
- _this.topicsSubscribed.add(topic);
217
+ this.topicsSubscribed.add(topic);
220
218
  }
221
219
  }
222
220
  });
@@ -224,17 +222,16 @@ var MqttStore = /** @class */ (function () {
224
222
  enumerable: true,
225
223
  configurable: true,
226
224
  writable: true,
227
- value: function (topic, message) {
228
- var _a, _b;
225
+ value: (topic, message) => {
229
226
  // Logger.log(`DEBUG: addMessage: topic: ${topic}, urgentPrefixes: ${JSON.stringify(this.urgentTopicPrefixes)}`)
230
- if (_this.urgentTopicPrefixes.some(function (prefix) { return topic.startsWith(prefix); })) {
227
+ if (this.urgentTopicPrefixes.some((prefix) => topic.startsWith(prefix))) {
231
228
  // NOTE: If topic starts with one of the urgent prefixes, deliver it immediately
232
- _this.messages[topic] = (_a = message.value) !== null && _a !== void 0 ? _a : undefined;
229
+ this.messages[topic] = message.value;
233
230
  }
234
231
  else {
235
232
  // NOTE: Otherwise store message to the queue, and move messages from the queue
236
233
  // NOTE: to the React components that are MobX observers periodically and in batches
237
- _this.messageQueue[topic] = (_b = message.value) !== null && _b !== void 0 ? _b : undefined;
234
+ this.messageQueue[topic] = message.value;
238
235
  }
239
236
  }
240
237
  });
@@ -242,12 +239,12 @@ var MqttStore = /** @class */ (function () {
242
239
  enumerable: true,
243
240
  configurable: true,
244
241
  writable: true,
245
- value: function () {
246
- if (Object.values(_this.messageQueue).length > 0) {
242
+ value: () => {
243
+ if (Object.values(this.messageQueue).length > 0) {
247
244
  // Logger.log(`DEBUG: addMessagesFromQueue: in queue: ${JSON.stringify(Object.values(this.messageQueue).length)}`)
248
- assign(_this.messages, _this.messageQueue);
245
+ assign(this.messages, this.messageQueue);
249
246
  // Logger.log(`DEBUG: addMessagesFromQueue: to process: ${JSON.stringify(Object.values(this.messages).length)}`)
250
- _this.messageQueue = {};
247
+ this.messageQueue = {};
251
248
  }
252
249
  }
253
250
  });
@@ -255,16 +252,16 @@ var MqttStore = /** @class */ (function () {
255
252
  enumerable: true,
256
253
  configurable: true,
257
254
  writable: true,
258
- value: function (timeout) {
259
- _this.queueWorker = setTimeout(function () {
260
- var started = performance.now();
261
- _this.addMessagesFromQueue();
262
- var ended = performance.now();
263
- _this.meanQueueWorkerPassDuration = addToMean(_this.meanQueueWorkerPassDuration, 10, ended - started);
255
+ value: (timeout) => {
256
+ this.queueWorker = setTimeout(() => {
257
+ const started = performance.now();
258
+ this.addMessagesFromQueue();
259
+ const ended = performance.now();
260
+ this.meanQueueWorkerPassDuration = addToMean(this.meanQueueWorkerPassDuration, 10, ended - started);
264
261
  // Schedule next update after 1 - 3 seconds
265
262
  // depending on how fast we were able to process the incoming messages
266
- var newTimeout = Math.max(1000, Math.min(_this.meanQueueWorkerPassDuration * 50, 3000));
267
- _this.scheduleNextQueueWorkerPass(newTimeout);
263
+ const newTimeout = Math.max(1000, Math.min(this.meanQueueWorkerPassDuration * 50, 3000));
264
+ this.scheduleNextQueueWorkerPass(newTimeout);
268
265
  }, timeout);
269
266
  }
270
267
  });
@@ -272,120 +269,121 @@ var MqttStore = /** @class */ (function () {
272
269
  enumerable: true,
273
270
  configurable: true,
274
271
  writable: true,
275
- value: function () {
276
- _this.removeQueueWorker();
277
- _this.meanQueueWorkerPassDuration = 20; // ms
278
- _this.scheduleNextQueueWorkerPass(1000); // ms
272
+ value: () => {
273
+ this.removeQueueWorker();
274
+ this.meanQueueWorkerPassDuration = 20; // ms
275
+ this.scheduleNextQueueWorkerPass(1000); // ms
279
276
  }
280
277
  });
281
278
  Object.defineProperty(this, "removeQueueWorker", {
282
279
  enumerable: true,
283
280
  configurable: true,
284
281
  writable: true,
285
- value: function () {
286
- if (_this.queueWorker) {
287
- clearInterval(_this.queueWorker);
282
+ value: () => {
283
+ if (this.queueWorker) {
284
+ clearTimeout(this.queueWorker);
288
285
  }
289
- _this.queueWorker = undefined;
286
+ this.queueWorker = undefined;
290
287
  }
291
288
  });
292
289
  Object.defineProperty(this, "setPortalId", {
293
290
  enumerable: true,
294
291
  configurable: true,
295
292
  writable: true,
296
- value: function (portalId) {
297
- _this.portalId = portalId;
298
- _this.urgentTopicPrefixes = ["N/".concat(portalId, "/switch/"), "N/".concat(portalId, "/system/0/SwitchableOutput")];
293
+ value: (portalId) => {
294
+ this.portalId = portalId;
295
+ this.urgentTopicPrefixes = [
296
+ `N/${portalId}/switch/`,
297
+ `N/${portalId}/system/0/SwitchableOutput`,
298
+ `N/${portalId}/system/0/GenericInput`,
299
+ ];
299
300
  }
300
301
  });
301
302
  Object.defineProperty(this, "boot", {
302
303
  enumerable: true,
303
304
  configurable: true,
304
305
  writable: true,
305
- value: function (protocol, host, port, path, remote, portalId) {
306
- if (host === void 0) { host = "localhost"; }
307
- if (path === void 0) { path = "websocket-mqtt"; }
308
- if (remote === void 0) { remote = false; }
306
+ value: (protocol, host = "localhost", port, path = "websocket-mqtt", remote = false, portalId) => {
309
307
  Logger.log("MQTT booting");
310
- var client = _this.client;
308
+ let client = this.client;
311
309
  if (client) {
312
310
  client.end(true);
313
- _this.client = undefined;
314
- _this.portalId = undefined;
315
- _this.topicsSubscribed = new Set();
316
- _this.urgentTopicPrefixes = [];
311
+ this.client = undefined;
312
+ this.portalId = undefined;
313
+ this.topicsSubscribed = new Set();
314
+ this.urgentTopicPrefixes = [];
317
315
  }
318
- var url;
316
+ let url;
319
317
  if (remote) {
320
318
  if (!host) {
321
319
  return;
322
320
  }
323
321
  // remote connection to VRM broker always uses MQTTS over 443
324
- url = "mqtts://".concat(host, ":443");
322
+ url = `mqtts://${host}:443`;
325
323
  }
326
324
  else {
327
325
  // local connection derives websocket protocol from web app protocol
328
- var wsproto = protocol === "https:" ? "wss:" : "ws:";
326
+ const wsproto = protocol === "https:" ? "wss:" : "ws:";
329
327
  if (port) {
330
- url = "".concat(wsproto, "//").concat(host, ":").concat(port, "/").concat(path);
328
+ url = `${wsproto}//${host}:${port}/${path}`;
331
329
  }
332
330
  else {
333
- url = "".concat(wsproto, "//").concat(host, "/").concat(path);
331
+ url = `${wsproto}//${host}/${path}`;
334
332
  }
335
333
  }
336
- Logger.log("MQTT connecting to ".concat(url));
334
+ Logger.log(`MQTT connecting to ${url}`);
337
335
  client = mqtt.connect(url, { resubscribe: false });
338
- _this.client = client;
339
- _this.portalId = portalId;
340
- client.on("error", function (error) {
336
+ this.client = client;
337
+ this.portalId = portalId;
338
+ client.on("error", (error) => {
341
339
  Logger.log("MQTT error");
342
- runInAction(function () {
343
- _this.setError(error);
344
- _this.setStatus(STATUS.DISCONNECTED);
340
+ runInAction(() => {
341
+ this.setError(error);
342
+ this.setStatus(STATUS.DISCONNECTED);
345
343
  });
346
- _this.removeQueueWorker();
347
- _this.clearKeepaliveTimer();
348
- _this.clearSubscribedTopics();
344
+ this.removeQueueWorker();
345
+ this.clearKeepaliveTimer();
346
+ this.clearSubscribedTopics();
349
347
  });
350
- client.on("offline", function () {
348
+ client.on("offline", () => {
351
349
  Logger.log("MQTT offline");
352
- runInAction(function () {
353
- _this.setError(true);
354
- _this.setStatus(STATUS.OFFLINE);
350
+ runInAction(() => {
351
+ this.setError(true);
352
+ this.setStatus(STATUS.OFFLINE);
355
353
  });
356
- _this.removeQueueWorker();
357
- _this.clearKeepaliveTimer();
358
- _this.clearSubscribedTopics();
354
+ this.removeQueueWorker();
355
+ this.clearKeepaliveTimer();
356
+ this.clearSubscribedTopics();
359
357
  });
360
- client.on("connect", function () {
358
+ client.on("connect", () => {
361
359
  Logger.log("MQTT connected");
362
- runInAction(function () {
363
- _this.setError(null);
364
- _this.setStatus(STATUS.CONNECTED);
360
+ runInAction(() => {
361
+ this.setError(null);
362
+ this.setStatus(STATUS.CONNECTED);
365
363
  // Never use wildcard when connecting remotely
366
- _this.subscribeToTopic("N/".concat(remote ? portalId : "+", "/system/0/Serial"));
367
- _this.setupKeepaliveTimer();
364
+ this.subscribeToTopic(`N/${remote ? portalId : "+"}/system/0/Serial`);
365
+ this.setupKeepaliveTimer();
368
366
  });
369
367
  });
370
- client.on("message", function (topic, message) {
368
+ client.on("message", (topic, message) => {
371
369
  // Logger.log(`DEBUG: Message received: ${topic} - ${message.toString()}`)
372
- if (topic.endsWith("/system/0/Serial") && !_this.portalId) {
373
- var portalId_1 = getMessageJson(message).value;
374
- if (_this.portalId !== portalId_1 && portalId_1 !== undefined) {
375
- _this.setPortalId(portalId_1);
370
+ if (topic.endsWith("/system/0/Serial") && !this.portalId) {
371
+ const portalId = getMessageJson(message).value;
372
+ if (this.portalId !== portalId && portalId !== undefined) {
373
+ this.setPortalId(portalId);
376
374
  }
377
- runInAction(function () { return _this.subscribeToAllTopics(); });
375
+ runInAction(() => this.subscribeToAllTopics());
378
376
  }
379
377
  if (topic.endsWith("full_publish_completed")) {
380
- var uniqueId = getMessageJson(message)["full-publish-completed-echo"] || "";
381
- Logger.log("Received full_publish_completed for ".concat(_this.portalId, " with full-publish-completed-echo: '").concat(uniqueId, "'"));
382
- if (uniqueId === _this.uniqueId) {
383
- _this.addMessagesFromQueue();
384
- _this.setupQueueWorker();
378
+ const uniqueId = getMessageJson(message)["full-publish-completed-echo"] || "";
379
+ Logger.log(`Received full_publish_completed for ${this.portalId} with full-publish-completed-echo: '${uniqueId}'`);
380
+ if (uniqueId === this.uniqueId) {
381
+ this.addMessagesFromQueue();
382
+ this.setupQueueWorker();
385
383
  }
386
384
  }
387
385
  if (message.toString() !== "") {
388
- _this.addMessage(topic, getMessageJson(message));
386
+ this.addMessage(topic, getMessageJson(message));
389
387
  }
390
388
  });
391
389
  Logger.log("MQTT booted");
@@ -395,32 +393,32 @@ var MqttStore = /** @class */ (function () {
395
393
  enumerable: true,
396
394
  configurable: true,
397
395
  writable: true,
398
- value: function () {
396
+ value: () => {
399
397
  var _a;
400
- var topics = [
401
- "N/".concat(_this.portalId, "/settings/#"),
402
- "N/".concat(_this.portalId, "/system/#"),
403
- "N/".concat(_this.portalId, "/vebus/#"),
404
- "N/".concat(_this.portalId, "/alternator/#"),
405
- "N/".concat(_this.portalId, "/battery/#"),
406
- "N/".concat(_this.portalId, "/charger/#"),
407
- "N/".concat(_this.portalId, "/dcsource/#"),
408
- "N/".concat(_this.portalId, "/generator/#"),
409
- "N/".concat(_this.portalId, "/genset/#"),
410
- "N/".concat(_this.portalId, "/dcgenset/#"),
411
- "N/".concat(_this.portalId, "/inverter/#"),
412
- "N/".concat(_this.portalId, "/tank/#"),
413
- "N/".concat(_this.portalId, "/temperature/#"),
414
- "N/".concat(_this.portalId, "/switch/#"),
415
- "N/".concat(_this.portalId, "/full_publish_completed"),
398
+ const topics = [
399
+ `N/${this.portalId}/settings/#`,
400
+ `N/${this.portalId}/system/#`,
401
+ `N/${this.portalId}/vebus/#`,
402
+ `N/${this.portalId}/alternator/#`,
403
+ `N/${this.portalId}/battery/#`,
404
+ `N/${this.portalId}/charger/#`,
405
+ `N/${this.portalId}/dcsource/#`,
406
+ `N/${this.portalId}/generator/#`,
407
+ `N/${this.portalId}/genset/#`,
408
+ `N/${this.portalId}/dcgenset/#`,
409
+ `N/${this.portalId}/inverter/#`,
410
+ `N/${this.portalId}/tank/#`,
411
+ `N/${this.portalId}/temperature/#`,
412
+ `N/${this.portalId}/switch/#`,
413
+ `N/${this.portalId}/full_publish_completed`,
416
414
  ];
417
- (_a = _this.client) === null || _a === void 0 ? void 0 : _a.subscribe(topics, function (err) {
415
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.subscribe(topics, (err) => {
418
416
  if (err) {
419
417
  Logger.error(err);
420
418
  return;
421
419
  }
422
420
  // When we received all topics we send a full keepalive.
423
- _this.sendFullKeepalive();
421
+ this.sendFullKeepalive();
424
422
  });
425
423
  }
426
424
  });
@@ -428,13 +426,13 @@ var MqttStore = /** @class */ (function () {
428
426
  enumerable: true,
429
427
  configurable: true,
430
428
  writable: true,
431
- value: function () {
429
+ value: () => {
432
430
  var _a;
433
- if (_this.portalId) {
434
- var options = JSON.stringify({ "keepalive-options": ["suppress-republish"] });
435
- var topic = "R/".concat(_this.portalId, "/keepalive");
436
- Logger.log("Sending keepalive for ".concat(_this.portalId, " with ").concat(options));
437
- (_a = _this.client) === null || _a === void 0 ? void 0 : _a.publish(topic, options);
431
+ if (this.portalId) {
432
+ const options = JSON.stringify({ "keepalive-options": ["suppress-republish"] });
433
+ const topic = `R/${this.portalId}/keepalive`;
434
+ Logger.log(`Sending keepalive for ${this.portalId} with ${options}`);
435
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.publish(topic, options);
438
436
  }
439
437
  }
440
438
  });
@@ -442,13 +440,12 @@ var MqttStore = /** @class */ (function () {
442
440
  enumerable: true,
443
441
  configurable: true,
444
442
  writable: true,
445
- value: function () {
443
+ value: () => {
446
444
  var _a;
447
- if (_this.portalId) {
448
- var topic = "R/".concat(_this.portalId, "/keepalive");
449
- Logger.log("Sending first keepalive for ".concat(_this.portalId, " with full-publish-completed-echo: '").concat(_this.uniqueId, "'"));
450
- _this.client &&
451
- ((_a = _this.client) === null || _a === void 0 ? void 0 : _a.publish(topic, "{ \"keepalive-options\" : [ {\"full-publish-completed-echo\": \"".concat(_this.uniqueId, "\" } ] }")));
445
+ if (this.portalId) {
446
+ const topic = `R/${this.portalId}/keepalive`;
447
+ Logger.log(`Sending first keepalive for ${this.portalId} with full-publish-completed-echo: '${this.uniqueId}'`);
448
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.publish(topic, `{ "keepalive-options" : [ {"full-publish-completed-echo": "${this.uniqueId}" } ] }`);
452
449
  }
453
450
  }
454
451
  });
@@ -456,36 +453,37 @@ var MqttStore = /** @class */ (function () {
456
453
  enumerable: true,
457
454
  configurable: true,
458
455
  writable: true,
459
- value: function () {
460
- _this.clearKeepaliveTimer();
461
- _this.keepAliveHandlerRef = setInterval(_this.sendSuppressedKeepalive, 30000);
462
- _this.sendFullKeepalive();
456
+ value: () => {
457
+ this.clearKeepaliveTimer();
458
+ this.keepAliveHandlerRef = setInterval(this.sendSuppressedKeepalive, 30000);
459
+ this.sendFullKeepalive();
463
460
  }
464
461
  });
465
462
  Object.defineProperty(this, "clearKeepaliveTimer", {
466
463
  enumerable: true,
467
464
  configurable: true,
468
465
  writable: true,
469
- value: function () {
470
- var ref = _this.keepAliveHandlerRef;
466
+ value: () => {
467
+ const ref = this.keepAliveHandlerRef;
471
468
  if (ref) {
472
469
  clearInterval(ref);
473
470
  }
474
- _this.keepAliveHandlerRef = undefined;
471
+ this.keepAliveHandlerRef = undefined;
475
472
  }
476
473
  });
477
474
  Object.defineProperty(this, "publish", {
478
475
  enumerable: true,
479
476
  configurable: true,
480
477
  writable: true,
481
- value: function (topic, data, options) {
478
+ value: (topic, data, options) => {
482
479
  var _a;
483
- if (_this.status !== STATUS.CONNECTED || !_this.client) {
480
+ if (this.status !== STATUS.CONNECTED || !this.client) {
484
481
  Logger.log("Could not publish value, not connected to MQTT broker");
482
+ return;
485
483
  }
486
- var message = typeof data === "object" && data !== null && "raw" in data ? data.raw : JSON.stringify({ value: data });
487
- Logger.log("Publishing to ".concat(topic, ": ").concat(message));
488
- (_a = _this.client) === null || _a === void 0 ? void 0 : _a.publish(topic, message, options !== null && options !== void 0 ? options : {});
484
+ const message = typeof data === "object" && data !== null && "raw" in data ? data.raw : JSON.stringify({ value: data });
485
+ Logger.log(`Publishing to ${topic}: ${message}`);
486
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.publish(topic, message, options !== null && options !== void 0 ? options : {});
489
487
  }
490
488
  });
491
489
  makeAutoObservable(this, {
@@ -503,45 +501,23 @@ var MqttStore = /** @class */ (function () {
503
501
  clearSubscribedTopics: false,
504
502
  });
505
503
  }
506
- Object.defineProperty(MqttStore.prototype, "isConnected", {
507
- get: function () {
508
- return this.status === STATUS.CONNECTED;
509
- },
510
- enumerable: false,
511
- configurable: true
512
- });
513
- Object.defineProperty(MqttStore.prototype, "clearSubscribedTopics", {
514
- enumerable: false,
515
- configurable: true,
516
- writable: true,
517
- value: function () {
518
- var _this = this;
519
- this.topicsSubscribed.clear();
520
- this.urgentTopicPrefixes = [];
521
- runInAction(function () {
522
- _this.portalId = undefined;
523
- });
524
- }
525
- });
526
- Object.defineProperty(MqttStore.prototype, "setStatus", {
527
- enumerable: false,
528
- configurable: true,
529
- writable: true,
530
- value: function (status) {
531
- this.status = status;
532
- }
533
- });
534
- Object.defineProperty(MqttStore.prototype, "setError", {
535
- enumerable: false,
536
- configurable: true,
537
- writable: true,
538
- value: function (error) {
539
- this.error = error;
540
- }
541
- });
542
- return MqttStore;
543
- }());
544
- export { MqttStore };
504
+ get isConnected() {
505
+ return this.status === STATUS.CONNECTED;
506
+ }
507
+ clearSubscribedTopics() {
508
+ this.topicsSubscribed.clear();
509
+ this.urgentTopicPrefixes = [];
510
+ runInAction(() => {
511
+ this.portalId = undefined;
512
+ });
513
+ }
514
+ setStatus(status) {
515
+ this.status = status;
516
+ }
517
+ setError(error) {
518
+ this.error = error;
519
+ }
520
+ }
545
521
  /**
546
522
  * Compute mean by providing existing mean, number of samples, and new sample.
547
523
  *
@@ -557,7 +533,7 @@ function addToMean(mean, n, newValue) {
557
533
  return mean + (newValue - mean) / (n + 1);
558
534
  }
559
535
  function initializeStore() {
560
- var _store = store !== null && store !== void 0 ? store : new MqttStore();
536
+ const _store = store !== null && store !== void 0 ? store : new MqttStore();
561
537
  // For SSG and SSR always create a new store
562
538
  if (typeof window === "undefined")
563
539
  return _store;
@@ -567,6 +543,6 @@ function initializeStore() {
567
543
  return _store;
568
544
  }
569
545
  export function useMqtt() {
570
- return useMemo(function () { return initializeStore(); }, []);
546
+ return useMemo(() => initializeStore(), []);
571
547
  }
572
548
  //# sourceMappingURL=Mqtt.store.js.map