@victronenergy/mfd-modules 10.4.1 → 11.0.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.
- package/README.md +1 -1
- package/dist/src/Modules/AcLoads/AcLoads.provider.d.ts.map +1 -1
- package/dist/src/Modules/AcLoads/AcLoads.provider.js +19 -19
- package/dist/src/Modules/AcLoads/AcLoads.provider.js.map +1 -1
- package/dist/src/Modules/AcMode/AcMode.provider.d.ts.map +1 -1
- package/dist/src/Modules/AcMode/AcMode.provider.js +19 -31
- package/dist/src/Modules/AcMode/AcMode.provider.js.map +1 -1
- package/dist/src/Modules/ActiveSource/ActiveInValues.provider.js +17 -17
- package/dist/src/Modules/ActiveSource/ActiveInValues.provider.js.map +1 -1
- package/dist/src/Modules/ActiveSource/ActiveSource.provider.js +11 -11
- package/dist/src/Modules/ActiveSource/ActiveSource.provider.js.map +1 -1
- package/dist/src/Modules/Alternators/Alternator.provider.d.ts.map +1 -1
- package/dist/src/Modules/Alternators/Alternator.provider.js +7 -8
- package/dist/src/Modules/Alternators/Alternator.provider.js.map +1 -1
- package/dist/src/Modules/Alternators/Alternators.provider.d.ts.map +1 -1
- package/dist/src/Modules/Alternators/Alternators.provider.js +16 -14
- package/dist/src/Modules/Alternators/Alternators.provider.js.map +1 -1
- package/dist/src/Modules/Alternators/Alternators.store.d.ts.map +1 -1
- package/dist/src/Modules/Alternators/Alternators.store.js +7 -10
- package/dist/src/Modules/Alternators/Alternators.store.js.map +1 -1
- package/dist/src/Modules/App/App.provider.d.ts.map +1 -1
- package/dist/src/Modules/App/App.provider.js +51 -51
- package/dist/src/Modules/App/App.provider.js.map +1 -1
- package/dist/src/Modules/App/App.store.d.ts +11 -7
- package/dist/src/Modules/App/App.store.d.ts.map +1 -1
- package/dist/src/Modules/App/App.store.js +73 -107
- package/dist/src/Modules/App/App.store.js.map +1 -1
- package/dist/src/Modules/Battery/Batteries.provider.d.ts.map +1 -1
- package/dist/src/Modules/Battery/Batteries.provider.js +16 -14
- package/dist/src/Modules/Battery/Batteries.provider.js.map +1 -1
- package/dist/src/Modules/Battery/Batteries.store.d.ts.map +1 -1
- package/dist/src/Modules/Battery/Batteries.store.js +7 -10
- package/dist/src/Modules/Battery/Batteries.store.js.map +1 -1
- package/dist/src/Modules/Battery/SystemBatteries.provider.js +5 -5
- package/dist/src/Modules/Battery/SystemBatteries.provider.js.map +1 -1
- package/dist/src/Modules/Chargers/Charger.provider.js +23 -33
- package/dist/src/Modules/Chargers/Charger.provider.js.map +1 -1
- package/dist/src/Modules/Chargers/Chargers.provider.d.ts.map +1 -1
- package/dist/src/Modules/Chargers/Chargers.provider.js +16 -15
- package/dist/src/Modules/Chargers/Chargers.provider.js.map +1 -1
- package/dist/src/Modules/Chargers/Chargers.store.d.ts.map +1 -1
- package/dist/src/Modules/Chargers/Chargers.store.js +7 -10
- package/dist/src/Modules/Chargers/Chargers.store.js.map +1 -1
- package/dist/src/Modules/DcLoads/DcLoads.provider.d.ts.map +1 -1
- package/dist/src/Modules/DcLoads/DcLoads.provider.js +9 -20
- package/dist/src/Modules/DcLoads/DcLoads.provider.js.map +1 -1
- package/dist/src/Modules/Generators/ConnectedGenset.provider.d.ts.map +1 -1
- package/dist/src/Modules/Generators/ConnectedGenset.provider.js +36 -47
- package/dist/src/Modules/Generators/ConnectedGenset.provider.js.map +1 -1
- package/dist/src/Modules/Generators/ConnectedGensets.provider.d.ts.map +1 -1
- package/dist/src/Modules/Generators/ConnectedGensets.provider.js +16 -14
- package/dist/src/Modules/Generators/ConnectedGensets.provider.js.map +1 -1
- package/dist/src/Modules/Generators/ConnectedGensets.store.d.ts.map +1 -1
- package/dist/src/Modules/Generators/ConnectedGensets.store.js +8 -11
- package/dist/src/Modules/Generators/ConnectedGensets.store.js.map +1 -1
- package/dist/src/Modules/Generators/GeneratorConnectedGenset.provider.js +17 -27
- package/dist/src/Modules/Generators/GeneratorConnectedGenset.provider.js.map +1 -1
- package/dist/src/Modules/Generators/GeneratorRelay.provider.d.ts +2 -2
- package/dist/src/Modules/Generators/GeneratorRelay.provider.d.ts.map +1 -1
- package/dist/src/Modules/Generators/GeneratorRelay.provider.js +24 -34
- package/dist/src/Modules/Generators/GeneratorRelay.provider.js.map +1 -1
- package/dist/src/Modules/Header/Header.provider.js +4 -4
- package/dist/src/Modules/Header/Header.provider.js.map +1 -1
- package/dist/src/Modules/InverterCharger/InputLimit.provider.js +6 -17
- package/dist/src/Modules/InverterCharger/InputLimit.provider.js.map +1 -1
- package/dist/src/Modules/InverterCharger/InputLimitSelector.provider.d.ts.map +1 -1
- package/dist/src/Modules/InverterCharger/InputLimitSelector.provider.js +12 -26
- package/dist/src/Modules/InverterCharger/InputLimitSelector.provider.js.map +1 -1
- package/dist/src/Modules/InverterCharger/InverterCharger.provider.d.ts.map +1 -1
- package/dist/src/Modules/InverterCharger/InverterCharger.provider.js +16 -27
- package/dist/src/Modules/InverterCharger/InverterCharger.provider.js.map +1 -1
- package/dist/src/Modules/Inverters/Inverter.provider.d.ts.map +1 -1
- package/dist/src/Modules/Inverters/Inverter.provider.js +19 -30
- package/dist/src/Modules/Inverters/Inverter.provider.js.map +1 -1
- package/dist/src/Modules/Inverters/Inverters.provider.d.ts.map +1 -1
- package/dist/src/Modules/Inverters/Inverters.provider.js +14 -13
- package/dist/src/Modules/Inverters/Inverters.provider.js.map +1 -1
- package/dist/src/Modules/Inverters/Inverters.store.d.ts.map +1 -1
- package/dist/src/Modules/Inverters/Inverters.store.js +7 -10
- package/dist/src/Modules/Inverters/Inverters.store.js.map +1 -1
- package/dist/src/Modules/Inverters/index.js.map +1 -1
- package/dist/src/Modules/Language/Language.provider.d.ts +1 -1
- package/dist/src/Modules/Language/Language.provider.d.ts.map +1 -1
- package/dist/src/Modules/Language/Language.provider.js +21 -56
- package/dist/src/Modules/Language/Language.provider.js.map +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.constants.js +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.constants.js.map +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.provider.d.ts +2 -2
- package/dist/src/Modules/Mqtt/Mqtt.provider.d.ts.map +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.provider.js +4 -4
- package/dist/src/Modules/Mqtt/Mqtt.provider.js.map +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.store.d.ts +3 -3
- package/dist/src/Modules/Mqtt/Mqtt.store.d.ts.map +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.store.js +169 -193
- package/dist/src/Modules/Mqtt/Mqtt.store.js.map +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.types.d.ts +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.types.d.ts.map +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.types.js +0 -1
- package/dist/src/Modules/Mqtt/Mqtt.types.js.map +1 -1
- package/dist/src/Modules/PvCharger/PvCharger.provider.js +8 -8
- package/dist/src/Modules/PvCharger/PvCharger.provider.js.map +1 -1
- package/dist/src/Modules/ShorePowerInput/ShorePowerInput.provider.d.ts +4 -1
- package/dist/src/Modules/ShorePowerInput/ShorePowerInput.provider.d.ts.map +1 -1
- package/dist/src/Modules/ShorePowerInput/ShorePowerInput.provider.js +24 -35
- package/dist/src/Modules/ShorePowerInput/ShorePowerInput.provider.js.map +1 -1
- package/dist/src/Modules/ShorePowerInput/index.d.ts +0 -1
- package/dist/src/Modules/ShorePowerInput/index.d.ts.map +1 -1
- package/dist/src/Modules/ShorePowerInput/index.js +0 -1
- package/dist/src/Modules/ShorePowerInput/index.js.map +1 -1
- package/dist/src/Modules/SwitchingPane/GenericInput.provider.d.ts +27 -0
- package/dist/src/Modules/SwitchingPane/GenericInput.provider.d.ts.map +1 -0
- package/dist/src/Modules/SwitchingPane/GenericInput.provider.js +32 -0
- package/dist/src/Modules/SwitchingPane/GenericInput.provider.js.map +1 -0
- package/dist/src/Modules/{SwitchableOutputs → SwitchingPane}/SwitchableOutput.provider.d.ts +25 -9
- package/dist/src/Modules/SwitchingPane/SwitchableOutput.provider.d.ts.map +1 -0
- package/dist/src/Modules/SwitchingPane/SwitchableOutput.provider.js +58 -0
- package/dist/src/Modules/SwitchingPane/SwitchableOutput.provider.js.map +1 -0
- package/dist/src/Modules/SwitchingPane/SwitchingDevice.provider.d.ts.map +1 -0
- package/dist/src/Modules/SwitchingPane/SwitchingDevice.provider.js +48 -0
- package/dist/src/Modules/SwitchingPane/SwitchingDevice.provider.js.map +1 -0
- package/dist/src/Modules/SwitchingPane/SwitchingDevices.store.d.ts.map +1 -0
- package/dist/src/Modules/{SwitchableOutputs → SwitchingPane}/SwitchingDevices.store.js +7 -10
- package/dist/src/Modules/SwitchingPane/SwitchingDevices.store.js.map +1 -0
- package/dist/src/Modules/SwitchingPane/SwitchingPane.provider.d.ts +2 -0
- package/dist/src/Modules/SwitchingPane/SwitchingPane.provider.d.ts.map +1 -0
- package/dist/src/Modules/SwitchingPane/SwitchingPane.provider.js +256 -0
- package/dist/src/Modules/SwitchingPane/SwitchingPane.provider.js.map +1 -0
- package/dist/src/Modules/SwitchingPane/SwitchingPane.store.d.ts +50 -0
- package/dist/src/Modules/SwitchingPane/SwitchingPane.store.d.ts.map +1 -0
- package/dist/src/Modules/{SwitchableOutputs/SwitchableOutputs.store.js → SwitchingPane/SwitchingPane.store.js} +67 -18
- package/dist/src/Modules/SwitchingPane/SwitchingPane.store.js.map +1 -0
- package/dist/src/Modules/SwitchingPane/index.d.ts +7 -0
- package/dist/src/Modules/SwitchingPane/index.d.ts.map +1 -0
- package/dist/src/Modules/SwitchingPane/index.js +7 -0
- package/dist/src/Modules/SwitchingPane/index.js.map +1 -0
- package/dist/src/Modules/SystemState/SystemState.provider.js +5 -5
- package/dist/src/Modules/SystemState/SystemState.provider.js.map +1 -1
- package/dist/src/Modules/Tanks/Tank.provider.d.ts.map +1 -1
- package/dist/src/Modules/Tanks/Tank.provider.js +11 -11
- package/dist/src/Modules/Tanks/Tank.provider.js.map +1 -1
- package/dist/src/Modules/Tanks/Tanks.provider.d.ts.map +1 -1
- package/dist/src/Modules/Tanks/Tanks.provider.js +19 -18
- package/dist/src/Modules/Tanks/Tanks.provider.js.map +1 -1
- package/dist/src/Modules/Tanks/Tanks.store.d.ts.map +1 -1
- package/dist/src/Modules/Tanks/Tanks.store.js +7 -10
- package/dist/src/Modules/Tanks/Tanks.store.js.map +1 -1
- package/dist/src/Modules/Temperatures/Temperature.provider.d.ts.map +1 -1
- package/dist/src/Modules/Temperatures/Temperature.provider.js +29 -29
- package/dist/src/Modules/Temperatures/Temperature.provider.js.map +1 -1
- package/dist/src/Modules/Temperatures/Temperatures.provider.d.ts.map +1 -1
- package/dist/src/Modules/Temperatures/Temperatures.provider.js +18 -17
- package/dist/src/Modules/Temperatures/Temperatures.provider.js.map +1 -1
- package/dist/src/Modules/Temperatures/Temperatures.store.d.ts.map +1 -1
- package/dist/src/Modules/Temperatures/Temperatures.store.js +7 -10
- package/dist/src/Modules/Temperatures/Temperatures.store.js.map +1 -1
- package/dist/src/Modules/Temperatures/index.d.ts +3 -3
- package/dist/src/Modules/Temperatures/index.js +3 -3
- package/dist/src/Modules/Temperatures/index.js.map +1 -1
- package/dist/src/Modules/Theme/Theme.provider.js +6 -6
- package/dist/src/Modules/Theme/Theme.provider.js.map +1 -1
- package/dist/src/Modules/Theme/Theme.store.d.ts.map +1 -1
- package/dist/src/Modules/Theme/Theme.store.js +35 -38
- package/dist/src/Modules/Theme/Theme.store.js.map +1 -1
- package/dist/src/Modules/Vebus/Vebus.provider.d.ts.map +1 -1
- package/dist/src/Modules/Vebus/Vebus.provider.js +39 -48
- package/dist/src/Modules/Vebus/Vebus.provider.js.map +1 -1
- package/dist/src/Modules/Vebus/Vebus.store.d.ts.map +1 -1
- package/dist/src/Modules/Vebus/Vebus.store.js +11 -14
- package/dist/src/Modules/Vebus/Vebus.store.js.map +1 -1
- package/dist/src/Modules/Vrm/Vrm.store.d.ts.map +1 -1
- package/dist/src/Modules/Vrm/Vrm.store.js +85 -154
- package/dist/src/Modules/Vrm/Vrm.store.js.map +1 -1
- package/dist/src/Modules/Vrm/Vrm.types.js +0 -1
- package/dist/src/Modules/WindGenerators/WindGenerator.provider.d.ts.map +1 -1
- package/dist/src/Modules/WindGenerators/WindGenerator.provider.js +6 -7
- package/dist/src/Modules/WindGenerators/WindGenerator.provider.js.map +1 -1
- package/dist/src/Modules/WindGenerators/WindGenerators.provider.d.ts.map +1 -1
- package/dist/src/Modules/WindGenerators/WindGenerators.provider.js +21 -19
- package/dist/src/Modules/WindGenerators/WindGenerators.provider.js.map +1 -1
- package/dist/src/Modules/WindGenerators/WindGenerators.store.d.ts.map +1 -1
- package/dist/src/Modules/WindGenerators/WindGenerators.store.js +7 -10
- package/dist/src/Modules/WindGenerators/WindGenerators.store.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/constants.d.ts +53 -3
- package/dist/src/utils/constants.d.ts.map +1 -1
- package/dist/src/utils/constants.js +82 -30
- package/dist/src/utils/constants.js.map +1 -1
- package/dist/src/utils/hsvw.d.ts.map +1 -1
- package/dist/src/utils/hsvw.js +24 -25
- package/dist/src/utils/hsvw.js.map +1 -1
- package/dist/src/utils/logger.d.ts +5 -8
- package/dist/src/utils/logger.d.ts.map +1 -1
- package/dist/src/utils/logger.js +11 -23
- package/dist/src/utils/logger.js.map +1 -1
- package/dist/src/utils/storage.d.ts.map +1 -1
- package/dist/src/utils/storage.js +7 -6
- package/dist/src/utils/storage.js.map +1 -1
- package/dist/src/utils/util.d.ts +6 -15
- package/dist/src/utils/util.d.ts.map +1 -1
- package/dist/src/utils/util.js +8 -100
- package/dist/src/utils/util.js.map +1 -1
- package/package.json +26 -15
- package/dist/eslint.config.d.mts +0 -13
- package/dist/eslint.config.d.mts.map +0 -1
- package/dist/eslint.config.mjs +0 -28
- package/dist/eslint.config.mjs.map +0 -1
- package/dist/src/Modules/ShorePowerInput/ShorePowerInput.store.d.ts +0 -11
- package/dist/src/Modules/ShorePowerInput/ShorePowerInput.store.d.ts.map +0 -1
- package/dist/src/Modules/ShorePowerInput/ShorePowerInput.store.js +0 -37
- package/dist/src/Modules/ShorePowerInput/ShorePowerInput.store.js.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.d.ts.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.js +0 -67
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.js.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.d.ts +0 -2
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.d.ts.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js +0 -168
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.d.ts +0 -38
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.d.ts.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.js.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.d.ts.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.js +0 -50
- package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.js.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchingDevices.store.d.ts.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchingDevices.store.js.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/index.d.ts +0 -6
- package/dist/src/Modules/SwitchableOutputs/index.d.ts.map +0 -1
- package/dist/src/Modules/SwitchableOutputs/index.js +0 -6
- package/dist/src/Modules/SwitchableOutputs/index.js.map +0 -1
- /package/dist/src/Modules/{SwitchableOutputs → SwitchingPane}/SwitchingDevice.provider.d.ts +0 -0
- /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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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(
|
|
105
|
+
value: computedFn((topic) => {
|
|
107
106
|
// Logger.log(`DEBUG: messageFromTopic: ${JSON.stringify(topic)}`)
|
|
108
107
|
// trace()
|
|
109
|
-
return topic ?
|
|
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(
|
|
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
|
-
|
|
142
|
-
Object.entries(topics).forEach(
|
|
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(
|
|
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] =
|
|
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(
|
|
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
|
-
|
|
185
|
-
return Object.fromEntries(Object.keys(
|
|
186
|
-
.filter(
|
|
187
|
-
.map(
|
|
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(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
message !==
|
|
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:
|
|
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 (!
|
|
209
|
-
Logger.log(
|
|
210
|
-
(_a =
|
|
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
|
-
|
|
217
|
-
|
|
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
|
-
|
|
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:
|
|
228
|
-
var _a, _b;
|
|
225
|
+
value: (topic, message) => {
|
|
229
226
|
// Logger.log(`DEBUG: addMessage: topic: ${topic}, urgentPrefixes: ${JSON.stringify(this.urgentTopicPrefixes)}`)
|
|
230
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
246
|
-
if (Object.values(
|
|
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(
|
|
245
|
+
assign(this.messages, this.messageQueue);
|
|
249
246
|
// Logger.log(`DEBUG: addMessagesFromQueue: to process: ${JSON.stringify(Object.values(this.messages).length)}`)
|
|
250
|
-
|
|
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:
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
267
|
-
|
|
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:
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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:
|
|
286
|
-
if (
|
|
287
|
-
|
|
282
|
+
value: () => {
|
|
283
|
+
if (this.queueWorker) {
|
|
284
|
+
clearTimeout(this.queueWorker);
|
|
288
285
|
}
|
|
289
|
-
|
|
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:
|
|
297
|
-
|
|
298
|
-
|
|
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:
|
|
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
|
-
|
|
308
|
+
let client = this.client;
|
|
311
309
|
if (client) {
|
|
312
310
|
client.end(true);
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
311
|
+
this.client = undefined;
|
|
312
|
+
this.portalId = undefined;
|
|
313
|
+
this.topicsSubscribed = new Set();
|
|
314
|
+
this.urgentTopicPrefixes = [];
|
|
317
315
|
}
|
|
318
|
-
|
|
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 =
|
|
322
|
+
url = `mqtts://${host}:443`;
|
|
325
323
|
}
|
|
326
324
|
else {
|
|
327
325
|
// local connection derives websocket protocol from web app protocol
|
|
328
|
-
|
|
326
|
+
const wsproto = protocol === "https:" ? "wss:" : "ws:";
|
|
329
327
|
if (port) {
|
|
330
|
-
url =
|
|
328
|
+
url = `${wsproto}//${host}:${port}/${path}`;
|
|
331
329
|
}
|
|
332
330
|
else {
|
|
333
|
-
url =
|
|
331
|
+
url = `${wsproto}//${host}/${path}`;
|
|
334
332
|
}
|
|
335
333
|
}
|
|
336
|
-
Logger.log(
|
|
334
|
+
Logger.log(`MQTT connecting to ${url}`);
|
|
337
335
|
client = mqtt.connect(url, { resubscribe: false });
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
client.on("error",
|
|
336
|
+
this.client = client;
|
|
337
|
+
this.portalId = portalId;
|
|
338
|
+
client.on("error", (error) => {
|
|
341
339
|
Logger.log("MQTT error");
|
|
342
|
-
runInAction(
|
|
343
|
-
|
|
344
|
-
|
|
340
|
+
runInAction(() => {
|
|
341
|
+
this.setError(error);
|
|
342
|
+
this.setStatus(STATUS.DISCONNECTED);
|
|
345
343
|
});
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
344
|
+
this.removeQueueWorker();
|
|
345
|
+
this.clearKeepaliveTimer();
|
|
346
|
+
this.clearSubscribedTopics();
|
|
349
347
|
});
|
|
350
|
-
client.on("offline",
|
|
348
|
+
client.on("offline", () => {
|
|
351
349
|
Logger.log("MQTT offline");
|
|
352
|
-
runInAction(
|
|
353
|
-
|
|
354
|
-
|
|
350
|
+
runInAction(() => {
|
|
351
|
+
this.setError(true);
|
|
352
|
+
this.setStatus(STATUS.OFFLINE);
|
|
355
353
|
});
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
354
|
+
this.removeQueueWorker();
|
|
355
|
+
this.clearKeepaliveTimer();
|
|
356
|
+
this.clearSubscribedTopics();
|
|
359
357
|
});
|
|
360
|
-
client.on("connect",
|
|
358
|
+
client.on("connect", () => {
|
|
361
359
|
Logger.log("MQTT connected");
|
|
362
|
-
runInAction(
|
|
363
|
-
|
|
364
|
-
|
|
360
|
+
runInAction(() => {
|
|
361
|
+
this.setError(null);
|
|
362
|
+
this.setStatus(STATUS.CONNECTED);
|
|
365
363
|
// Never use wildcard when connecting remotely
|
|
366
|
-
|
|
367
|
-
|
|
364
|
+
this.subscribeToTopic(`N/${remote ? portalId : "+"}/system/0/Serial`);
|
|
365
|
+
this.setupKeepaliveTimer();
|
|
368
366
|
});
|
|
369
367
|
});
|
|
370
|
-
client.on("message",
|
|
368
|
+
client.on("message", (topic, message) => {
|
|
371
369
|
// Logger.log(`DEBUG: Message received: ${topic} - ${message.toString()}`)
|
|
372
|
-
if (topic.endsWith("/system/0/Serial") && !
|
|
373
|
-
|
|
374
|
-
if (
|
|
375
|
-
|
|
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(
|
|
375
|
+
runInAction(() => this.subscribeToAllTopics());
|
|
378
376
|
}
|
|
379
377
|
if (topic.endsWith("full_publish_completed")) {
|
|
380
|
-
|
|
381
|
-
Logger.log(
|
|
382
|
-
if (uniqueId ===
|
|
383
|
-
|
|
384
|
-
|
|
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
|
-
|
|
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:
|
|
396
|
+
value: () => {
|
|
399
397
|
var _a;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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 =
|
|
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
|
-
|
|
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:
|
|
429
|
+
value: () => {
|
|
432
430
|
var _a;
|
|
433
|
-
if (
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
Logger.log(
|
|
437
|
-
(_a =
|
|
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:
|
|
443
|
+
value: () => {
|
|
446
444
|
var _a;
|
|
447
|
-
if (
|
|
448
|
-
|
|
449
|
-
Logger.log(
|
|
450
|
-
|
|
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:
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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:
|
|
470
|
-
|
|
466
|
+
value: () => {
|
|
467
|
+
const ref = this.keepAliveHandlerRef;
|
|
471
468
|
if (ref) {
|
|
472
469
|
clearInterval(ref);
|
|
473
470
|
}
|
|
474
|
-
|
|
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:
|
|
478
|
+
value: (topic, data, options) => {
|
|
482
479
|
var _a;
|
|
483
|
-
if (
|
|
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
|
-
|
|
487
|
-
Logger.log(
|
|
488
|
-
(_a =
|
|
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
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
-
|
|
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(
|
|
546
|
+
return useMemo(() => initializeStore(), []);
|
|
571
547
|
}
|
|
572
548
|
//# sourceMappingURL=Mqtt.store.js.map
|