@victronenergy/mfd-modules 9.6.0 → 9.7.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/dist/src/Modules/App/App.provider.d.ts.map +1 -1
- package/dist/src/Modules/App/App.provider.js +28 -7
- package/dist/src/Modules/App/App.provider.js.map +1 -1
- package/dist/src/Modules/App/App.store.d.ts +14 -3
- package/dist/src/Modules/App/App.store.d.ts.map +1 -1
- package/dist/src/Modules/App/App.store.js +62 -12
- package/dist/src/Modules/App/App.store.js.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.d.ts.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js +12 -0
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.d.ts +3 -0
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.d.ts.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.js +12 -0
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.provider.d.ts","sourceRoot":"/","sources":["src/Modules/App/App.provider.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"App.provider.d.ts","sourceRoot":"/","sources":["src/Modules/App/App.provider.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM,sCAqElB,CAAA"}
|
|
@@ -9,6 +9,8 @@ export var useApp = function () {
|
|
|
9
9
|
firmwareVersion: "N/".concat(portalId, "/system/0/FirmwareVersion"),
|
|
10
10
|
units: {
|
|
11
11
|
temperature: "N/".concat(portalId, "/settings/0/Settings/System/Units/Temperature"),
|
|
12
|
+
speed: "N/".concat(portalId, "/settings/0/Settings/Gps/SpeedUnit"),
|
|
13
|
+
volume: "N/".concat(portalId, "/settings/0/Settings/System/VolumeUnit"),
|
|
12
14
|
},
|
|
13
15
|
guiVersion: "N/".concat(portalId, "/settings/0/Settings/Gui/RunningVersion"),
|
|
14
16
|
electricalPowerIndicator: "N/".concat(portalId, "/settings/0/Settings/Gui/ElectricalPowerIndicator"),
|
|
@@ -16,26 +18,45 @@ export var useApp = function () {
|
|
|
16
18
|
var topics = useMemo(function () { return getTopics(mqtt.portalId); }, [mqtt.portalId]);
|
|
17
19
|
var locked = useTopicState(topics.locked);
|
|
18
20
|
var firmwareVersion = useTopicState(topics.firmwareVersion);
|
|
19
|
-
var
|
|
21
|
+
var temperatureUnit = useTopicState(topics.units.temperature);
|
|
22
|
+
var speedUnit = useTopicState(topics.units.speed);
|
|
23
|
+
var volumeUnit = useTopicState(topics.units.volume);
|
|
20
24
|
var guiVersion = useTopicState(topics.guiVersion);
|
|
21
25
|
var electricalPowerIndicator = useTopicState(topics.electricalPowerIndicator);
|
|
22
26
|
useEffect(function () {
|
|
23
27
|
if (locked !== undefined) {
|
|
24
28
|
appStore.setLockedWithoutPersistence(!!locked);
|
|
25
29
|
}
|
|
26
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
30
|
}, [locked]);
|
|
28
31
|
useEffect(function () {
|
|
29
|
-
|
|
32
|
+
if (firmwareVersion) {
|
|
33
|
+
appStore.setFirmwareVersion(firmwareVersion);
|
|
34
|
+
}
|
|
30
35
|
}, [firmwareVersion]);
|
|
31
36
|
useEffect(function () {
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
if (temperatureUnit) {
|
|
38
|
+
appStore.setUnit("temperature", temperatureUnit);
|
|
39
|
+
}
|
|
40
|
+
}, [temperatureUnit]);
|
|
41
|
+
useEffect(function () {
|
|
42
|
+
if (speedUnit) {
|
|
43
|
+
appStore.setUnit("speed", speedUnit);
|
|
44
|
+
}
|
|
45
|
+
}, [speedUnit]);
|
|
46
|
+
useEffect(function () {
|
|
47
|
+
if (volumeUnit) {
|
|
48
|
+
appStore.setUnit("volume", volumeUnit);
|
|
49
|
+
}
|
|
50
|
+
}, [volumeUnit]);
|
|
34
51
|
useEffect(function () {
|
|
35
|
-
|
|
52
|
+
if (guiVersion) {
|
|
53
|
+
appStore.setGuiVersion(guiVersion);
|
|
54
|
+
}
|
|
36
55
|
}, [guiVersion]);
|
|
37
56
|
useEffect(function () {
|
|
38
|
-
electricalPowerIndicator !== undefined
|
|
57
|
+
if (electricalPowerIndicator !== undefined) {
|
|
58
|
+
appStore.setElectricalPowerIndicator(electricalPowerIndicator);
|
|
59
|
+
}
|
|
39
60
|
}, [electricalPowerIndicator]);
|
|
40
61
|
return appStore;
|
|
41
62
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.provider.js","sourceRoot":"/","sources":["src/Modules/App/App.provider.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"App.provider.js","sourceRoot":"/","sources":["src/Modules/App/App.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAY,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,EAA0C,WAAW,EAAE,MAAM,aAAa,CAAA;AAEjF,MAAM,CAAC,IAAM,MAAM,GAAG;IACpB,IAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,IAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IAEtB,IAAM,SAAS,GAAG,UAAC,QAAkB,IAAK,OAAA,CAAC;QACzC,MAAM,EAAE,YAAK,QAAQ,4CAAyC;QAC9D,eAAe,EAAE,YAAK,QAAQ,8BAA2B;QACzD,KAAK,EAAE;YACL,WAAW,EAAE,YAAK,QAAQ,kDAA+C;YACzE,KAAK,EAAE,YAAK,QAAQ,uCAAoC;YACxD,MAAM,EAAE,YAAK,QAAQ,2CAAwC;SAC9D;QACD,UAAU,EAAE,YAAK,QA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C,eAAe,CAAC,CAAC,CAAA;IAErB,SAAS,CAAC;QACR,IAAI,SAAS,EAAE,CAAC;YACd,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,SAAsB,CAAC,CAAA;QACnD,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,SAAS,CAAC;QACR,IAAI,UAAU,EAAE,CAAC;YACf,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAwB,CAAC,CAAA;QACtD,CAAC;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhB,SAAS,CAAC;QACR,IAAI,UAAU,EAAE,CAAC;YACf,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;QACpC,CAAC;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhB,SAAS,CAAC;QACR,IAAI,wBAAwB,KAAK,SAAS,EAAE,CAAC;YAC3C,QAAQ,CAAC,2BAA2B,CAAC,wBAAwB,CAAC,CAAA;QAChE,CAAC;IACH,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAC,CAAA;IAE9B,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import { useEffect, useMemo } from \"react\"\nimport { PortalId, useMqtt, useTopicState } from \"../Mqtt\"\nimport { TemperatureUnit, SpeedUnit, VolumeUnit, useAppStore } from \"./App.store\"\n\nexport const useApp = () => {\n const appStore = useAppStore()\n const mqtt = useMqtt()\n\n const getTopics = (portalId: PortalId) => ({\n locked: `N/${portalId}/settings/0/Settings/VenusApp/LockState`,\n firmwareVersion: `N/${portalId}/system/0/FirmwareVersion`,\n units: {\n temperature: `N/${portalId}/settings/0/Settings/System/Units/Temperature`,\n speed: `N/${portalId}/settings/0/Settings/Gps/SpeedUnit`,\n volume: `N/${portalId}/settings/0/Settings/System/VolumeUnit`,\n },\n guiVersion: `N/${portalId}/settings/0/Settings/Gui/RunningVersion`,\n electricalPowerIndicator: `N/${portalId}/settings/0/Settings/Gui/ElectricalPowerIndicator`,\n })\n\n const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId])\n\n const locked = useTopicState<number>(topics.locked)\n const firmwareVersion = useTopicState<string>(topics.firmwareVersion)\n const temperatureUnit = useTopicState<string>(topics.units.temperature)\n const speedUnit = useTopicState<string>(topics.units.speed)\n const volumeUnit = useTopicState<number>(topics.units.volume)\n const guiVersion = useTopicState<number>(topics.guiVersion)\n const electricalPowerIndicator = useTopicState<number>(topics.electricalPowerIndicator)\n\n useEffect(() => {\n if (locked !== undefined) {\n appStore.setLockedWithoutPersistence(!!locked)\n }\n }, [locked])\n\n useEffect(() => {\n if (firmwareVersion) {\n appStore.setFirmwareVersion(firmwareVersion)\n }\n }, [firmwareVersion])\n\n useEffect(() => {\n if (temperatureUnit) {\n appStore.setUnit(\"temperature\", temperatureUnit as TemperatureUnit)\n }\n }, [temperatureUnit])\n\n useEffect(() => {\n if (speedUnit) {\n appStore.setUnit(\"speed\", speedUnit as SpeedUnit)\n }\n }, [speedUnit])\n\n useEffect(() => {\n if (volumeUnit) {\n appStore.setUnit(\"volume\", volumeUnit as VolumeUnit)\n }\n }, [volumeUnit])\n\n useEffect(() => {\n if (guiVersion) {\n appStore.setGuiVersion(guiVersion)\n }\n }, [guiVersion])\n\n useEffect(() => {\n if (electricalPowerIndicator !== undefined) {\n appStore.setElectricalPowerIndicator(electricalPowerIndicator)\n }\n }, [electricalPowerIndicator])\n\n return appStore\n}\n"]}
|
|
@@ -6,8 +6,17 @@ export interface AppState {
|
|
|
6
6
|
}
|
|
7
7
|
interface IUnit {
|
|
8
8
|
temperature: TemperatureUnit;
|
|
9
|
+
speed: SpeedUnit;
|
|
10
|
+
volume: VolumeUnit;
|
|
9
11
|
}
|
|
10
12
|
export type TemperatureUnit = "fahrenheit" | "celsius";
|
|
13
|
+
export type SpeedUnit = "km/h" | "m/s" | "mph" | "kt";
|
|
14
|
+
export declare enum VolumeUnit {
|
|
15
|
+
CUBIC_METERS = 0,
|
|
16
|
+
LITRES = 1,
|
|
17
|
+
GALLONS_IMPERIAL = 2,
|
|
18
|
+
GALLONS_US = 3
|
|
19
|
+
}
|
|
11
20
|
export declare class AppStore {
|
|
12
21
|
page: string;
|
|
13
22
|
locked: boolean;
|
|
@@ -22,6 +31,10 @@ export declare class AppStore {
|
|
|
22
31
|
get humanReadableFirmwareVersion(): any;
|
|
23
32
|
get temperatureUnitToHumanReadable(): "°C" | "°F";
|
|
24
33
|
get temperatureUnit(): TemperatureUnit;
|
|
34
|
+
get speedUnitToHumanReadable(): SpeedUnit;
|
|
35
|
+
get speedUnit(): SpeedUnit;
|
|
36
|
+
get volumeUnitToHumanReadable(): "m³" | "l" | "gal";
|
|
37
|
+
get volumeUnit(): VolumeUnit;
|
|
25
38
|
setPage: (page: string) => string;
|
|
26
39
|
setLockedWithoutPersistence: (locked: boolean) => boolean;
|
|
27
40
|
setRemote: (remote: boolean) => void;
|
|
@@ -29,9 +42,7 @@ export declare class AppStore {
|
|
|
29
42
|
toggleLocked: () => void;
|
|
30
43
|
setLanguage: (language: string) => string;
|
|
31
44
|
setFirmwareVersion: (firmwareVersion: string) => string;
|
|
32
|
-
setUnit: (unit:
|
|
33
|
-
temperature: TemperatureUnit;
|
|
34
|
-
};
|
|
45
|
+
setUnit: <K extends keyof IUnit>(unit: K, value: IUnit[K]) => void;
|
|
35
46
|
setGuiVersion: (guiVersion: number) => number;
|
|
36
47
|
setElectricalPowerIndicator: (electricalPowerIndicator: number) => number;
|
|
37
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.store.d.ts","sourceRoot":"/","sources":["src/Modules/App/App.store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAW,MAAM,SAAS,CAAA;AAE5C,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,UAAU,K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GAAI,QAAQ,OAAO,UAa3B;IACD,YAAY,aAAqC;IACjD,YAAY,aAGX;IACD,WAAW,GAAI,UAAU,MAAM,YAA+B;IAC9D,kBAAkB,GAAI,iBAAiB,MAAM,YAA6C;IAC1F,OAAO,GAAI,CAAC,SAAS,MAAM,KAAK,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,UAKzD;IACD,aAAa,GAAI,YAAY,MAAM,YAAmC;IACtE,2BAA2B,GAAI,0BAA0B,MAAM,YACH;CAC7D;AAYD,wBAAgB,WAAW,aAG1B"}
|
|
@@ -14,6 +14,13 @@ import { useMemo } from "react";
|
|
|
14
14
|
import { versionToHumanReadable } from "../../utils/util";
|
|
15
15
|
import { VIEWS } from "../../utils/constants";
|
|
16
16
|
import { useMqtt } from "../Mqtt";
|
|
17
|
+
export var VolumeUnit;
|
|
18
|
+
(function (VolumeUnit) {
|
|
19
|
+
VolumeUnit[VolumeUnit["CUBIC_METERS"] = 0] = "CUBIC_METERS";
|
|
20
|
+
VolumeUnit[VolumeUnit["LITRES"] = 1] = "LITRES";
|
|
21
|
+
VolumeUnit[VolumeUnit["GALLONS_IMPERIAL"] = 2] = "GALLONS_IMPERIAL";
|
|
22
|
+
VolumeUnit[VolumeUnit["GALLONS_US"] = 3] = "GALLONS_US";
|
|
23
|
+
})(VolumeUnit || (VolumeUnit = {}));
|
|
17
24
|
var store;
|
|
18
25
|
var AppStore = /** @class */ (function () {
|
|
19
26
|
function AppStore(mqttStore) {
|
|
@@ -36,7 +43,9 @@ var AppStore = /** @class */ (function () {
|
|
|
36
43
|
enumerable: true,
|
|
37
44
|
configurable: true,
|
|
38
45
|
writable: true,
|
|
39
|
-
value: typeof window !== "undefined" &&
|
|
46
|
+
value: typeof window !== "undefined" &&
|
|
47
|
+
(window === null || window === void 0 ? void 0 : window.location.protocol) === "https:" &&
|
|
48
|
+
(window === null || window === void 0 ? void 0 : window.location.hostname.endsWith("victronenergy.com")) &&
|
|
40
49
|
((window === null || window === void 0 ? void 0 : window.location.hostname.startsWith("mqtt")) || (window === null || window === void 0 ? void 0 : window.location.hostname.startsWith("webmqtt")))
|
|
41
50
|
});
|
|
42
51
|
Object.defineProperty(this, "language", {
|
|
@@ -79,13 +88,13 @@ var AppStore = /** @class */ (function () {
|
|
|
79
88
|
enumerable: true,
|
|
80
89
|
configurable: true,
|
|
81
90
|
writable: true,
|
|
82
|
-
value: function (page) { return _this.page = page; }
|
|
91
|
+
value: function (page) { return (_this.page = page); }
|
|
83
92
|
});
|
|
84
93
|
Object.defineProperty(this, "setLockedWithoutPersistence", {
|
|
85
94
|
enumerable: true,
|
|
86
95
|
configurable: true,
|
|
87
96
|
writable: true,
|
|
88
|
-
value: function (locked) { return _this.locked = locked; }
|
|
97
|
+
value: function (locked) { return (_this.locked = locked); }
|
|
89
98
|
});
|
|
90
99
|
Object.defineProperty(this, "setRemote", {
|
|
91
100
|
enumerable: true,
|
|
@@ -93,14 +102,14 @@ var AppStore = /** @class */ (function () {
|
|
|
93
102
|
writable: true,
|
|
94
103
|
value: function (remote) {
|
|
95
104
|
_this.remote = remote;
|
|
96
|
-
// @ts-
|
|
105
|
+
// @ts-expect-error Missing TS declaration for venusNativeApp
|
|
97
106
|
if (window === null || window === void 0 ? void 0 : window.venusNativeApp) {
|
|
98
107
|
if (remote) {
|
|
99
|
-
// @ts-
|
|
108
|
+
// @ts-expect-error Missing TS declaration for venusNativeApp
|
|
100
109
|
window.venusNativeApp.switchToRemote();
|
|
101
110
|
}
|
|
102
111
|
else {
|
|
103
|
-
// @ts-
|
|
112
|
+
// @ts-expect-error Missing TS declaration for venusNativeApp
|
|
104
113
|
window.venusNativeApp.switchToLocal();
|
|
105
114
|
}
|
|
106
115
|
}
|
|
@@ -125,13 +134,13 @@ var AppStore = /** @class */ (function () {
|
|
|
125
134
|
enumerable: true,
|
|
126
135
|
configurable: true,
|
|
127
136
|
writable: true,
|
|
128
|
-
value: function (language) { return _this.language = language; }
|
|
137
|
+
value: function (language) { return (_this.language = language); }
|
|
129
138
|
});
|
|
130
139
|
Object.defineProperty(this, "setFirmwareVersion", {
|
|
131
140
|
enumerable: true,
|
|
132
141
|
configurable: true,
|
|
133
142
|
writable: true,
|
|
134
|
-
value: function (firmwareVersion) { return _this.firmwareVersion = firmwareVersion; }
|
|
143
|
+
value: function (firmwareVersion) { return (_this.firmwareVersion = firmwareVersion); }
|
|
135
144
|
});
|
|
136
145
|
Object.defineProperty(this, "setUnit", {
|
|
137
146
|
enumerable: true,
|
|
@@ -139,26 +148,30 @@ var AppStore = /** @class */ (function () {
|
|
|
139
148
|
writable: true,
|
|
140
149
|
value: function (unit, value) {
|
|
141
150
|
var _a;
|
|
142
|
-
|
|
151
|
+
_this.units = __assign(__assign({}, _this.units), (_a = {}, _a[unit] = value, _a));
|
|
143
152
|
}
|
|
144
153
|
});
|
|
145
154
|
Object.defineProperty(this, "setGuiVersion", {
|
|
146
155
|
enumerable: true,
|
|
147
156
|
configurable: true,
|
|
148
157
|
writable: true,
|
|
149
|
-
value: function (guiVersion) { return _this.guiVersion = guiVersion; }
|
|
158
|
+
value: function (guiVersion) { return (_this.guiVersion = guiVersion); }
|
|
150
159
|
});
|
|
151
160
|
Object.defineProperty(this, "setElectricalPowerIndicator", {
|
|
152
161
|
enumerable: true,
|
|
153
162
|
configurable: true,
|
|
154
163
|
writable: true,
|
|
155
|
-
value: function (electricalPowerIndicator) {
|
|
164
|
+
value: function (electricalPowerIndicator) {
|
|
165
|
+
return (_this.electricalPowerIndicator = electricalPowerIndicator);
|
|
166
|
+
}
|
|
156
167
|
});
|
|
157
168
|
makeAutoObservable(this, { mqtt: false });
|
|
158
169
|
this.mqtt = mqttStore;
|
|
159
170
|
this.firmwareVersion = "-";
|
|
160
171
|
this.units = {
|
|
161
|
-
temperature: "celsius"
|
|
172
|
+
temperature: "celsius",
|
|
173
|
+
speed: "km/h",
|
|
174
|
+
volume: VolumeUnit.CUBIC_METERS,
|
|
162
175
|
};
|
|
163
176
|
this.guiVersion = 2;
|
|
164
177
|
this.electricalPowerIndicator = 1;
|
|
@@ -187,6 +200,43 @@ var AppStore = /** @class */ (function () {
|
|
|
187
200
|
enumerable: false,
|
|
188
201
|
configurable: true
|
|
189
202
|
});
|
|
203
|
+
Object.defineProperty(AppStore.prototype, "speedUnitToHumanReadable", {
|
|
204
|
+
get: function () {
|
|
205
|
+
return this.units.speed;
|
|
206
|
+
},
|
|
207
|
+
enumerable: false,
|
|
208
|
+
configurable: true
|
|
209
|
+
});
|
|
210
|
+
Object.defineProperty(AppStore.prototype, "speedUnit", {
|
|
211
|
+
get: function () {
|
|
212
|
+
return this.units.speed;
|
|
213
|
+
},
|
|
214
|
+
enumerable: false,
|
|
215
|
+
configurable: true
|
|
216
|
+
});
|
|
217
|
+
Object.defineProperty(AppStore.prototype, "volumeUnitToHumanReadable", {
|
|
218
|
+
get: function () {
|
|
219
|
+
switch (this.units.volume) {
|
|
220
|
+
case VolumeUnit.CUBIC_METERS:
|
|
221
|
+
return "m³";
|
|
222
|
+
case VolumeUnit.LITRES:
|
|
223
|
+
return "l";
|
|
224
|
+
case VolumeUnit.GALLONS_IMPERIAL:
|
|
225
|
+
return "gal";
|
|
226
|
+
case VolumeUnit.GALLONS_US:
|
|
227
|
+
return "gal";
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
enumerable: false,
|
|
231
|
+
configurable: true
|
|
232
|
+
});
|
|
233
|
+
Object.defineProperty(AppStore.prototype, "volumeUnit", {
|
|
234
|
+
get: function () {
|
|
235
|
+
return this.units.volume;
|
|
236
|
+
},
|
|
237
|
+
enumerable: false,
|
|
238
|
+
configurable: true
|
|
239
|
+
});
|
|
190
240
|
return AppStore;
|
|
191
241
|
}());
|
|
192
242
|
export { AppStore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.store.js","sourceRoot":"/","sources":["src/Modules/App/App.store.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAA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nimport { useMemo } from \"react\"\nimport { versionToHumanReadable } from \"../../utils/util\"\nimport { VIEWS } from \"../../utils/constants\"\nimport { MqttStore, useMqtt } from \"../Mqtt\"\n\nexport interface AppState {\n page: string\n locked: boolean\n remote: boolean\n}\n\ninterface IUnit {\n temperature: TemperatureUnit\n speed: SpeedUnit\n volume: VolumeUnit\n}\n\nexport type TemperatureUnit = \"fahrenheit\" | \"celsius\"\nexport type SpeedUnit = \"km/h\" | \"m/s\" | \"mph\" | \"kt\"\nexport enum VolumeUnit {\n CUBIC_METERS = 0,\n LITRES = 1,\n GALLONS_IMPERIAL = 2,\n GALLONS_US = 3,\n}\n\nlet store: AppStore\n\nexport class AppStore {\n page: string = VIEWS.METRICS\n locked: boolean = false\n // figure out whether we are connecting to VRM provided MQTT broker\n // see https://github.com/victronenergy/dbus-flashmq?tab=readme-ov-file#determining-the-broker-url-for-a-given-installation\n remote: boolean =\n typeof window !== \"undefined\" &&\n window?.location.protocol === \"https:\" &&\n window?.location.hostname.endsWith(\"victronenergy.com\") &&\n (window?.location.hostname.startsWith(\"mqtt\") || window?.location.hostname.startsWith(\"webmqtt\"))\n language?: string\n mqtt: MqttStore\n firmwareVersion: string\n units: IUnit\n guiVersion: number\n electricalPowerIndicator: number\n\n constructor(mqttStore: MqttStore) {\n makeAutoObservable(this, { mqtt: false })\n this.mqtt = mqttStore\n this.firmwareVersion = \"-\"\n this.units = {\n temperature: \"celsius\",\n speed: \"km/h\",\n volume: VolumeUnit.CUBIC_METERS,\n }\n this.guiVersion = 2\n this.electricalPowerIndicator = 1\n }\n\n get humanReadableFirmwareVersion() {\n return versionToHumanReadable(+this.firmwareVersion) || \"-\"\n }\n\n get temperatureUnitToHumanReadable() {\n if (this.units.temperature === \"celsius\") {\n return \"°C\"\n }\n\n return \"°F\"\n }\n\n get temperatureUnit() {\n return this.units.temperature\n }\n\n get speedUnitToHumanReadable() {\n return this.units.speed\n }\n\n get speedUnit() {\n return this.units.speed\n }\n\n get volumeUnitToHumanReadable() {\n switch (this.units.volume) {\n case VolumeUnit.CUBIC_METERS:\n return \"m³\"\n case VolumeUnit.LITRES:\n return \"l\"\n case VolumeUnit.GALLONS_IMPERIAL:\n return \"gal\"\n case VolumeUnit.GALLONS_US:\n return \"gal\"\n }\n }\n\n get volumeUnit() {\n return this.units.volume\n }\n\n setPage = (page: string) => (this.page = page)\n setLockedWithoutPersistence = (locked: boolean) => (this.locked = locked)\n setRemote = (remote: boolean) => {\n this.remote = remote\n\n // @ts-expect-error Missing TS declaration for venusNativeApp\n if (window?.venusNativeApp) {\n if (remote) {\n // @ts-expect-error Missing TS declaration for venusNativeApp\n window.venusNativeApp.switchToRemote()\n } else {\n // @ts-expect-error Missing TS declaration for venusNativeApp\n window.venusNativeApp.switchToLocal()\n }\n }\n }\n toggleRemote = () => this.setRemote(!this.remote)\n toggleLocked = () => {\n this.mqtt.publish(`N/${this.mqtt.portalId}/settings/0/Settings/VenusApp/LockState`, +!this.locked)\n this.locked = !this.locked\n }\n setLanguage = (language: string) => (this.language = language)\n setFirmwareVersion = (firmwareVersion: string) => (this.firmwareVersion = firmwareVersion)\n setUnit = <K extends keyof IUnit>(unit: K, value: IUnit[K]) => {\n this.units = {\n ...this.units,\n [unit]: value,\n }\n }\n setGuiVersion = (guiVersion: number) => (this.guiVersion = guiVersion)\n setElectricalPowerIndicator = (electricalPowerIndicator: number) =>\n (this.electricalPowerIndicator = electricalPowerIndicator)\n}\n\nfunction initializeStore(mqttStore: MqttStore) {\n const _store = store ?? new AppStore(mqttStore)\n // For SSG and SSR always create a new store\n if (typeof window === \"undefined\") return _store\n // Create the store once in the client\n if (!store) store = _store\n\n return _store\n}\n\nexport function useAppStore() {\n const mqtt = useMqtt()\n return useMemo(() => initializeStore(mqtt), [])\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchableOutputs.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.provider.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"SwitchableOutputs.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.provider.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,oBAAoB,kEA0JhC,CAAA"}
|
|
@@ -44,6 +44,10 @@ export var useSwitchableOutputs = function () {
|
|
|
44
44
|
var availableSwitchableOutputTypes_1 = availableSwitchableOutputs_1.map(function (topic) {
|
|
45
45
|
return messagesForSwitchableOutputs["".concat(topic.slice(0, -"/Group".length), "/Type")];
|
|
46
46
|
});
|
|
47
|
+
// All switchable outputs names in array sorted by topic
|
|
48
|
+
var availableSwitchableOutputNames_1 = availableSwitchableOutputs_1.map(function (topic) {
|
|
49
|
+
return messagesForSwitchableOutputs["".concat(topic.slice(0, -"/Group".length), "/CustomName")];
|
|
50
|
+
});
|
|
47
51
|
// All switchable outputs visibility in array sorted by topic
|
|
48
52
|
var availableSwitchableOutputVisibilityFlags_1 = availableSwitchableOutputs_1.map(function (topic) {
|
|
49
53
|
return messagesForSwitchableOutputs["".concat(topic.slice(0, -"/Group".length), "/ShowUIControl")];
|
|
@@ -73,6 +77,13 @@ export var useSwitchableOutputs = function () {
|
|
|
73
77
|
switchableOutputsStore.setOutputTypes(newOutputTypes);
|
|
74
78
|
Logger.log("Switchable outputs types changed, recomputing...");
|
|
75
79
|
}
|
|
80
|
+
var oldOutputNames = switchableOutputsStore.outputNames;
|
|
81
|
+
var newOutputNames = availableSwitchableOutputNames_1;
|
|
82
|
+
var outputNamesChanged = !arraysEqual(oldOutputNames, newOutputNames);
|
|
83
|
+
if (outputNamesChanged) {
|
|
84
|
+
switchableOutputsStore.setOutputNames(newOutputNames);
|
|
85
|
+
Logger.log("Switchable outputs names changed, recomputing...");
|
|
86
|
+
}
|
|
76
87
|
var oldOutputVisibilityFlags = switchableOutputsStore.outputVisibilityFlags;
|
|
77
88
|
var newOutputVisibilityFlags = availableSwitchableOutputVisibilityFlags_1;
|
|
78
89
|
var outputVisibilityFlagsChanged = !arraysEqual(oldOutputVisibilityFlags, newOutputVisibilityFlags);
|
|
@@ -96,6 +107,7 @@ export var useSwitchableOutputs = function () {
|
|
|
96
107
|
}
|
|
97
108
|
if (groupAssignmentsChanged ||
|
|
98
109
|
outputTypesChanged ||
|
|
110
|
+
outputNamesChanged ||
|
|
99
111
|
outputVisibilityFlagsChanged ||
|
|
100
112
|
switchingDevicesChanged ||
|
|
101
113
|
switchingDeviceNamesChanged) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchableOutputs.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.provider.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAY,OAAO,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,6BAA6B,EAA6B,MAAM,4BAA4B,CAAA;AACrG,OAAO,EAAE,8BAA8B,EAA6C,MAAM,6BAA6B,CAAA;AAEvH,MAAM,CAAC,IAAM,oBAAoB,GAAG;IAClC,IAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAA;IAE1D,IAAM,SAAS,GAAG,UAAC,QAAkB,IAAK,OAAA,CAAC;QACzC,iBAAiB,EAAE,YAAK,QAAQ,4CAAyC;QACzE,gBAAgB,EAAE,YAAK,QAAQ,cAAW;KAC3C,CAAC,EAHwC,CAGxC,CAAA;IAEF,IAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IACtB,IAAM,MAAM,GAAG,OAAO,CAAC,cAAM,OAAA,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAxB,CAAwB,EAAE,CA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ger from \"../../utils/logger\"\nimport { PortalId, useMqtt } from \"../Mqtt\"\nimport { useMemo, useEffect } from \"react\"\nimport { useSwitchableOutputsStore } from \"./SwitchableOutputs.store\"\nimport { getSwitchingDeviceStateTopics, SwitchingDeviceInstanceId } from \"./SwitchingDevice.provider\"\nimport { getSwitchableOutputStateTopics, SwitchableOutputId, SwitchableOutputState } from \"./SwitchableOutput.provider\"\n\nexport const useSwitchableOutputs = () => {\n const switchableOutputsStore = useSwitchableOutputsStore()\n\n const getTopics = (portalId: PortalId) => ({\n switchableOutputs: `N/${portalId}/switch/+/SwitchableOutput/+/Settings/+`,\n switchingDevices: `N/${portalId}/switch/+`,\n })\n\n const mqtt = useMqtt()\n const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId])\n\n const messagesForSwitchableOutputs = mqtt.messagesByWildcard(topics.switchableOutputs)\n const messagesForSwitchingDevices = mqtt.messagesByWildcard(topics.switchingDevices)\n\n // Examine MQTT to find all available switchable outputs and their group assignments\n useEffect(() => {\n if (!messagesForSwitchableOutputs || Object.entries(messagesForSwitchableOutputs).length === 0) {\n Logger.log(\"Waiting for switchable outputs...\")\n } else {\n // All switchable outputs in array sorted by topic\n const availableSwitchableOutputs = Object.keys(messagesForSwitchableOutputs)\n .filter((key) => key.endsWith(\"/Settings/Group\"))\n .sort() as string[]\n\n // All switchable outputs group assignments in array sorted by topic\n const customGroupAssigments = availableSwitchableOutputs.map((topic) => {\n return messagesForSwitchableOutputs[topic]\n })\n // All switchable outputs types in array sorted by topic\n const availableSwitchableOutputTypes = availableSwitchableOutputs.map((topic) => {\n return messagesForSwitchableOutputs[`${topic.slice(0, -\"/Group\".length)}/Type`]\n })\n // All switchable outputs visibility in array sorted by topic\n const availableSwitchableOutputVisibilityFlags = availableSwitchableOutputs.map((topic) => {\n return messagesForSwitchableOutputs[`${topic.slice(0, -\"/Group\".length)}/ShowUIControl`]\n })\n\n // All switching devices in array sorted by instance number\n const availableSwitchingDevices = Object.keys(messagesForSwitchingDevices)\n .filter((key) => key.endsWith(\"/DeviceInstance\"))\n .sort() as string[]\n // All switching device names in array sorted by instance number\n const availableSwitchingDeviceNames = availableSwitchingDevices.map((topic) => {\n const topicPrefix = topic.slice(0, -\"/DeviceInstance\".length)\n return (\n messagesForSwitchingDevices[`${topicPrefix}/CustomName`] ||\n messagesForSwitchingDevices[`${topicPrefix}/ProductName`]\n )\n })\n\n const dispose = autorun(() => {\n const oldAssignments = switchableOutputsStore.customGroupAssignments\n const newAssignments = customGroupAssigments\n const groupAssignmentsChanged = !arraysEqual(oldAssignments, newAssignments)\n if (groupAssignmentsChanged) {\n switchableOutputsStore.setCustomGroupAssignments(newAssignments)\n Logger.log(`Switchable outputs group assignments changed, recomputing...`)\n }\n\n const oldOutputTypes = switchableOutputsStore.outputTypes\n const newOutputTypes = availableSwitchableOutputTypes\n const outputTypesChanged = !arraysEqual(oldOutputTypes, newOutputTypes)\n if (outputTypesChanged) {\n switchableOutputsStore.setOutputTypes(newOutputTypes)\n Logger.log(`Switchable outputs types changed, recomputing...`)\n }\n\n const oldOutputVisibilityFlags = switchableOutputsStore.outputVisibilityFlags\n const newOutputVisibilityFlags = availableSwitchableOutputVisibilityFlags\n const outputVisibilityFlagsChanged = !arraysEqual(oldOutputVisibilityFlags, newOutputVisibilityFlags)\n if (outputVisibilityFlagsChanged) {\n switchableOutputsStore.setOutputVisibilityFlags(newOutputVisibilityFlags)\n Logger.log(`Switchable outputs visibility flags changed, recomputing...`)\n }\n\n const oldSwitchingDevices = switchableOutputsStore.switchingDevices\n const newSwitchingDevices = availableSwitchingDevices\n const switchingDevicesChanged = !arraysEqual(oldSwitchingDevices, newSwitchingDevices)\n if (switchingDevicesChanged) {\n switchableOutputsStore.setSwitchingDevices(newSwitchingDevices)\n Logger.log(`Switching devices changed, recomputing...`)\n }\n\n const oldSwitchingDeviceNames = switchableOutputsStore.switchingDeviceNames\n const newSwitchingDeviceNames = availableSwitchingDeviceNames\n const switchingDeviceNamesChanged = !arraysEqual(oldSwitchingDeviceNames, newSwitchingDeviceNames)\n if (switchingDeviceNamesChanged) {\n switchableOutputsStore.setSwitchingDeviceNames(newSwitchingDeviceNames)\n Logger.log(`Switching device names changed, recomputing...`)\n }\n\n if (\n groupAssignmentsChanged ||\n outputTypesChanged ||\n outputVisibilityFlagsChanged ||\n switchingDevicesChanged ||\n switchingDeviceNamesChanged\n ) {\n // New groups mapping array of switches to group name key\n const newGroups: { [key: string]: SwitchableOutputState[] } = {}\n\n // Walk the array of all switchable outputs, determine to which group it belongs\n // and populate its initial state\n availableSwitchableOutputs.forEach((output, index) => {\n const swo = extractSwitchableOutputInfo(output)\n const switchingDevice = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, swo.deviceId))\n const customGroupAssignment = customGroupAssigments[index].trim()\n const groupName =\n customGroupAssignment === \"\"\n ? switchingDevice.customName || switchingDevice.productName\n : customGroupAssignment\n const switchableOutput = mqtt.messagesByTopics(\n getSwitchableOutputStateTopics(mqtt.portalId, swo.deviceId, swo.outputId)\n ) as unknown as SwitchableOutputState\n\n // Ignore hidden controls\n if (switchableOutput.showUIControl === 0) {\n return\n }\n\n newGroups[groupName] ||= []\n newGroups[groupName].push({ ...switchableOutput, deviceId: swo.deviceId, outputId: swo.outputId })\n })\n\n Logger.log(`New switchable output groups: ${JSON.stringify(Object.keys(newGroups))}`)\n // Sort switches in a group by name\n Object.values(newGroups).forEach((array) => {\n array.sort((a, b) => {\n const aName = a.customName || a.name\n const bName = b.customName || b.name\n return aName.localeCompare(bName)\n })\n })\n switchableOutputsStore.setGroups(newGroups)\n }\n })\n return () => dispose()\n }\n }, [messagesForSwitchableOutputs, messagesForSwitchingDevices])\n\n return switchableOutputsStore\n}\n\nfunction extractSwitchableOutputInfo(topic: string) {\n const switchStart = topic.indexOf(\"/switch/\") + 8 // length of `/switch/`\n const outputStart = topic.indexOf(\"/SwitchableOutput/\") + 18 // length of `/SwitchableOutput/`\n\n return {\n deviceId: topic.substring(switchStart, topic.indexOf(\"/\", switchStart)) as unknown as SwitchingDeviceInstanceId,\n outputId: topic.substring(outputStart, topic.indexOf(\"/\", outputStart)) as unknown as SwitchableOutputId,\n }\n}\n\nfunction arraysEqual<T>(a: T[], b: T[]): boolean {\n if (a.length !== b.length) return false\n return a.every((element, index) => b[index] === element)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SwitchableOutputs.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.provider.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAY,OAAO,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,6BAA6B,EAA6B,MAAM,4BAA4B,CAAA;AACrG,OAAO,EAAE,8BAA8B,EAA6C,MAAM,6BAA6B,CAAA;AAEvH,MAAM,CAAC,IAAM,oBAAoB,GAAG;IAClC,IAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAA;IAE1D,IAAM,SAAS,GAAG,UAAC,QAAkB,IAAK,OAAA,CAAC;QACzC,iBAAiB,EAAE,YAAK,QAAQ,4CAAyC;QACzE,gBAAgB,EAAE,YAAK,QAAQ,cAAW;KAC3C,CAAC,EAHwC,CAGxC,CAAA;IAEF,IAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IACtB,IAAM,MAAM,GAAG,OAAO,CAAC,cAAM,OAAA,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAxB,CAAwB,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEvE,IAAM,4BAA4B,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAA;IACtF,IAAM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AE,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAkC;KACzG,CAAA;AACH,CAAC;AAED,SAAS,WAAW,CAAI,CAAM,EAAE,CAAM;IACpC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IACvC,OAAO,CAAC,CAAC,KAAK,CAAC,UAAC,OAAO,EAAE,KAAK,IAAK,OAAA,CAAC,CAAC,KAAK,CAAC,KAAK,OAAO,EAApB,CAAoB,CAAC,CAAA;AAC1D,CAAC","sourcesContent":["import { autorun } from \"mobx\"\nimport Logger from \"../../utils/logger\"\nimport { PortalId, useMqtt } from \"../Mqtt\"\nimport { useMemo, useEffect } from \"react\"\nimport { useSwitchableOutputsStore } from \"./SwitchableOutputs.store\"\nimport { getSwitchingDeviceStateTopics, SwitchingDeviceInstanceId } from \"./SwitchingDevice.provider\"\nimport { getSwitchableOutputStateTopics, SwitchableOutputId, SwitchableOutputState } from \"./SwitchableOutput.provider\"\n\nexport const useSwitchableOutputs = () => {\n const switchableOutputsStore = useSwitchableOutputsStore()\n\n const getTopics = (portalId: PortalId) => ({\n switchableOutputs: `N/${portalId}/switch/+/SwitchableOutput/+/Settings/+`,\n switchingDevices: `N/${portalId}/switch/+`,\n })\n\n const mqtt = useMqtt()\n const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId])\n\n const messagesForSwitchableOutputs = mqtt.messagesByWildcard(topics.switchableOutputs)\n const messagesForSwitchingDevices = mqtt.messagesByWildcard(topics.switchingDevices)\n\n // Examine MQTT to find all available switchable outputs and their group assignments\n useEffect(() => {\n if (!messagesForSwitchableOutputs || Object.entries(messagesForSwitchableOutputs).length === 0) {\n Logger.log(\"Waiting for switchable outputs...\")\n } else {\n // All switchable outputs in array sorted by topic\n const availableSwitchableOutputs = Object.keys(messagesForSwitchableOutputs)\n .filter((key) => key.endsWith(\"/Settings/Group\"))\n .sort() as string[]\n\n // All switchable outputs group assignments in array sorted by topic\n const customGroupAssigments = availableSwitchableOutputs.map((topic) => {\n return messagesForSwitchableOutputs[topic]\n })\n // All switchable outputs types in array sorted by topic\n const availableSwitchableOutputTypes = availableSwitchableOutputs.map((topic) => {\n return messagesForSwitchableOutputs[`${topic.slice(0, -\"/Group\".length)}/Type`]\n })\n // All switchable outputs names in array sorted by topic\n const availableSwitchableOutputNames = availableSwitchableOutputs.map((topic) => {\n return messagesForSwitchableOutputs[`${topic.slice(0, -\"/Group\".length)}/CustomName`]\n })\n // All switchable outputs visibility in array sorted by topic\n const availableSwitchableOutputVisibilityFlags = availableSwitchableOutputs.map((topic) => {\n return messagesForSwitchableOutputs[`${topic.slice(0, -\"/Group\".length)}/ShowUIControl`]\n })\n\n // All switching devices in array sorted by instance number\n const availableSwitchingDevices = Object.keys(messagesForSwitchingDevices)\n .filter((key) => key.endsWith(\"/DeviceInstance\"))\n .sort() as string[]\n // All switching device names in array sorted by instance number\n const availableSwitchingDeviceNames = availableSwitchingDevices.map((topic) => {\n const topicPrefix = topic.slice(0, -\"/DeviceInstance\".length)\n return (\n messagesForSwitchingDevices[`${topicPrefix}/CustomName`] ||\n messagesForSwitchingDevices[`${topicPrefix}/ProductName`]\n )\n })\n\n const dispose = autorun(() => {\n const oldAssignments = switchableOutputsStore.customGroupAssignments\n const newAssignments = customGroupAssigments\n const groupAssignmentsChanged = !arraysEqual(oldAssignments, newAssignments)\n if (groupAssignmentsChanged) {\n switchableOutputsStore.setCustomGroupAssignments(newAssignments)\n Logger.log(`Switchable outputs group assignments changed, recomputing...`)\n }\n\n const oldOutputTypes = switchableOutputsStore.outputTypes\n const newOutputTypes = availableSwitchableOutputTypes\n const outputTypesChanged = !arraysEqual(oldOutputTypes, newOutputTypes)\n if (outputTypesChanged) {\n switchableOutputsStore.setOutputTypes(newOutputTypes)\n Logger.log(`Switchable outputs types changed, recomputing...`)\n }\n\n const oldOutputNames = switchableOutputsStore.outputNames\n const newOutputNames = availableSwitchableOutputNames\n const outputNamesChanged = !arraysEqual(oldOutputNames, newOutputNames)\n if (outputNamesChanged) {\n switchableOutputsStore.setOutputNames(newOutputNames)\n Logger.log(`Switchable outputs names changed, recomputing...`)\n }\n\n const oldOutputVisibilityFlags = switchableOutputsStore.outputVisibilityFlags\n const newOutputVisibilityFlags = availableSwitchableOutputVisibilityFlags\n const outputVisibilityFlagsChanged = !arraysEqual(oldOutputVisibilityFlags, newOutputVisibilityFlags)\n if (outputVisibilityFlagsChanged) {\n switchableOutputsStore.setOutputVisibilityFlags(newOutputVisibilityFlags)\n Logger.log(`Switchable outputs visibility flags changed, recomputing...`)\n }\n\n const oldSwitchingDevices = switchableOutputsStore.switchingDevices\n const newSwitchingDevices = availableSwitchingDevices\n const switchingDevicesChanged = !arraysEqual(oldSwitchingDevices, newSwitchingDevices)\n if (switchingDevicesChanged) {\n switchableOutputsStore.setSwitchingDevices(newSwitchingDevices)\n Logger.log(`Switching devices changed, recomputing...`)\n }\n\n const oldSwitchingDeviceNames = switchableOutputsStore.switchingDeviceNames\n const newSwitchingDeviceNames = availableSwitchingDeviceNames\n const switchingDeviceNamesChanged = !arraysEqual(oldSwitchingDeviceNames, newSwitchingDeviceNames)\n if (switchingDeviceNamesChanged) {\n switchableOutputsStore.setSwitchingDeviceNames(newSwitchingDeviceNames)\n Logger.log(`Switching device names changed, recomputing...`)\n }\n\n if (\n groupAssignmentsChanged ||\n outputTypesChanged ||\n outputNamesChanged ||\n outputVisibilityFlagsChanged ||\n switchingDevicesChanged ||\n switchingDeviceNamesChanged\n ) {\n // New groups mapping array of switches to group name key\n const newGroups: { [key: string]: SwitchableOutputState[] } = {}\n\n // Walk the array of all switchable outputs, determine to which group it belongs\n // and populate its initial state\n availableSwitchableOutputs.forEach((output, index) => {\n const swo = extractSwitchableOutputInfo(output)\n const switchingDevice = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, swo.deviceId))\n const customGroupAssignment = customGroupAssigments[index].trim()\n const groupName =\n customGroupAssignment === \"\"\n ? switchingDevice.customName || switchingDevice.productName\n : customGroupAssignment\n const switchableOutput = mqtt.messagesByTopics(\n getSwitchableOutputStateTopics(mqtt.portalId, swo.deviceId, swo.outputId)\n ) as unknown as SwitchableOutputState\n\n // Ignore hidden controls\n if (switchableOutput.showUIControl === 0) {\n return\n }\n\n newGroups[groupName] ||= []\n newGroups[groupName].push({ ...switchableOutput, deviceId: swo.deviceId, outputId: swo.outputId })\n })\n\n Logger.log(`New switchable output groups: ${JSON.stringify(Object.keys(newGroups))}`)\n // Sort switches in a group by name\n Object.values(newGroups).forEach((array) => {\n array.sort((a, b) => {\n const aName = a.customName || a.name\n const bName = b.customName || b.name\n return aName.localeCompare(bName)\n })\n })\n switchableOutputsStore.setGroups(newGroups)\n }\n })\n return () => dispose()\n }\n }, [messagesForSwitchableOutputs, messagesForSwitchingDevices])\n\n return switchableOutputsStore\n}\n\nfunction extractSwitchableOutputInfo(topic: string) {\n const switchStart = topic.indexOf(\"/switch/\") + 8 // length of `/switch/`\n const outputStart = topic.indexOf(\"/SwitchableOutput/\") + 18 // length of `/SwitchableOutput/`\n\n return {\n deviceId: topic.substring(switchStart, topic.indexOf(\"/\", switchStart)) as unknown as SwitchingDeviceInstanceId,\n outputId: topic.substring(outputStart, topic.indexOf(\"/\", outputStart)) as unknown as SwitchableOutputId,\n }\n}\n\nfunction arraysEqual<T>(a: T[], b: T[]): boolean {\n if (a.length !== b.length) return false\n return a.every((element, index) => b[index] === element)\n}\n"]}
|
|
@@ -6,6 +6,7 @@ export interface SwitchableOutputsState {
|
|
|
6
6
|
};
|
|
7
7
|
customGroupAssignments: string[];
|
|
8
8
|
outputTypes: SwitchableOutputType[];
|
|
9
|
+
outputNames: string[];
|
|
9
10
|
outputVisibilityFlags: (0 | 1)[];
|
|
10
11
|
switchingDevices: string[];
|
|
11
12
|
switchingDeviceNames: string[];
|
|
@@ -16,6 +17,7 @@ export declare class SwitchableOutputsStore {
|
|
|
16
17
|
};
|
|
17
18
|
customGroupAssignments: string[];
|
|
18
19
|
outputTypes: SwitchableOutputType[];
|
|
20
|
+
outputNames: string[];
|
|
19
21
|
outputVisibilityFlags: (0 | 1)[];
|
|
20
22
|
switchingDevices: string[];
|
|
21
23
|
switchingDeviceNames: string[];
|
|
@@ -27,6 +29,7 @@ export declare class SwitchableOutputsStore {
|
|
|
27
29
|
};
|
|
28
30
|
setCustomGroupAssignments: (assignments: string[]) => string[];
|
|
29
31
|
setOutputTypes: (outputTypes: SwitchableOutputType[]) => SwitchableOutputType[];
|
|
32
|
+
setOutputNames: (outputNames: string[]) => string[];
|
|
30
33
|
setOutputVisibilityFlags: (outputVisibilityFlags: (0 | 1)[]) => (0 | 1)[];
|
|
31
34
|
setSwitchingDevices: (switchingDevices: string[]) => string[];
|
|
32
35
|
setSwitchingDeviceNames: (switchingDeviceNames: string[]) => string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchableOutputs.store.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAItD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAAA;KAAE,CAAA;IAElD,sBAAsB,EAAE,MAAM,EAAE,CAAA;IAEhC,WAAW,EAAE,oBAAoB,EAAE,CAAA;IAEnC,qBAAqB,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAA;IAEhC,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAE1B,oBAAoB,EAAE,MAAM,EAAE,CAAA;CAC/B;AAED,qBAAa,sBAAsB;IACjC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAAA;KAAE,C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BAAsB;IACjC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAAA;KAAE,CAAK;IACvD,sBAAsB,EAAE,MAAM,EAAE,CAAK;IACrC,WAAW,EAAE,oBAAoB,EAAE,CAAK;IACxC,WAAW,EAAE,MAAM,EAAE,CAAK;IAC1B,qBAAqB,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAK;IACrC,gBAAgB,EAAE,MAAM,EAAE,CAAK;IAC/B,oBAAoB,EAAE,MAAM,EAAE,CAAK;;IAanC,SAAS,GAAI,QAAQ;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAAA;KAAE;;MAA2B;IAC1F,yBAAyB,GAAI,aAAa,MAAM,EAAE,cAAgD;IAClG,cAAc,GAAI,aAAa,oBAAoB,EAAE,4BAAqC;IAC1F,cAAc,GAAI,aAAa,MAAM,EAAE,cAAqC;IAC5E,wBAAwB,GAAI,uBAAuB,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,eAAyD;IACrH,mBAAmB,GAAI,kBAAkB,MAAM,EAAE,cAA+C;IAChG,uBAAuB,GAAI,sBAAsB,MAAM,EAAE,cAAuD;CACjH;AAYD,wBAAgB,yBAAyB,2BAExC"}
|
|
@@ -22,6 +22,12 @@ var SwitchableOutputsStore = /** @class */ (function () {
|
|
|
22
22
|
writable: true,
|
|
23
23
|
value: []
|
|
24
24
|
});
|
|
25
|
+
Object.defineProperty(this, "outputNames", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: []
|
|
30
|
+
});
|
|
25
31
|
Object.defineProperty(this, "outputVisibilityFlags", {
|
|
26
32
|
enumerable: true,
|
|
27
33
|
configurable: true,
|
|
@@ -58,6 +64,12 @@ var SwitchableOutputsStore = /** @class */ (function () {
|
|
|
58
64
|
writable: true,
|
|
59
65
|
value: function (outputTypes) { return (_this.outputTypes = outputTypes); }
|
|
60
66
|
});
|
|
67
|
+
Object.defineProperty(this, "setOutputNames", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true,
|
|
71
|
+
value: function (outputNames) { return (_this.outputNames = outputNames); }
|
|
72
|
+
});
|
|
61
73
|
Object.defineProperty(this, "setOutputVisibilityFlags", {
|
|
62
74
|
enumerable: true,
|
|
63
75
|
configurable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchableOutputs.store.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAI/B,IAAI,KAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"SwitchableOutputs.store.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAI/B,IAAI,KAA6B,CAAA;AAkBjC;IASE;QAAA,iBASC;QAjBD;;;;mBAAqD,EAAE;WAAA;QACvD;;;;mBAAmC,EAAE;WAAA;QACrC;;;;mBAAsC,EAAE;WAAA;QACxC;;;;mBAAwB,EAAE;WAAA;QAC1B;;;;mBAAmC,EAAE;WAAA;QACrC;;;;mBAA6B,EAAE;WAAA;QAC/B;;;;mBAAiC,EAAE;WAAA;QAanC;;;;mBAAY,UAAC,MAAkD,IAAK,OAAA,CAAC,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC,EAAtB,CAAsB;WAAA;QAC1F;;;;mBAA4B,UAAC,WAAqB,IAAK,OAAA,CAAC,KAAI,CAAC,sBAAsB,GAAG,WAAW,CAAC,EAA3C,CAA2C;WAAA;QA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AutoObservable } from \"mobx\"\nimport { useMemo } from \"react\"\nimport { SwitchableOutputState } from \"./SwitchableOutput.provider\"\nimport { SwitchableOutputType } from \"utils/constants\"\n\nlet store: SwitchableOutputsStore\n\nexport interface SwitchableOutputsState {\n groups: { [key: string]: SwitchableOutputState[] }\n // custom group assignments for available switchable outputs sorted by their topic path\n customGroupAssignments: string[]\n // types of switchable outputs sorted by their topic path\n outputTypes: SwitchableOutputType[]\n // custom names of switchable outputs sorted by their topic path\n outputNames: string[]\n // visibility status of switchable outputs sorted by their topic path\n outputVisibilityFlags: (0 | 1)[]\n // switching devices\n switchingDevices: string[]\n // switching devices custom names\n switchingDeviceNames: string[]\n}\n\nexport class SwitchableOutputsStore {\n groups: { [key: string]: SwitchableOutputState[] } = {}\n customGroupAssignments: string[] = []\n outputTypes: SwitchableOutputType[] = []\n outputNames: string[] = []\n outputVisibilityFlags: (0 | 1)[] = []\n switchingDevices: string[] = []\n switchingDeviceNames: string[] = []\n\n constructor() {\n makeAutoObservable(this, {\n setGroups: action,\n setCustomGroupAssignments: action,\n setOutputTypes: action,\n setOutputVisibilityFlags: action,\n setSwitchingDevices: action,\n setSwitchingDeviceNames: action,\n })\n }\n\n setGroups = (groups: { [key: string]: SwitchableOutputState[] }) => (this.groups = groups)\n setCustomGroupAssignments = (assignments: string[]) => (this.customGroupAssignments = assignments)\n setOutputTypes = (outputTypes: SwitchableOutputType[]) => (this.outputTypes = outputTypes)\n setOutputNames = (outputNames: string[]) => (this.outputNames = outputNames)\n setOutputVisibilityFlags = (outputVisibilityFlags: (0 | 1)[]) => (this.outputVisibilityFlags = outputVisibilityFlags)\n setSwitchingDevices = (switchingDevices: string[]) => (this.switchingDevices = switchingDevices)\n setSwitchingDeviceNames = (switchingDeviceNames: string[]) => (this.switchingDeviceNames = switchingDeviceNames)\n}\n\nfunction initializeStore() {\n const _store = store ?? new SwitchableOutputsStore()\n // For SSG and SSR always create a new store\n if (typeof window === \"undefined\") return _store\n // Create the store once in the client\n if (!store) store = _store\n\n return _store\n}\n\nexport function useSwitchableOutputsStore() {\n return useMemo(() => initializeStore(), [])\n}\n"]}
|