@victronenergy/mfd-modules 9.10.0 → 10.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/dist/src/Modules/Mqtt/Mqtt.store.d.ts +3 -1
- package/dist/src/Modules/Mqtt/Mqtt.store.d.ts.map +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.store.js +1 -1
- package/dist/src/Modules/Mqtt/Mqtt.store.js.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.d.ts +6 -3
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.d.ts.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.js +32 -28
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.js.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.d.ts +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.d.ts.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js +12 -8
- package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.d.ts +2 -2
- package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.d.ts.map +1 -1
- package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.js +6 -6
- package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.js.map +1 -1
- package/dist/src/utils/hsvw.d.ts +1 -0
- package/dist/src/utils/hsvw.d.ts.map +1 -1
- package/dist/src/utils/hsvw.js +9 -0
- package/dist/src/utils/hsvw.js.map +1 -1
- package/package.json +1 -1
|
@@ -92,7 +92,9 @@ export declare class MqttStore {
|
|
|
92
92
|
sendFullKeepalive: () => void;
|
|
93
93
|
setupKeepaliveTimer: () => void;
|
|
94
94
|
clearKeepaliveTimer: () => void;
|
|
95
|
-
publish: (topic: string, data: string | number |
|
|
95
|
+
publish: (topic: string, data: string | number | {
|
|
96
|
+
raw: string;
|
|
97
|
+
}, options?: IClientPublishOptions) => void;
|
|
96
98
|
}
|
|
97
99
|
export declare function useMqtt(): MqttStore;
|
|
98
100
|
//# sourceMappingURL=Mqtt.store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mqtt.store.d.ts","sourceRoot":"/","sources":["src/Modules/Mqtt/Mqtt.store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAU,MAAM,EAAE,MAAM,SAAS,CAAA;AAQ7E,qBAAa,SAAS;IACpB,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAoB;IAClC,QAAQ,EAAE,YAAY,CAAK;IAC3B,YAAY,EAAE,YAAY,CAAK;IAC/B,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAoB;IACjD,QAAQ,EAAE,QAAQ,CAAA;IAClB,QAAQ,EAAE,MAAM,CAA0C;IAC1D,mBAAmB,EAAE,GAAG,CAAA;IACxB,WAAW,EAAE,GAAG,CAAA;IAChB,2BAA2B,EAAE,MAAM,CAAI;IACvC,mBAAmB,EAAE,MAAM,EAAE,CAAK;IAElC;;;;;;;;;;;;;;;;OAgBG;IACH,gBAAgB,WACL,MAAM,iBAMhB;IAED;;;;;;;;;;;;;;;;;;UAkBM;IACN,gBAAgB,YACJ,MAAM;;MAsBjB;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,kBAAkB,cACJ,MAAM,SAsBnB;;IAmBD,IAAI,WAAW,YAEd;IAED,gBAAgB,GAAI,QAAQ,MAAM,UAmBjC;IAED,qBAAqB;IAMrB,UAAU,GAAI,OAAO,MAAM,EAAE,SAA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
484
|
Logger.log("Could not publish value, not connected to MQTT broker");
|
|
485
485
|
}
|
|
486
|
-
var message = JSON.stringify({ value: data });
|
|
486
|
+
var message = typeof data === "object" && data !== null && "raw" in data ? data.raw : JSON.stringify({ value: data });
|
|
487
487
|
Logger.log("Publishing to ".concat(topic, ": ").concat(message));
|
|
488
488
|
(_a = _this.client) === null || _a === void 0 ? void 0 : _a.publish(topic, message, options !== null && options !== void 0 ? options : {});
|
|
489
489
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mqtt.store.js","sourceRoot":"/","sources":["src/Modules/Mqtt/Mqtt.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAuC,MAAM,EAAU,MAAM,SAAS,CAAA;AAC7E,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAElC,IAAI,KAAgB,CAAA;AAEpB;IA+HE;QAAA,iBAeC;QA7ID;;;;;WAA0B;QAC1B;;;;;WAA+B;QAC/B;;;;mBAAiB,MAAM,CAAC,UAAU;WAAA;QAClC;;;;mBAAyB,EAAE;WAAA;QAC3B;;;;mBAA6B,EAAE;WAAA;QAC/B;;;;mBAAgC,IAAI,GAAG,EAAU;WAAA;QACjD;;;;;WAAkB;QAClB;;;;mBAAmB,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;WAAA;QAC1D;;;;;WAAwB;QACxB;;;;;WAAgB;QAChB;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AAC,QAAQ,GAAG,SAAS,CAAA;YACzB,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAA;QAC/B,CAAC;;;;;;eAuDD,UAAU,MAAc;YACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACtB,CAAC;;;;;;eAED,UAAS,KAA8B;YACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QACpB,CAAC;;IA4LH,gBAAC;AAAD,CAAC,AAtaD,IAsaC;;AAED;;;;;;;;;;GAUG;AACH,SAAS,SAAS,CAAC,IAAY,EAAE,CAAS,EAAE,QAAgB;IAC1D,OAAO,IAAI,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED,SAAS,eAAe;IACtB,IAAM,MAAM,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,SAAS,EAAE,CAAA;IACvC,4CAA4C;IAC5C,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,MAAM,CAAA;IAChD,sCAAsC;IACtC,IAAI,CAAC,KAAK;QAAE,KAAK,GAAG,MAAM,CAAA;IAE1B,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,OAAO;IACrB,OAAO,OAAO,CAAC,cAAM,OAAA,eAAe,EAAE,EAAjB,CAAiB,EAAE,EAAE,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import { comparer, makeAutoObservable, runInAction } from \"mobx\"\nimport { computedFn } from \"mobx-utils\"\nimport * as mqtt from \"mqtt\"\nimport { IClientPublishOptions, MqttClient } from \"mqtt\"\nimport { MqttMessage, MqttMessages, PortalId, STATUS, Topics } from \"../Mqtt\"\nimport Logger from \"../../utils/logger\"\nimport { getMessageJson } from \"../../utils/util\"\nimport { useMemo } from \"react\"\nimport { assign } from \"lodash-es\"\n\nlet store: MqttStore\n\nexport class MqttStore {\n client?: MqttClient | null\n error?: object | null | boolean\n status: string = STATUS.CONNECTING\n messages: MqttMessages = {}\n messageQueue: MqttMessages = {}\n topicsSubscribed: Set<string> = new Set<string>()\n portalId: PortalId\n uniqueId: string = Math.random().toString(16).substr(2, 8)\n keepAliveHandlerRef: any\n queueWorker: any\n meanQueueWorkerPassDuration: number = 0\n urgentTopicPrefixes: string[] = []\n\n /**\n * Returns the current cached message for a given MQTT topic.\n *\n * React Components using this method will re-render when their specific\n * topic's message changes.\n *\n * Using comparer.identity will trigger the re-renders any time\n * a message arrives for the given topic. We rely on the fact\n * that MQTT will only re-send a message when the value changes,\n * or on a full keep alive.\n *\n * Note: Receiving the same message for a given topic will cause re-renders,\n * as we do not check structural identity of the message.\n *\n * @param topic - The MQTT topic to retrieve the message for\n * @returns The message object for the topic, or undefined if topic is not provided or not found\n */\n messageFromTopic = computedFn(\n (topic?: string) => {\n // Logger.log(`DEBUG: messageFromTopic: ${JSON.stringify(topic)}`)\n // trace()\n return topic ? this.messages[topic] : undefined\n },\n { name: \"Mqtt.store.messageFromTopic\", equals: comparer.identity }\n )\n\n /**\n * Returns the current cached messages for a given set of MQTT topics.\n *\n * This is a memoized computed function - each set of topics has its own cached value.\n *\n * React Components using this method will re-render when\n * any of the messages for specified topics change.\n *\n * Using comparer.identity will trigger the re-renders any time\n * a message arrives for any of the specified topics. We rely on the fact\n * that MQTT will only re-send a message when the value changes,\n * or on a full keep alive.\n\n * Note: Receiving the same message for a given topic will cause re-renders,\n * as we do not check structural identity of the message.\n *\n * @param topics - The MQTT topics to retrieve the messages for\n * @returns The messages objects for the given topics, or empty dictionary if topics not found\n */\n messagesByTopics = computedFn(\n (topics?: Topics) => {\n // Logger.log(`DEBUG: messagesByTopics: ${JSON.stringify(topics)}`)\n // trace()\n if (!topics) {\n return {}\n }\n\n const result: { [key: string]: MqttMessage | MqttMessage[] } = {}\n\n Object.entries(topics).forEach(([label, topic]) => {\n if (Array.isArray(topic)) {\n result[label] = topic.map((t) => this.messageFromTopic(t))\n } else if (topic === undefined) {\n result[label] = undefined\n } else {\n result[label] = this.messageFromTopic(topic)\n }\n })\n\n return result\n },\n { name: \"Mqtt.store.messagesByTopics\", equals: comparer.identity }\n )\n\n /**\n * Returns the current cached messages for MQTT topics specified via regex.\n *\n * React Components using this method will re-render when\n * values of any of the matched topics change. The components also re-render\n * when new MQTT topics are received and match needs to be checked.\n *\n * Using comparer.identity will trigger the re-renders any time\n * a message arrives for any of the matched topics. We rely on the fact\n * that MQTT will only re-send a message when the value changes,\n * or on a full keep alive.\n *\n * Note: Receiving the same message for a given topic will cause re-renders,\n * as we do not check structural identity of the message.\n *\n * @param wildcard - The MQTT wildcard to retrieve the message for\n * @returns The messages objects for the given topics, or empty dictionary if topics not found\n */\n messagesByWildcard = computedFn(\n (wildcard?: string) => {\n // Logger.log(`DEBUG: messagesByWildcard: ${JSON.stringify(wildcard)}`)\n // trace()\n if (wildcard === undefined || wildcard === \"\" || wildcard === null) return {}\n\n const topicRegex = new RegExp(wildcard.replace(/\\+/g, \"\\\\w*\")) // + in mqtt is anything -> .*\n\n return Object.fromEntries(\n Object.keys(this.messages)\n .filter((topic) => topic.match(topicRegex))\n .map((topic) => [topic, this.messages[topic]])\n // Filter out empty results\n .filter(\n ([_, message]) =>\n message !== undefined &&\n message !== null &&\n (!Array.isArray(message) ||\n (message.length !== 0 && !message.every((v) => v === undefined || v === null)))\n )\n )\n },\n { name: \"Mqtt.store.messagesByWildcard\", equals: comparer.identity }\n )\n\n constructor() {\n makeAutoObservable(this, {\n messageQueue: false,\n urgentTopicPrefixes: false,\n setupKeepaliveTimer: false,\n clearKeepaliveTimer: false,\n sendFullKeepalive: false,\n sendSuppressedKeepalive: false,\n setupQueueWorker: false,\n removeQueueWorker: false,\n scheduleNextQueueWorkerPass: false,\n subscribeToTopic: false,\n subscribeToAllTopics: false,\n clearSubscribedTopics: false,\n })\n }\n\n get isConnected() {\n return this.status === STATUS.CONNECTED\n }\n\n subscribeToTopic = (topic?: string) => {\n if (!topic) return\n if (topic.includes(\"undefined\")) return\n\n if (!this.topicsSubscribed.has(topic)) {\n Logger.log(`Subscribing to ${topic}`)\n this.client?.subscribe(topic, (err, granted) => {\n if (err) {\n Logger.error(err)\n return\n }\n\n granted !== undefined && granted[0]\n ? Logger.log(`Subscribed to ${granted[0].topic} with Qos ${granted[0].qos}`)\n : Logger.log(`Subscribed to ${topic} with Qos unknown`)\n })\n\n this.topicsSubscribed.add(topic)\n }\n }\n\n clearSubscribedTopics() {\n this.topicsSubscribed.clear()\n this.portalId = undefined\n this.urgentTopicPrefixes = []\n }\n\n addMessage = (topic: string, message: { value: string | null }) => {\n // Logger.log(`DEBUG: addMessage: topic: ${topic}, urgentPrefixes: ${JSON.stringify(this.urgentTopicPrefixes)}`)\n if (this.urgentTopicPrefixes.some((prefix) => topic.startsWith(prefix))) {\n // NOTE: If topic starts with one of the urgent prefixes, deliver it immediately\n this.messages[topic] = message.value ?? undefined\n } else {\n // NOTE: Otherwise store message to the queue, and move messages from the queue\n // NOTE: to the React components that are MobX observers periodically and in batches\n this.messageQueue[topic] = message.value ?? undefined\n }\n }\n\n addMessagesFromQueue = () => {\n if (Object.values(this.messageQueue).length > 0) {\n // Logger.log(`DEBUG: addMessagesFromQueue: in queue: ${JSON.stringify(Object.values(this.messageQueue).length)}`)\n assign(this.messages, this.messageQueue)\n // Logger.log(`DEBUG: addMessagesFromQueue: to process: ${JSON.stringify(Object.values(this.messages).length)}`)\n this.messageQueue = {}\n }\n }\n\n scheduleNextQueueWorkerPass = (timeout: number) => {\n this.queueWorker = setTimeout(() => {\n const started = performance.now()\n this.addMessagesFromQueue()\n const ended = performance.now()\n this.meanQueueWorkerPassDuration = addToMean(this.meanQueueWorkerPassDuration, 10, ended - started)\n // Schedule next update after 1 - 3 seconds\n // depending on how fast we were able to process the incoming messages\n const newTimeout = Math.max(1000, Math.min(this.meanQueueWorkerPassDuration * 50, 3000))\n this.scheduleNextQueueWorkerPass(newTimeout)\n }, timeout)\n }\n\n setupQueueWorker = () => {\n this.removeQueueWorker()\n\n this.meanQueueWorkerPassDuration = 20 // ms\n this.scheduleNextQueueWorkerPass(1000) // ms\n }\n\n removeQueueWorker = () => {\n if (this.queueWorker) {\n clearInterval(this.queueWorker)\n }\n this.queueWorker = undefined\n }\n\n setPortalId = (portalId: string) => {\n this.portalId = portalId\n this.urgentTopicPrefixes = [`N/${portalId}/switch/`]\n }\n\n setStatus(status: string) {\n this.status = status\n }\n\n setError(error: object | null | boolean) {\n this.error = error\n }\n\n boot = (\n protocol: string,\n host: string = \"localhost\",\n port: number | null,\n path: string = \"websocket-mqtt\",\n remote: boolean = false,\n portalId?: string\n ) => {\n Logger.log(\"MQTT booting\")\n\n let client = this.client\n\n if (client) {\n client.end(true)\n this.client = undefined\n this.portalId = undefined\n this.topicsSubscribed = new Set<string>()\n this.urgentTopicPrefixes = []\n }\n\n let url\n if (remote) {\n if (!host) {\n return\n }\n // remote connection to VRM broker always uses MQTTS over 443\n url = `mqtts://${host}:443`\n } else {\n // local connection derives websocket protocol from web app protocol\n const wsproto = protocol === \"https:\" ? \"wss:\" : \"ws:\"\n if (port) {\n url = `${wsproto}//${host}:${port}/${path}`\n } else {\n url = `${wsproto}//${host}/${path}`\n }\n }\n\n Logger.log(`MQTT connecting to ${url}`)\n client = mqtt.connect(url, { resubscribe: false })\n\n this.client = client\n this.portalId = portalId\n\n client.on(\"error\", (error) => {\n Logger.log(\"MQTT error\")\n runInAction(() => {\n this.setError(error)\n this.setStatus(STATUS.DISCONNECTED)\n })\n this.removeQueueWorker()\n this.clearKeepaliveTimer()\n this.clearSubscribedTopics()\n })\n\n client.on(\"offline\", () => {\n Logger.log(\"MQTT offline\")\n runInAction(() => {\n this.setError(true)\n this.setStatus(STATUS.OFFLINE)\n })\n this.removeQueueWorker()\n this.clearKeepaliveTimer()\n this.clearSubscribedTopics()\n })\n\n client.on(\"connect\", () => {\n Logger.log(\"MQTT connected\")\n runInAction(() => {\n this.setError(null)\n this.setStatus(STATUS.CONNECTED)\n // Never use wildcard when connecting remotely\n this.subscribeToTopic(`N/${remote ? portalId : \"+\"}/system/0/Serial`)\n this.setupKeepaliveTimer()\n })\n })\n\n client.on(\"message\", (topic, message) => {\n // Logger.log(`DEBUG: Message received: ${topic} - ${message.toString()}`)\n\n if (topic.endsWith(\"/system/0/Serial\") && !this.portalId) {\n const portalId = getMessageJson(message).value\n\n if (this.portalId !== portalId && portalId !== undefined) {\n this.setPortalId(portalId)\n }\n\n runInAction(() => this.subscribeToAllTopics())\n }\n if (topic.endsWith(\"full_publish_completed\")) {\n const uniqueId = getMessageJson(message)[\"full-publish-completed-echo\"] || \"\"\n Logger.log(\n `Received full_publish_completed for ${this.portalId} with full-publish-completed-echo: '${uniqueId}'`\n )\n if (uniqueId === this.uniqueId) {\n this.addMessagesFromQueue()\n this.setupQueueWorker()\n }\n }\n\n if (message.toString() !== \"\") {\n this.addMessage(topic, getMessageJson(message))\n }\n })\n\n Logger.log(\"MQTT booted\")\n }\n\n subscribeToAllTopics = () => {\n const topics = [\n `N/${this.portalId}/settings/#`,\n `N/${this.portalId}/system/#`,\n `N/${this.portalId}/vebus/#`,\n `N/${this.portalId}/alternator/#`,\n `N/${this.portalId}/battery/#`,\n `N/${this.portalId}/charger/#`,\n `N/${this.portalId}/dcsource/#`,\n `N/${this.portalId}/generator/#`,\n `N/${this.portalId}/genset/#`,\n `N/${this.portalId}/dcgenset/#`,\n `N/${this.portalId}/inverter/#`,\n `N/${this.portalId}/tank/#`,\n `N/${this.portalId}/temperature/#`,\n `N/${this.portalId}/switch/#`,\n `N/${this.portalId}/full_publish_completed`,\n ]\n\n this.client?.subscribe(topics, (err) => {\n if (err) {\n Logger.error(err)\n return\n }\n\n // When we received all topics we send a full keepalive.\n this.sendFullKeepalive()\n })\n }\n\n sendSuppressedKeepalive = () => {\n if (this.portalId) {\n const options = JSON.stringify({ \"keepalive-options\": [\"suppress-republish\"] })\n const topic = `R/${this.portalId}/keepalive`\n\n Logger.log(`Sending keepalive for ${this.portalId} with ${options}`)\n this.client?.publish(topic, options)\n }\n }\n\n sendFullKeepalive = () => {\n if (this.portalId) {\n const topic = `R/${this.portalId}/keepalive`\n\n Logger.log(`Sending first keepalive for ${this.portalId} with full-publish-completed-echo: '${this.uniqueId}'`)\n this.client &&\n this.client?.publish(\n topic,\n `{ \"keepalive-options\" : [ {\"full-publish-completed-echo\": \"${this.uniqueId}\" } ] }`\n )\n }\n }\n\n setupKeepaliveTimer = () => {\n this.clearKeepaliveTimer()\n\n this.keepAliveHandlerRef = setInterval(this.sendSuppressedKeepalive, 30000)\n\n this.sendFullKeepalive()\n }\n\n clearKeepaliveTimer = () => {\n const ref = this.keepAliveHandlerRef\n if (ref) {\n clearInterval(ref)\n }\n this.keepAliveHandlerRef = undefined\n }\n\n publish = (topic: string, data: string | number | number[], options?: IClientPublishOptions) => {\n if (this.status !== STATUS.CONNECTED || !this.client) {\n Logger.log(\"Could not publish value, not connected to MQTT broker\")\n }\n const message = JSON.stringify({ value: data })\n\n Logger.log(`Publishing to ${topic}: ${message}`)\n\n this.client?.publish(topic, message, options ?? {})\n }\n}\n\n/**\n * Compute mean by providing existing mean, number of samples, and new sample.\n *\n * @param {number} mean current mean\n * @param {number} n number of sampled values\n * @param {number} newValue the sample\n * @returns {number} the new mean\n *\n * @example\n * addToMean(14, 5, 53); // => 20.5\n */\nfunction addToMean(mean: number, n: number, newValue: number): number {\n return mean + (newValue - mean) / (n + 1)\n}\n\nfunction initializeStore() {\n const _store = store ?? new 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 useMqtt() {\n return useMemo(() => initializeStore(), [])\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Mqtt.store.js","sourceRoot":"/","sources":["src/Modules/Mqtt/Mqtt.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,Y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AAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED,SAAS,eAAe;IACtB,IAAM,MAAM,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,SAAS,EAAE,CAAA;IACvC,4CAA4C;IAC5C,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,MAAM,CAAA;IAChD,sCAAsC;IACtC,IAAI,CAAC,KAAK;QAAE,KAAK,GAAG,MAAM,CAAA;IAE1B,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,OAAO;IACrB,OAAO,OAAO,CAAC,cAAM,OAAA,eAAe,EAAE,EAAjB,CAAiB,EAAE,EAAE,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import { comparer, makeAutoObservable, runInAction } from \"mobx\"\nimport { computedFn } from \"mobx-utils\"\nimport * as mqtt from \"mqtt\"\nimport { IClientPublishOptions, MqttClient } from \"mqtt\"\nimport { MqttMessage, MqttMessages, PortalId, STATUS, Topics } from \"../Mqtt\"\nimport Logger from \"../../utils/logger\"\nimport { getMessageJson } from \"../../utils/util\"\nimport { useMemo } from \"react\"\nimport { assign } from \"lodash-es\"\n\nlet store: MqttStore\n\nexport class MqttStore {\n client?: MqttClient | null\n error?: object | null | boolean\n status: string = STATUS.CONNECTING\n messages: MqttMessages = {}\n messageQueue: MqttMessages = {}\n topicsSubscribed: Set<string> = new Set<string>()\n portalId: PortalId\n uniqueId: string = Math.random().toString(16).substr(2, 8)\n keepAliveHandlerRef: any\n queueWorker: any\n meanQueueWorkerPassDuration: number = 0\n urgentTopicPrefixes: string[] = []\n\n /**\n * Returns the current cached message for a given MQTT topic.\n *\n * React Components using this method will re-render when their specific\n * topic's message changes.\n *\n * Using comparer.identity will trigger the re-renders any time\n * a message arrives for the given topic. We rely on the fact\n * that MQTT will only re-send a message when the value changes,\n * or on a full keep alive.\n *\n * Note: Receiving the same message for a given topic will cause re-renders,\n * as we do not check structural identity of the message.\n *\n * @param topic - The MQTT topic to retrieve the message for\n * @returns The message object for the topic, or undefined if topic is not provided or not found\n */\n messageFromTopic = computedFn(\n (topic?: string) => {\n // Logger.log(`DEBUG: messageFromTopic: ${JSON.stringify(topic)}`)\n // trace()\n return topic ? this.messages[topic] : undefined\n },\n { name: \"Mqtt.store.messageFromTopic\", equals: comparer.identity }\n )\n\n /**\n * Returns the current cached messages for a given set of MQTT topics.\n *\n * This is a memoized computed function - each set of topics has its own cached value.\n *\n * React Components using this method will re-render when\n * any of the messages for specified topics change.\n *\n * Using comparer.identity will trigger the re-renders any time\n * a message arrives for any of the specified topics. We rely on the fact\n * that MQTT will only re-send a message when the value changes,\n * or on a full keep alive.\n\n * Note: Receiving the same message for a given topic will cause re-renders,\n * as we do not check structural identity of the message.\n *\n * @param topics - The MQTT topics to retrieve the messages for\n * @returns The messages objects for the given topics, or empty dictionary if topics not found\n */\n messagesByTopics = computedFn(\n (topics?: Topics) => {\n // Logger.log(`DEBUG: messagesByTopics: ${JSON.stringify(topics)}`)\n // trace()\n if (!topics) {\n return {}\n }\n\n const result: { [key: string]: MqttMessage | MqttMessage[] } = {}\n\n Object.entries(topics).forEach(([label, topic]) => {\n if (Array.isArray(topic)) {\n result[label] = topic.map((t) => this.messageFromTopic(t))\n } else if (topic === undefined) {\n result[label] = undefined\n } else {\n result[label] = this.messageFromTopic(topic)\n }\n })\n\n return result\n },\n { name: \"Mqtt.store.messagesByTopics\", equals: comparer.identity }\n )\n\n /**\n * Returns the current cached messages for MQTT topics specified via regex.\n *\n * React Components using this method will re-render when\n * values of any of the matched topics change. The components also re-render\n * when new MQTT topics are received and match needs to be checked.\n *\n * Using comparer.identity will trigger the re-renders any time\n * a message arrives for any of the matched topics. We rely on the fact\n * that MQTT will only re-send a message when the value changes,\n * or on a full keep alive.\n *\n * Note: Receiving the same message for a given topic will cause re-renders,\n * as we do not check structural identity of the message.\n *\n * @param wildcard - The MQTT wildcard to retrieve the message for\n * @returns The messages objects for the given topics, or empty dictionary if topics not found\n */\n messagesByWildcard = computedFn(\n (wildcard?: string) => {\n // Logger.log(`DEBUG: messagesByWildcard: ${JSON.stringify(wildcard)}`)\n // trace()\n if (wildcard === undefined || wildcard === \"\" || wildcard === null) return {}\n\n const topicRegex = new RegExp(wildcard.replace(/\\+/g, \"\\\\w*\")) // + in mqtt is anything -> .*\n\n return Object.fromEntries(\n Object.keys(this.messages)\n .filter((topic) => topic.match(topicRegex))\n .map((topic) => [topic, this.messages[topic]])\n // Filter out empty results\n .filter(\n ([_, message]) =>\n message !== undefined &&\n message !== null &&\n (!Array.isArray(message) ||\n (message.length !== 0 && !message.every((v) => v === undefined || v === null)))\n )\n )\n },\n { name: \"Mqtt.store.messagesByWildcard\", equals: comparer.identity }\n )\n\n constructor() {\n makeAutoObservable(this, {\n messageQueue: false,\n urgentTopicPrefixes: false,\n setupKeepaliveTimer: false,\n clearKeepaliveTimer: false,\n sendFullKeepalive: false,\n sendSuppressedKeepalive: false,\n setupQueueWorker: false,\n removeQueueWorker: false,\n scheduleNextQueueWorkerPass: false,\n subscribeToTopic: false,\n subscribeToAllTopics: false,\n clearSubscribedTopics: false,\n })\n }\n\n get isConnected() {\n return this.status === STATUS.CONNECTED\n }\n\n subscribeToTopic = (topic?: string) => {\n if (!topic) return\n if (topic.includes(\"undefined\")) return\n\n if (!this.topicsSubscribed.has(topic)) {\n Logger.log(`Subscribing to ${topic}`)\n this.client?.subscribe(topic, (err, granted) => {\n if (err) {\n Logger.error(err)\n return\n }\n\n granted !== undefined && granted[0]\n ? Logger.log(`Subscribed to ${granted[0].topic} with Qos ${granted[0].qos}`)\n : Logger.log(`Subscribed to ${topic} with Qos unknown`)\n })\n\n this.topicsSubscribed.add(topic)\n }\n }\n\n clearSubscribedTopics() {\n this.topicsSubscribed.clear()\n this.portalId = undefined\n this.urgentTopicPrefixes = []\n }\n\n addMessage = (topic: string, message: { value: string | null }) => {\n // Logger.log(`DEBUG: addMessage: topic: ${topic}, urgentPrefixes: ${JSON.stringify(this.urgentTopicPrefixes)}`)\n if (this.urgentTopicPrefixes.some((prefix) => topic.startsWith(prefix))) {\n // NOTE: If topic starts with one of the urgent prefixes, deliver it immediately\n this.messages[topic] = message.value ?? undefined\n } else {\n // NOTE: Otherwise store message to the queue, and move messages from the queue\n // NOTE: to the React components that are MobX observers periodically and in batches\n this.messageQueue[topic] = message.value ?? undefined\n }\n }\n\n addMessagesFromQueue = () => {\n if (Object.values(this.messageQueue).length > 0) {\n // Logger.log(`DEBUG: addMessagesFromQueue: in queue: ${JSON.stringify(Object.values(this.messageQueue).length)}`)\n assign(this.messages, this.messageQueue)\n // Logger.log(`DEBUG: addMessagesFromQueue: to process: ${JSON.stringify(Object.values(this.messages).length)}`)\n this.messageQueue = {}\n }\n }\n\n scheduleNextQueueWorkerPass = (timeout: number) => {\n this.queueWorker = setTimeout(() => {\n const started = performance.now()\n this.addMessagesFromQueue()\n const ended = performance.now()\n this.meanQueueWorkerPassDuration = addToMean(this.meanQueueWorkerPassDuration, 10, ended - started)\n // Schedule next update after 1 - 3 seconds\n // depending on how fast we were able to process the incoming messages\n const newTimeout = Math.max(1000, Math.min(this.meanQueueWorkerPassDuration * 50, 3000))\n this.scheduleNextQueueWorkerPass(newTimeout)\n }, timeout)\n }\n\n setupQueueWorker = () => {\n this.removeQueueWorker()\n\n this.meanQueueWorkerPassDuration = 20 // ms\n this.scheduleNextQueueWorkerPass(1000) // ms\n }\n\n removeQueueWorker = () => {\n if (this.queueWorker) {\n clearInterval(this.queueWorker)\n }\n this.queueWorker = undefined\n }\n\n setPortalId = (portalId: string) => {\n this.portalId = portalId\n this.urgentTopicPrefixes = [`N/${portalId}/switch/`]\n }\n\n setStatus(status: string) {\n this.status = status\n }\n\n setError(error: object | null | boolean) {\n this.error = error\n }\n\n boot = (\n protocol: string,\n host: string = \"localhost\",\n port: number | null,\n path: string = \"websocket-mqtt\",\n remote: boolean = false,\n portalId?: string\n ) => {\n Logger.log(\"MQTT booting\")\n\n let client = this.client\n\n if (client) {\n client.end(true)\n this.client = undefined\n this.portalId = undefined\n this.topicsSubscribed = new Set<string>()\n this.urgentTopicPrefixes = []\n }\n\n let url\n if (remote) {\n if (!host) {\n return\n }\n // remote connection to VRM broker always uses MQTTS over 443\n url = `mqtts://${host}:443`\n } else {\n // local connection derives websocket protocol from web app protocol\n const wsproto = protocol === \"https:\" ? \"wss:\" : \"ws:\"\n if (port) {\n url = `${wsproto}//${host}:${port}/${path}`\n } else {\n url = `${wsproto}//${host}/${path}`\n }\n }\n\n Logger.log(`MQTT connecting to ${url}`)\n client = mqtt.connect(url, { resubscribe: false })\n\n this.client = client\n this.portalId = portalId\n\n client.on(\"error\", (error) => {\n Logger.log(\"MQTT error\")\n runInAction(() => {\n this.setError(error)\n this.setStatus(STATUS.DISCONNECTED)\n })\n this.removeQueueWorker()\n this.clearKeepaliveTimer()\n this.clearSubscribedTopics()\n })\n\n client.on(\"offline\", () => {\n Logger.log(\"MQTT offline\")\n runInAction(() => {\n this.setError(true)\n this.setStatus(STATUS.OFFLINE)\n })\n this.removeQueueWorker()\n this.clearKeepaliveTimer()\n this.clearSubscribedTopics()\n })\n\n client.on(\"connect\", () => {\n Logger.log(\"MQTT connected\")\n runInAction(() => {\n this.setError(null)\n this.setStatus(STATUS.CONNECTED)\n // Never use wildcard when connecting remotely\n this.subscribeToTopic(`N/${remote ? portalId : \"+\"}/system/0/Serial`)\n this.setupKeepaliveTimer()\n })\n })\n\n client.on(\"message\", (topic, message) => {\n // Logger.log(`DEBUG: Message received: ${topic} - ${message.toString()}`)\n\n if (topic.endsWith(\"/system/0/Serial\") && !this.portalId) {\n const portalId = getMessageJson(message).value\n\n if (this.portalId !== portalId && portalId !== undefined) {\n this.setPortalId(portalId)\n }\n\n runInAction(() => this.subscribeToAllTopics())\n }\n if (topic.endsWith(\"full_publish_completed\")) {\n const uniqueId = getMessageJson(message)[\"full-publish-completed-echo\"] || \"\"\n Logger.log(\n `Received full_publish_completed for ${this.portalId} with full-publish-completed-echo: '${uniqueId}'`\n )\n if (uniqueId === this.uniqueId) {\n this.addMessagesFromQueue()\n this.setupQueueWorker()\n }\n }\n\n if (message.toString() !== \"\") {\n this.addMessage(topic, getMessageJson(message))\n }\n })\n\n Logger.log(\"MQTT booted\")\n }\n\n subscribeToAllTopics = () => {\n const topics = [\n `N/${this.portalId}/settings/#`,\n `N/${this.portalId}/system/#`,\n `N/${this.portalId}/vebus/#`,\n `N/${this.portalId}/alternator/#`,\n `N/${this.portalId}/battery/#`,\n `N/${this.portalId}/charger/#`,\n `N/${this.portalId}/dcsource/#`,\n `N/${this.portalId}/generator/#`,\n `N/${this.portalId}/genset/#`,\n `N/${this.portalId}/dcgenset/#`,\n `N/${this.portalId}/inverter/#`,\n `N/${this.portalId}/tank/#`,\n `N/${this.portalId}/temperature/#`,\n `N/${this.portalId}/switch/#`,\n `N/${this.portalId}/full_publish_completed`,\n ]\n\n this.client?.subscribe(topics, (err) => {\n if (err) {\n Logger.error(err)\n return\n }\n\n // When we received all topics we send a full keepalive.\n this.sendFullKeepalive()\n })\n }\n\n sendSuppressedKeepalive = () => {\n if (this.portalId) {\n const options = JSON.stringify({ \"keepalive-options\": [\"suppress-republish\"] })\n const topic = `R/${this.portalId}/keepalive`\n\n Logger.log(`Sending keepalive for ${this.portalId} with ${options}`)\n this.client?.publish(topic, options)\n }\n }\n\n sendFullKeepalive = () => {\n if (this.portalId) {\n const topic = `R/${this.portalId}/keepalive`\n\n Logger.log(`Sending first keepalive for ${this.portalId} with full-publish-completed-echo: '${this.uniqueId}'`)\n this.client &&\n this.client?.publish(\n topic,\n `{ \"keepalive-options\" : [ {\"full-publish-completed-echo\": \"${this.uniqueId}\" } ] }`\n )\n }\n }\n\n setupKeepaliveTimer = () => {\n this.clearKeepaliveTimer()\n\n this.keepAliveHandlerRef = setInterval(this.sendSuppressedKeepalive, 30000)\n\n this.sendFullKeepalive()\n }\n\n clearKeepaliveTimer = () => {\n const ref = this.keepAliveHandlerRef\n if (ref) {\n clearInterval(ref)\n }\n this.keepAliveHandlerRef = undefined\n }\n\n publish = (topic: string, data: string | number | { raw: string }, options?: IClientPublishOptions) => {\n if (this.status !== STATUS.CONNECTED || !this.client) {\n Logger.log(\"Could not publish value, not connected to MQTT broker\")\n }\n const message =\n typeof data === \"object\" && data !== null && \"raw\" in data ? data.raw : JSON.stringify({ value: data })\n\n Logger.log(`Publishing to ${topic}: ${message}`)\n\n this.client?.publish(topic, message, options ?? {})\n }\n}\n\n/**\n * Compute mean by providing existing mean, number of samples, and new sample.\n *\n * @param {number} mean current mean\n * @param {number} n number of sampled values\n * @param {number} newValue the sample\n * @returns {number} the new mean\n *\n * @example\n * addToMean(14, 5, 53); // => 20.5\n */\nfunction addToMean(mean: number, n: number, newValue: number): number {\n return mean + (newValue - mean) / (n + 1)\n}\n\nfunction initializeStore() {\n const _store = store ?? new 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 useMqtt() {\n return useMemo(() => initializeStore(), [])\n}\n"]}
|
|
@@ -2,9 +2,12 @@ import { PortalId, Topics } from "../Mqtt";
|
|
|
2
2
|
import { SwitchingDeviceInstanceId } from "./SwitchingDevice.provider";
|
|
3
3
|
import { SwitchableOutputStatus, SwitchableOutputType } from "../../utils/constants";
|
|
4
4
|
import { HSVWColorArray } from "../../utils/hsvw";
|
|
5
|
+
export declare const SWITCHABLE_OUTPUT_TREES: readonly ["system", "switch"];
|
|
6
|
+
export type SwitchableOutputTree = (typeof SWITCHABLE_OUTPUT_TREES)[number];
|
|
5
7
|
export type SwitchableOutputId = string;
|
|
6
8
|
export type SwitchableOutputUnit = string | "/Speed" | "/Temperature" | "/Volume";
|
|
7
9
|
export interface SwitchableOutputState {
|
|
10
|
+
tree: SwitchableOutputTree;
|
|
8
11
|
deviceId: SwitchingDeviceInstanceId;
|
|
9
12
|
outputId: SwitchableOutputId;
|
|
10
13
|
type: SwitchableOutputType;
|
|
@@ -50,7 +53,7 @@ export interface SwitchableOutputTopics extends Topics {
|
|
|
50
53
|
labels?: string[];
|
|
51
54
|
}
|
|
52
55
|
export declare const getSwitchableOutputNameForDisplay: (state: SwitchableOutputState, switchingDeviceName: string) => string;
|
|
53
|
-
export declare const getSwitchableOutputStateTopics: (portalId: PortalId, deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId) => {
|
|
56
|
+
export declare const getSwitchableOutputStateTopics: (portalId: PortalId, tree: SwitchableOutputTree, deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId) => {
|
|
54
57
|
type: string;
|
|
55
58
|
status: string;
|
|
56
59
|
name: string;
|
|
@@ -69,11 +72,11 @@ export declare const getSwitchableOutputStateTopics: (portalId: PortalId, device
|
|
|
69
72
|
labels: string;
|
|
70
73
|
lightControls: string;
|
|
71
74
|
};
|
|
72
|
-
export declare const getSwitchableOutputWriteTopics: (portalId: PortalId, deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId) => {
|
|
75
|
+
export declare const getSwitchableOutputWriteTopics: (portalId: PortalId, tree: SwitchableOutputTree, deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId) => {
|
|
73
76
|
auto: string;
|
|
74
77
|
state: string;
|
|
75
78
|
dimming: string;
|
|
76
79
|
lightControls: string;
|
|
77
80
|
};
|
|
78
|
-
export declare function useSwitchableOutput(deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId): SwitchableOutputProvider;
|
|
81
|
+
export declare function useSwitchableOutput(tree: SwitchableOutputTree, deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId): SwitchableOutputProvider;
|
|
79
82
|
//# sourceMappingURL=SwitchableOutput.provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchableOutput.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutput.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE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AAO,qBAAqB,EAAE,qBAAqB,MAAM,WAO1G,CAAA;AAED,eAAO,MAAM,8BAA8B,GACzC,UAAU,QAAQ,EAClB,MAAM,oBAAoB,EAC1B,UAAU,yBAAyB,EACnC,UAAU,kBAAkB;;;;;;;;;;;;;;;;;;CAmB5B,CAAA;AAEF,eAAO,MAAM,8BAA8B,GACzC,UAAU,QAAQ,EAClB,MAAM,oBAAoB,EAC1B,UAAU,yBAAyB,EACnC,UAAU,kBAAkB;;;;;CAM5B,CAAA;AAEF,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,EAAE,yBAAyB,EACnC,QAAQ,EAAE,kBAAkB,GAC3B,wBAAwB,CAyB1B"}
|
|
@@ -11,6 +11,8 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
import { useMqtt, useTopicsState } from "../Mqtt";
|
|
13
13
|
import { useMemo } from "react";
|
|
14
|
+
import { hsvwArrayToJSON } from "../../utils/hsvw";
|
|
15
|
+
export var SWITCHABLE_OUTPUT_TREES = ["system", "switch"];
|
|
14
16
|
export var getSwitchableOutputNameForDisplay = function (state, switchingDeviceName) {
|
|
15
17
|
// when custom name defined, or group not overriden
|
|
16
18
|
if (state.customName || state.group === "") {
|
|
@@ -19,39 +21,41 @@ export var getSwitchableOutputNameForDisplay = function (state, switchingDeviceN
|
|
|
19
21
|
// otherwise prepend switching device name
|
|
20
22
|
return "".concat(switchingDeviceName, " | ").concat(state.name);
|
|
21
23
|
};
|
|
22
|
-
export var getSwitchableOutputStateTopics = function (portalId, deviceId, outputId) { return ({
|
|
23
|
-
type: "N/".concat(portalId, "/
|
|
24
|
-
status: "N/".concat(portalId, "/
|
|
25
|
-
name: "N/".concat(portalId, "/
|
|
26
|
-
customName: "N/".concat(portalId, "/
|
|
27
|
-
group: "N/".concat(portalId, "/
|
|
28
|
-
showUIControl: "N/".concat(portalId, "/
|
|
29
|
-
auto: "N/".concat(portalId, "/
|
|
30
|
-
state: "N/".concat(portalId, "/
|
|
31
|
-
dimming: "N/".concat(portalId, "/
|
|
32
|
-
dimmingMin: "N/".concat(portalId, "/
|
|
33
|
-
dimmingMax: "N/".concat(portalId, "/
|
|
34
|
-
stepSize: "N/".concat(portalId, "/
|
|
35
|
-
measurement: "N/".concat(portalId, "/
|
|
36
|
-
unit: "N/".concat(portalId, "/
|
|
37
|
-
decimals: "N/".concat(portalId, "/
|
|
38
|
-
labels: "N/".concat(portalId, "/
|
|
39
|
-
lightControls: "N/".concat(portalId, "/
|
|
24
|
+
export var getSwitchableOutputStateTopics = function (portalId, tree, deviceId, outputId) { return ({
|
|
25
|
+
type: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/Type"),
|
|
26
|
+
status: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Status"),
|
|
27
|
+
name: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Name"),
|
|
28
|
+
customName: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/CustomName"),
|
|
29
|
+
group: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/Group"),
|
|
30
|
+
showUIControl: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/ShowUIControl"),
|
|
31
|
+
auto: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Auto"),
|
|
32
|
+
state: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/State"),
|
|
33
|
+
dimming: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Dimming"),
|
|
34
|
+
dimmingMin: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/DimmingMin"),
|
|
35
|
+
dimmingMax: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/DimmingMax"),
|
|
36
|
+
stepSize: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/StepSize"),
|
|
37
|
+
measurement: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Measurement"),
|
|
38
|
+
unit: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/Unit"),
|
|
39
|
+
decimals: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/Decimals"),
|
|
40
|
+
labels: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/Labels"),
|
|
41
|
+
lightControls: "N/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/LightControls"),
|
|
40
42
|
}); };
|
|
41
|
-
export var getSwitchableOutputWriteTopics = function (portalId, deviceId, outputId) { return ({
|
|
42
|
-
auto: "W/".concat(portalId, "/
|
|
43
|
-
state: "W/".concat(portalId, "/
|
|
44
|
-
dimming: "W/".concat(portalId, "/
|
|
45
|
-
lightControls: "W/".concat(portalId, "/
|
|
43
|
+
export var getSwitchableOutputWriteTopics = function (portalId, tree, deviceId, outputId) { return ({
|
|
44
|
+
auto: "W/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Auto"),
|
|
45
|
+
state: "W/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/State"),
|
|
46
|
+
dimming: "W/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Dimming"),
|
|
47
|
+
lightControls: "W/".concat(portalId, "/").concat(tree, "/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/LightControls"),
|
|
46
48
|
}); };
|
|
47
|
-
export function useSwitchableOutput(deviceId, outputId) {
|
|
49
|
+
export function useSwitchableOutput(tree, deviceId, outputId) {
|
|
48
50
|
var mqtt = useMqtt();
|
|
49
|
-
var topics = useMemo(function () { return getSwitchableOutputStateTopics(mqtt.portalId, deviceId, outputId); }, [mqtt.portalId, deviceId, outputId]);
|
|
50
|
-
var writeTopics = useMemo(function () { return getSwitchableOutputWriteTopics(mqtt.portalId, deviceId, outputId); }, [mqtt.portalId, deviceId, outputId]);
|
|
51
|
+
var topics = useMemo(function () { return getSwitchableOutputStateTopics(mqtt.portalId, tree, deviceId, outputId); }, [mqtt.portalId, deviceId, outputId]);
|
|
52
|
+
var writeTopics = useMemo(function () { return getSwitchableOutputWriteTopics(mqtt.portalId, tree, deviceId, outputId); }, [mqtt.portalId, deviceId, outputId]);
|
|
51
53
|
var updateAuto = function (auto) { return mqtt.publish(writeTopics.auto, auto); };
|
|
52
54
|
var updateState = function (state) { return mqtt.publish(writeTopics.state, state); };
|
|
53
55
|
var updateDimming = function (dimming) { return mqtt.publish(writeTopics.dimming, dimming); };
|
|
54
|
-
var updateLightControls = function (hsvwa) {
|
|
55
|
-
|
|
56
|
+
var updateLightControls = function (hsvwa) {
|
|
57
|
+
return mqtt.publish(writeTopics.lightControls, { raw: hsvwArrayToJSON(hsvwa) });
|
|
58
|
+
};
|
|
59
|
+
return __assign(__assign({}, useTopicsState(topics)), { tree: tree, updateAuto: updateAuto, updateState: updateState, updateDimming: updateDimming, updateLightControls: updateLightControls });
|
|
56
60
|
}
|
|
57
61
|
//# sourceMappingURL=SwitchableOutput.provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchableOutput.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutput.provider.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO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ACtF,IAAM,mBAAmB,GAAG,UAAC,KAAqB;QAChD,OAAA,IAAI,CAAC,OAAO,CAAC,WAAY,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;IAAzE,CAAyE,CAAA;IAE3E,6BACK,cAAc,CAAwB,MAAM,CAAC,KAChD,IAAI,EAAE,IAAI,EACV,UAAU,YAAA,EACV,WAAW,aAAA,EACX,aAAa,eAAA,EACb,mBAAmB,qBAAA,IACpB;AACH,CAAC","sourcesContent":["import { PortalId, Topics, useMqtt, useTopicsState } from \"../Mqtt\"\nimport { useMemo } from \"react\"\nimport { SwitchingDeviceInstanceId } from \"./SwitchingDevice.provider\"\nimport { SwitchableOutputStatus, SwitchableOutputType } from \"../../utils/constants\"\nimport { hsvwArrayToJSON, HSVWColorArray } from \"../../utils/hsvw\"\n\nexport const SWITCHABLE_OUTPUT_TREES = [\"system\", \"switch\"] as const\nexport type SwitchableOutputTree = (typeof SWITCHABLE_OUTPUT_TREES)[number]\nexport type SwitchableOutputId = string\nexport type SwitchableOutputUnit = string | \"/Speed\" | \"/Temperature\" | \"/Volume\"\n\nexport interface SwitchableOutputState {\n tree: SwitchableOutputTree\n deviceId: SwitchingDeviceInstanceId\n outputId: SwitchableOutputId\n type: SwitchableOutputType\n status: SwitchableOutputStatus\n name: string\n customName: string\n group: string\n parentDeviceName: string\n showUIControl: 0 | 1\n auto: 0 | 1\n state: 0 | 1\n dimming?: number\n dimmingMin?: number\n dimmingMax?: number\n // NOTE: stepSize can be of any precision, respect the precision in the UI\n stepSize?: number\n measurement?: number\n unit: SwitchableOutputUnit\n decimals?: number\n // NOTE: JSON encoded string array\n labels: string\n lightControls: HSVWColorArray\n}\n\nexport interface SwitchableOutputProvider extends SwitchableOutputState {\n updateAuto: (auto: 0 | 1) => void\n updateState: (state: 0 | 1) => void\n updateDimming: (dimming: number) => void\n updateLightControls: (hsvwa: HSVWColorArray) => void\n}\n\nexport interface SwitchableOutputTopics extends Topics {\n type?: string\n status?: string\n name?: string\n customName?: string\n group?: string\n showUIControl?: string\n auto?: string\n state?: string\n dimming?: string\n dimmingMin?: string\n dimmingMax?: string\n stepSize?: string\n measurement?: string\n unit?: string\n labels?: string[]\n}\n\nexport const getSwitchableOutputNameForDisplay = (state: SwitchableOutputState, switchingDeviceName: string) => {\n // when custom name defined, or group not overriden\n if (state.customName || state.group === \"\") {\n return state.customName || state.name\n }\n // otherwise prepend switching device name\n return `${switchingDeviceName} | ${state.name}`\n}\n\nexport const getSwitchableOutputStateTopics = (\n portalId: PortalId,\n tree: SwitchableOutputTree,\n deviceId: SwitchingDeviceInstanceId,\n outputId: SwitchableOutputId\n) => ({\n type: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/Type`,\n status: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Status`,\n name: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Name`,\n customName: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/CustomName`,\n group: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/Group`,\n showUIControl: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/ShowUIControl`,\n auto: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Auto`,\n state: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/State`,\n dimming: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Dimming`,\n dimmingMin: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/DimmingMin`,\n dimmingMax: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/DimmingMax`,\n stepSize: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/StepSize`,\n measurement: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Measurement`,\n unit: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/Unit`,\n decimals: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/Decimals`,\n labels: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Settings/Labels`,\n lightControls: `N/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/LightControls`,\n})\n\nexport const getSwitchableOutputWriteTopics = (\n portalId: PortalId,\n tree: SwitchableOutputTree,\n deviceId: SwitchingDeviceInstanceId,\n outputId: SwitchableOutputId\n) => ({\n auto: `W/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Auto`,\n state: `W/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/State`,\n dimming: `W/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/Dimming`,\n lightControls: `W/${portalId}/${tree}/${deviceId}/SwitchableOutput/${outputId}/LightControls`,\n})\n\nexport function useSwitchableOutput(\n tree: SwitchableOutputTree,\n deviceId: SwitchingDeviceInstanceId,\n outputId: SwitchableOutputId\n): SwitchableOutputProvider {\n const mqtt = useMqtt()\n const topics = useMemo(\n () => getSwitchableOutputStateTopics(mqtt.portalId, tree, deviceId, outputId),\n [mqtt.portalId, deviceId, outputId]\n )\n const writeTopics = useMemo(\n () => getSwitchableOutputWriteTopics(mqtt.portalId, tree, deviceId, outputId),\n [mqtt.portalId, deviceId, outputId]\n )\n\n const updateAuto = (auto: 0 | 1) => mqtt.publish(writeTopics!.auto, auto)\n const updateState = (state: 0 | 1) => mqtt.publish(writeTopics!.state, state)\n const updateDimming = (dimming: number) => mqtt.publish(writeTopics!.dimming, dimming)\n const updateLightControls = (hsvwa: HSVWColorArray) =>\n mqtt.publish(writeTopics!.lightControls, { raw: hsvwArrayToJSON(hsvwa) })\n\n return {\n ...useTopicsState<SwitchableOutputState>(topics),\n tree: tree,\n updateAuto,\n updateState,\n updateDimming,\n updateLightControls,\n }\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useSwitchableOutputs: () => import("./SwitchableOutputs.store").SwitchableOutputsStore;
|
|
1
|
+
export declare const useSwitchableOutputs: (gxDeviceRelaysGroupName: string) => import("./SwitchableOutputs.store").SwitchableOutputsStore;
|
|
2
2
|
//# sourceMappingURL=SwitchableOutputs.provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchableOutputs.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SwitchableOutputs.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.provider.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,oBAAoB,GAAI,yBAAyB,MAAM,+DAiKnE,CAAA"}
|
|
@@ -15,11 +15,11 @@ import { useMqtt } from "../Mqtt";
|
|
|
15
15
|
import { useMemo, useEffect } from "react";
|
|
16
16
|
import { useSwitchableOutputsStore } from "./SwitchableOutputs.store";
|
|
17
17
|
import { getSwitchingDeviceStateTopics } from "./SwitchingDevice.provider";
|
|
18
|
-
import { getSwitchableOutputNameForDisplay, getSwitchableOutputStateTopics, } from "./SwitchableOutput.provider";
|
|
19
|
-
export var useSwitchableOutputs = function () {
|
|
18
|
+
import { getSwitchableOutputNameForDisplay, getSwitchableOutputStateTopics, SWITCHABLE_OUTPUT_TREES, } from "./SwitchableOutput.provider";
|
|
19
|
+
export var useSwitchableOutputs = function (gxDeviceRelaysGroupName) {
|
|
20
20
|
var switchableOutputsStore = useSwitchableOutputsStore();
|
|
21
21
|
var getTopics = function (portalId) { return ({
|
|
22
|
-
switchableOutputs: "N/".concat(portalId, "/
|
|
22
|
+
switchableOutputs: "N/".concat(portalId, "/(").concat(SWITCHABLE_OUTPUT_TREES.join("|"), ")/+/SwitchableOutput/+/Settings/+"),
|
|
23
23
|
switchingDevices: "N/".concat(portalId, "/switch/+"),
|
|
24
24
|
}); };
|
|
25
25
|
var mqtt = useMqtt();
|
|
@@ -117,17 +117,17 @@ export var useSwitchableOutputs = function () {
|
|
|
117
117
|
// and populate its initial state
|
|
118
118
|
availableSwitchableOutputs_1.forEach(function (output, index) {
|
|
119
119
|
var swo = extractSwitchableOutputInfo(output);
|
|
120
|
-
var switchingDevice = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, swo.deviceId));
|
|
120
|
+
var switchingDevice = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, swo.tree, swo.deviceId));
|
|
121
121
|
var customGroupAssignment = customGroupAssigments_1[index].trim();
|
|
122
|
-
var deviceName = switchingDevice.customName || switchingDevice.productName;
|
|
122
|
+
var deviceName = switchingDevice.customName || switchingDevice.productName || gxDeviceRelaysGroupName;
|
|
123
123
|
var groupName = customGroupAssignment === "" ? deviceName : customGroupAssignment;
|
|
124
|
-
var switchableOutput = mqtt.messagesByTopics(getSwitchableOutputStateTopics(mqtt.portalId, swo.deviceId, swo.outputId));
|
|
124
|
+
var switchableOutput = mqtt.messagesByTopics(getSwitchableOutputStateTopics(mqtt.portalId, swo.tree, swo.deviceId, swo.outputId));
|
|
125
125
|
// Ignore hidden controls
|
|
126
126
|
if (switchableOutput.showUIControl === 0) {
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
129
|
newGroups_1[groupName] || (newGroups_1[groupName] = []);
|
|
130
|
-
newGroups_1[groupName].push(__assign(__assign({}, switchableOutput), { deviceId: swo.deviceId, outputId: swo.outputId, parentDeviceName: deviceName }));
|
|
130
|
+
newGroups_1[groupName].push(__assign(__assign({}, switchableOutput), { tree: swo.tree, deviceId: swo.deviceId, outputId: swo.outputId, parentDeviceName: deviceName }));
|
|
131
131
|
});
|
|
132
132
|
Logger.log("New switchable output groups: ".concat(JSON.stringify(Object.keys(newGroups_1))));
|
|
133
133
|
// Sort switches in a group by name
|
|
@@ -147,9 +147,13 @@ export var useSwitchableOutputs = function () {
|
|
|
147
147
|
return switchableOutputsStore;
|
|
148
148
|
};
|
|
149
149
|
function extractSwitchableOutputInfo(topic) {
|
|
150
|
-
var
|
|
150
|
+
var _a;
|
|
151
|
+
var pattern = new RegExp("/(".concat(SWITCHABLE_OUTPUT_TREES.join("|"), ")/"));
|
|
152
|
+
var match = topic.match(pattern);
|
|
153
|
+
var switchStart = match ? match.index + match[0].length : -1; // length of `/system/`, or `/switch/`, or ...
|
|
151
154
|
var outputStart = topic.indexOf("/SwitchableOutput/") + 18; // length of `/SwitchableOutput/`
|
|
152
155
|
return {
|
|
156
|
+
tree: (_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : null, // "switch", "system", ...
|
|
153
157
|
deviceId: topic.substring(switchStart, topic.indexOf("/", switchStart)),
|
|
154
158
|
outputId: topic.substring(outputStart, topic.indexOf("/", outputStart)),
|
|
155
159
|
};
|
|
@@ -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,EACL,iCAAiC,EACjC,8BAA8B,GAG/B,MAAM,6BAA6B,CAAA;AAEpC,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;QAC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A4B,EAAE,2BAA2B,CAAC,CAAC,CAAA;IAE/D,OAAO,sBAAsB,CAAA;AAC/B,CAAC,CAAA;AAED,SAAS,2BAA2B,CAAC,KAAa;IAChD,IAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA,CAAC,uBAAuB;IACzE,IAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAA,CAAC,iCAAiC;IAE9F,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAyC;QAC/G,QAAQ,EAAE,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 {\n getSwitchableOutputNameForDisplay,\n getSwitchableOutputStateTopics,\n SwitchableOutputId,\n SwitchableOutputState,\n} 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 deviceName = switchingDevice.customName || switchingDevice.productName\n const groupName = customGroupAssignment === \"\" ? deviceName : 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({\n ...switchableOutput,\n deviceId: swo.deviceId,\n outputId: swo.outputId,\n parentDeviceName: deviceName as unknown as string,\n })\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 = getSwitchableOutputNameForDisplay(a, a.parentDeviceName)\n const bName = getSwitchableOutputNameForDisplay(b, b.parentDeviceName)\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,EACL,iCAAiC,EACjC,8BAA8B,EAC9B,uBAAuB,GAIxB,MAAM,6BAA6B,CAAA;AAEpC,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAAC,uBAA+B;IAClE,IAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAA;IAE1D,IAAM,SAAS,GAAG,UAAC,QAAkB,IAAK,OAAA,CAAC;QACzC,iBAAiB,EAAE,YAAK,QAAQ,eAAK,uBAAuB,CAAC,IAAI,CAAC,GAAG,CAAC,sCAAmC;QACzG,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,CA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A2B,CAAC,KAAa;;IAChD,IAAM,OAAO,GAAG,IAAI,MAAM,CAAC,YAAK,uBAAuB,CAAC,IAAI,CAAC,GAAG,CAAC,OAAI,CAAC,CAAA;IACtE,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAClC,IAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,8CAA8C;IAC9G,IAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAA,CAAC,iCAAiC;IAE9F,OAAO;QACL,IAAI,EAAE,MAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,CAAC,CAA0B,mCAAI,IAAI,EAAE,0BAA0B;QAC9E,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAyC;QAC/G,QAAQ,EAAE,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 {\n getSwitchableOutputNameForDisplay,\n getSwitchableOutputStateTopics,\n SWITCHABLE_OUTPUT_TREES,\n SwitchableOutputId,\n SwitchableOutputState,\n SwitchableOutputTree,\n} from \"./SwitchableOutput.provider\"\n\nexport const useSwitchableOutputs = (gxDeviceRelaysGroupName: string) => {\n const switchableOutputsStore = useSwitchableOutputsStore()\n\n const getTopics = (portalId: PortalId) => ({\n switchableOutputs: `N/${portalId}/(${SWITCHABLE_OUTPUT_TREES.join(\"|\")})/+/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\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(\n getSwitchingDeviceStateTopics(mqtt.portalId, swo.tree, swo.deviceId)\n )\n const customGroupAssignment = customGroupAssigments[index].trim()\n const deviceName = switchingDevice.customName || switchingDevice.productName || gxDeviceRelaysGroupName\n const groupName = customGroupAssignment === \"\" ? deviceName : customGroupAssignment\n const switchableOutput = mqtt.messagesByTopics(\n getSwitchableOutputStateTopics(mqtt.portalId, swo.tree, 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({\n ...switchableOutput,\n tree: swo.tree,\n deviceId: swo.deviceId,\n outputId: swo.outputId,\n parentDeviceName: deviceName as unknown as string,\n })\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 = getSwitchableOutputNameForDisplay(a, a.parentDeviceName)\n const bName = getSwitchableOutputNameForDisplay(b, b.parentDeviceName)\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 pattern = new RegExp(`/(${SWITCHABLE_OUTPUT_TREES.join(\"|\")})/`)\n const match = topic.match(pattern)\n const switchStart = match ? match.index! + match[0].length : -1 // length of `/system/`, or `/switch/`, or ...\n const outputStart = topic.indexOf(\"/SwitchableOutput/\") + 18 // length of `/SwitchableOutput/`\n\n return {\n tree: (match?.[1] as SwitchableOutputTree) ?? null, // \"switch\", \"system\", ...\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,5 +1,5 @@
|
|
|
1
1
|
import { PortalId, Topics } from "../Mqtt";
|
|
2
|
-
import { SwitchableOutputState } from "./SwitchableOutput.provider";
|
|
2
|
+
import { SwitchableOutputState, SwitchableOutputTree } from "./SwitchableOutput.provider";
|
|
3
3
|
export type SwitchingDeviceInstanceId = number;
|
|
4
4
|
export interface SwitchingDeviceState {
|
|
5
5
|
productName: string;
|
|
@@ -12,7 +12,7 @@ export interface SwitchingDeviceTopics extends Topics {
|
|
|
12
12
|
customName?: string;
|
|
13
13
|
instance?: string;
|
|
14
14
|
}
|
|
15
|
-
export declare const getSwitchingDeviceStateTopics: (portalId: PortalId, instanceId: SwitchingDeviceInstanceId) => {
|
|
15
|
+
export declare const getSwitchingDeviceStateTopics: (portalId: PortalId, tree: SwitchableOutputTree, instanceId: SwitchingDeviceInstanceId) => {
|
|
16
16
|
productName: string;
|
|
17
17
|
customName: string;
|
|
18
18
|
instance: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchingDevice.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchingDevice.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAA2B,MAAM,SAAS,CAAA;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"SwitchingDevice.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchingDevice.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAA2B,MAAM,SAAS,CAAA;AAEnE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAIzF,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAA;AAE9C,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,iBAAiB,EAAE,qBAAqB,EAAE,CAAA;CAC3C;AAED,MAAM,WAAW,qBAAsB,SAAQ,MAAM;IACnD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,6BAA6B,GACxC,UAAU,QAAQ,EAClB,MAAM,oBAAoB,EAC1B,YAAY,yBAAyB;;;;CAKrC,CAAA;AAEF,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,yBAAyB,GAAG,oBAAoB,CAK9F;AAED,wBAAgB,mBAAmB,6DAuClC"}
|
|
@@ -3,14 +3,14 @@ import { useMqtt, useTopicsState } from "../Mqtt";
|
|
|
3
3
|
import Logger from "../../utils/logger";
|
|
4
4
|
import { useSwitchingDevicesStore } from "./SwitchingDevices.store";
|
|
5
5
|
import { autorun } from "mobx";
|
|
6
|
-
export var getSwitchingDeviceStateTopics = function (portalId, instanceId) { return ({
|
|
7
|
-
productName: "N/".concat(portalId, "/
|
|
8
|
-
customName: "N/".concat(portalId, "/
|
|
9
|
-
instance: "N/".concat(portalId, "/
|
|
6
|
+
export var getSwitchingDeviceStateTopics = function (portalId, tree, instanceId) { return ({
|
|
7
|
+
productName: "N/".concat(portalId, "/").concat(tree, "/").concat(instanceId, "/ProductName"),
|
|
8
|
+
customName: "N/".concat(portalId, "/").concat(tree, "/").concat(instanceId, "/CustomName"),
|
|
9
|
+
instance: "N/".concat(portalId, "/").concat(tree, "/").concat(instanceId, "/DeviceInstance"),
|
|
10
10
|
}); };
|
|
11
11
|
export function useSwitchingDevice(instanceId) {
|
|
12
12
|
var portalId = useMqtt().portalId;
|
|
13
|
-
var topics = useMemo(function () { return getSwitchingDeviceStateTopics(portalId, instanceId); }, [portalId, instanceId]);
|
|
13
|
+
var topics = useMemo(function () { return getSwitchingDeviceStateTopics(portalId, "switch", instanceId); }, [portalId, instanceId]);
|
|
14
14
|
return useTopicsState(topics);
|
|
15
15
|
}
|
|
16
16
|
export function useSwitchingDevices() {
|
|
@@ -31,7 +31,7 @@ export function useSwitchingDevices() {
|
|
|
31
31
|
var dispose_1 = autorun(function () {
|
|
32
32
|
var oldDevices = switchingDevicesStore.devices;
|
|
33
33
|
var newDevices = deviceInstances_1.map(function (deviceId) {
|
|
34
|
-
return mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, deviceId));
|
|
34
|
+
return mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, "switch", deviceId));
|
|
35
35
|
});
|
|
36
36
|
// TODO: check unordered structural identify of old and new state
|
|
37
37
|
// TODO: to avoid unnecessary re-rendering: O(n^2) baby
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchingDevice.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchingDevice.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAoB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,MAAM,MAAM,oBAAoB,CAAA;AAEvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAiB9B,MAAM,CAAC,IAAM,6BAA6B,GAAG,
|
|
1
|
+
{"version":3,"file":"SwitchingDevice.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchingDevice.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAoB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,MAAM,MAAM,oBAAoB,CAAA;AAEvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAiB9B,MAAM,CAAC,IAAM,6BAA6B,GAAG,UAC3C,QAAkB,EAClB,IAA0B,EAC1B,UAAqC,IAClC,OAAA,CAAC;IACJ,WAAW,EAAE,YAAK,QAAQ,cAAI,IAAI,cAAI,UAAU,iBAAc;IAC9D,UAAU,EAAE,YAAK,QAAQ,cAAI,IAAI,cAAI,UAAU,gBAAa;IAC5D,QAAQ,EAAE,YAAK,QAAQ,cAAI,IAAI,cAAI,UAAU,oBAAiB;CAC/D,CAAC,EAJG,CAIH,CAAA;AAEF,MAAM,UAAU,kBAAkB,CAAC,UAAqC;IAC9D,IAAA,QAAQ,GAAK,OA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AE,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAAvF,CAAuF,CAC9C,CAAA;gBAC3C,iEAAiE;gBACjE,uDAAuD;gBACvD,IACE,UAAU,CAAC,MAAM,KAAK,CAAC;oBACvB,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM;oBACtC,CAAC,UAAU,CAAC,KAAK,CAAC,UAAC,EAAE,IAAK,OAAA,iBAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,EAA5B,CAA4B,CAAC,EACvD,CAAC;oBACD,MAAM,CAAC,GAAG,CAAC,2CAAoC,IAAI,CAAC,SAAS,CAAC,iBAAe,CAAC,CAAE,CAAC,CAAA;oBACjF,qBAAqB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;gBAC9C,CAAC;YACH,CAAC,CAAC,CAAA;YACF,OAAO,cAAM,OAAA,SAAO,EAAE,EAAT,CAAS,CAAA;QACxB,CAAC;IACH,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAC,CAAA;IAEjC,OAAO,qBAAqB,CAAA;AAC9B,CAAC","sourcesContent":["import { useEffect, useMemo } from \"react\"\nimport { PortalId, Topics, useMqtt, useTopicsState } from \"../Mqtt\"\nimport Logger from \"../../utils/logger\"\nimport { SwitchableOutputState, SwitchableOutputTree } from \"./SwitchableOutput.provider\"\nimport { useSwitchingDevicesStore } from \"./SwitchingDevices.store\"\nimport { autorun } from \"mobx\"\n\nexport type SwitchingDeviceInstanceId = number\n\nexport interface SwitchingDeviceState {\n productName: string\n customName: string\n instance: number\n switchableOutputs: SwitchableOutputState[]\n}\n\nexport interface SwitchingDeviceTopics extends Topics {\n productName?: string\n customName?: string\n instance?: string\n}\n\nexport const getSwitchingDeviceStateTopics = (\n portalId: PortalId,\n tree: SwitchableOutputTree,\n instanceId: SwitchingDeviceInstanceId\n) => ({\n productName: `N/${portalId}/${tree}/${instanceId}/ProductName`,\n customName: `N/${portalId}/${tree}/${instanceId}/CustomName`,\n instance: `N/${portalId}/${tree}/${instanceId}/DeviceInstance`,\n})\n\nexport function useSwitchingDevice(instanceId: SwitchingDeviceInstanceId): SwitchingDeviceState {\n const { portalId } = useMqtt()\n const topics = useMemo(() => getSwitchingDeviceStateTopics(portalId, \"switch\", instanceId), [portalId, instanceId])\n\n return useTopicsState<SwitchingDeviceState>(topics)\n}\n\nexport function useSwitchingDevices() {\n const switchingDevicesStore = useSwitchingDevicesStore()\n\n const getTopics = (portalId: PortalId) => ({\n devices: `N/${portalId}/switch/+/DeviceInstance`,\n })\n\n const mqtt = useMqtt()\n const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId])\n\n const messagesForSwitchingDevices = mqtt.messagesByWildcard(topics.devices)\n\n // Examine MQTT to find all available switching devices\n useEffect(() => {\n if (!messagesForSwitchingDevices || Object.entries(messagesForSwitchingDevices).length === 0) {\n Logger.log(\"Waiting for switching devices...\")\n } else {\n const deviceInstances = Object.values(messagesForSwitchingDevices) as SwitchingDeviceInstanceId[]\n const dispose = autorun(() => {\n const oldDevices = switchingDevicesStore.devices\n const newDevices = deviceInstances.map((deviceId) =>\n mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, \"switch\", deviceId))\n ) as unknown as SwitchingDeviceInstanceId[]\n // TODO: check unordered structural identify of old and new state\n // TODO: to avoid unnecessary re-rendering: O(n^2) baby\n if (\n oldDevices.length === 0 ||\n oldDevices.length != newDevices.length ||\n !newDevices.every((id) => deviceInstances.includes(id))\n ) {\n Logger.log(`New switching devices instances: ${JSON.stringify(deviceInstances)}`)\n switchingDevicesStore.setDevices(newDevices)\n }\n })\n return () => dispose()\n }\n }, [messagesForSwitchingDevices])\n\n return switchingDevicesStore\n}\n"]}
|
package/dist/src/utils/hsvw.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare function createPercentage(value: number): Percentage;
|
|
|
20
20
|
export declare function createColorTemperature(value: number): ColorTemperature;
|
|
21
21
|
export declare function arrayToHSVW(arr: HSVWColorArray): HSVWColor;
|
|
22
22
|
export declare function hsvwToArray(color: HSVWColor): HSVWColorArray;
|
|
23
|
+
export declare function hsvwArrayToJSON(arr: HSVWColorArray): string;
|
|
23
24
|
export declare function createHSVWColor(hue: number, saturation: number, brightness: number, white: number, colorTemp: number): HSVWColor;
|
|
24
25
|
export {};
|
|
25
26
|
//# sourceMappingURL=hsvw.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hsvw.d.ts","sourceRoot":"/","sources":["src/utils/hsvw.ts"],"names":[],"mappings":"AAAA,KAAK,GAAG,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,KAAK,CAAA;CAAE,CAAA;AACtC,KAAK,UAAU,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,YAAY,CAAA;CAAE,CAAA;AACpD,KAAK,gBAAgB,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,CAAA;AAEhE,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,GAAG,CAAA;IACR,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,EAAE,UAAU,CAAA;IACjB,gBAAgB,EAAE,gBAAgB,CAAA;CACnC;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAErE,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAG5C;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAG1D;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAGtE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,SAAS,CAS1D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,cAAc,CAE5D;AAED,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,E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,CAQX"}
|
package/dist/src/utils/hsvw.js
CHANGED
|
@@ -23,6 +23,15 @@ export function arrayToHSVW(arr) {
|
|
|
23
23
|
export function hsvwToArray(color) {
|
|
24
24
|
return [color.hue, color.saturation, color.brightness, color.white, color.colorTemperature];
|
|
25
25
|
}
|
|
26
|
+
export function hsvwArrayToJSON(arr) {
|
|
27
|
+
var formattedNumbers = arr
|
|
28
|
+
.map(function (n) {
|
|
29
|
+
// If integer, add .0, otherwise keep as is
|
|
30
|
+
return Number.isInteger(n) ? "".concat(n, ".0") : String(n);
|
|
31
|
+
})
|
|
32
|
+
.join(",");
|
|
33
|
+
return "{\"value\":[".concat(formattedNumbers, "]}");
|
|
34
|
+
}
|
|
26
35
|
export function createHSVWColor(hue, saturation, brightness, white, colorTemp) {
|
|
27
36
|
return {
|
|
28
37
|
hue: createHue(hue),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hsvw.js","sourceRoot":"/","sources":["src/utils/hsvw.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;IACjD,OAAO,OAAc,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;IACjD,OAAO,OAAqB,CAAA;AAC9B,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;IAClD,OAAO,OAA2B,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAmB;IACtC,IAAA,GAAG,GAA8C,GAAG,GAAjD,EAAE,UAAU,GAAkC,GAAG,GAArC,EAAE,UAAU,GAAsB,GAAG,GAAzB,EAAE,KAAK,GAAe,GAAG,GAAlB,EAAE,SAAS,GAAI,GAAG,GAAP,CAAO;IAC3D,OAAO;QACL,GAAG,EAAE,SAAS,CAAC,GAAG,CAAC;QACnB,UAAU,EAAE,gBAAgB,CAAC,UAAU,CAAC;QACxC,UAAU,EAAE,gBAAgB,CAAC,UAAU,CAAC;QACxC,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC;QAC9B,gBAAgB,EAAE,sBAAsB,CAAC,SAAS,CAAC;KACpD,CAAA;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAgB;IAC1C,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAA;AAC7F,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,GAAW,EACX,UAAkB,EAClB,UAAkB,EAClB,KAAa,EACb,SAAiB;IAEjB,OAAO;QACL,GAAG,EAAE,SAAS,CAAC,GAAG,CAAC;QACnB,UAAU,EAAE,gBAAgB,CAAC,UAAU,CAAC;QACxC,UAAU,EAAE,gBAAgB,CAAC,UAAU,CAAC;QACxC,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC;QAC9B,gBAAgB,EAAE,sBAAsB,CAAC,SAAS,CAAC;KACpD,CAAA;AACH,CAAC","sourcesContent":["type Hue = number & { __brand: \"Hue\" } // 0-360 degrees\ntype Percentage = number & { __brand: \"Percentage\" } // 0-100\ntype ColorTemperature = number & { __brand: \"ColorTemperature\" } // 0-6500 K\n\nexport interface HSVWColor {\n hue: Hue\n saturation: Percentage\n brightness: Percentage\n white: Percentage\n colorTemperature: ColorTemperature\n}\n\nexport type HSVWColorArray = [number, number, number, number, number]\n\nexport function createHue(value: number): Hue {\n const clamped = Math.max(0, Math.min(360, value))\n return clamped as Hue\n}\n\nexport function createPercentage(value: number): Percentage {\n const clamped = Math.max(0, Math.min(100, value))\n return clamped as Percentage\n}\n\nexport function createColorTemperature(value: number): ColorTemperature {\n const clamped = Math.max(0, Math.min(6500, value))\n return clamped as ColorTemperature\n}\n\nexport function arrayToHSVW(arr: HSVWColorArray): HSVWColor {\n const [hue, saturation, brightness, white, colorTemp] = arr\n return {\n hue: createHue(hue),\n saturation: createPercentage(saturation),\n brightness: createPercentage(brightness),\n white: createPercentage(white),\n colorTemperature: createColorTemperature(colorTemp),\n }\n}\n\nexport function hsvwToArray(color: HSVWColor): HSVWColorArray {\n return [color.hue, color.saturation, color.brightness, color.white, color.colorTemperature]\n}\n\nexport function createHSVWColor(\n hue: number,\n saturation: number,\n brightness: number,\n white: number,\n colorTemp: number\n): HSVWColor {\n return {\n hue: createHue(hue),\n saturation: createPercentage(saturation),\n brightness: createPercentage(brightness),\n white: createPercentage(white),\n colorTemperature: createColorTemperature(colorTemp),\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hsvw.js","sourceRoot":"/","sources":["src/utils/hsvw.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;IACjD,OAAO,OAAc,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;IACjD,OAAO,OAAqB,CAAA;AAC9B,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,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,SAAS,CAAC,GAAG,CAAC;QACnB,UAAU,EAAE,gBAAgB,CAAC,UAAU,CAAC;QACxC,UAAU,EAAE,gBAAgB,CAAC,UAAU,CAAC;QACxC,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC;QAC9B,gBAAgB,EAAE,sBAAsB,CAAC,SAAS,CAAC;KACpD,CAAA;AACH,CAAC","sourcesContent":["type Hue = number & { __brand: \"Hue\" } // 0-360 degrees\ntype Percentage = number & { __brand: \"Percentage\" } // 0-100\ntype ColorTemperature = number & { __brand: \"ColorTemperature\" } // 0-6500 K\n\nexport interface HSVWColor {\n hue: Hue\n saturation: Percentage\n brightness: Percentage\n white: Percentage\n colorTemperature: ColorTemperature\n}\n\nexport type HSVWColorArray = [number, number, number, number, number]\n\nexport function createHue(value: number): Hue {\n const clamped = Math.max(0, Math.min(360, value))\n return clamped as Hue\n}\n\nexport function createPercentage(value: number): Percentage {\n const clamped = Math.max(0, Math.min(100, value))\n return clamped as Percentage\n}\n\nexport function createColorTemperature(value: number): ColorTemperature {\n const clamped = Math.max(0, Math.min(6500, value))\n return clamped as ColorTemperature\n}\n\nexport function arrayToHSVW(arr: HSVWColorArray): HSVWColor {\n const [hue, saturation, brightness, white, colorTemp] = arr\n return {\n hue: createHue(hue),\n saturation: createPercentage(saturation),\n brightness: createPercentage(brightness),\n white: createPercentage(white),\n colorTemperature: createColorTemperature(colorTemp),\n }\n}\n\nexport function hsvwToArray(color: HSVWColor): HSVWColorArray {\n return [color.hue, color.saturation, color.brightness, color.white, color.colorTemperature]\n}\n\nexport function hsvwArrayToJSON(arr: HSVWColorArray): string {\n const formattedNumbers = arr\n .map((n) => {\n // If integer, add .0, otherwise keep as is\n return Number.isInteger(n) ? `${n}.0` : String(n)\n })\n .join(\",\")\n\n return `{\"value\":[${formattedNumbers}]}`\n}\n\nexport function createHSVWColor(\n hue: number,\n saturation: number,\n brightness: number,\n white: number,\n colorTemp: number\n): HSVWColor {\n return {\n hue: createHue(hue),\n saturation: createPercentage(saturation),\n brightness: createPercentage(brightness),\n white: createPercentage(white),\n colorTemperature: createColorTemperature(colorTemp),\n }\n}\n"]}
|