@victronenergy/mfd-modules 11.1.5 → 11.1.7

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.
@@ -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,UAAU,CAAC,OAAO,WAAW,CAAC,GAAG,SAAS,CAAA;IAC/D,WAAW,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,SAAS,CAAA;IACtD,2BAA2B,EAAE,MAAM,CAAI;IACvC,mBAAmB,EAAE,MAAM,EAAE,CAAK;IAClC,mBAAmB,EAAE,OAAO,CAAQ;IAEpC;;;;;;;;;;;;;;;;OAgBG;IACH,gBAAgB,WACL,MAAM,iBAMhB;IAED;;;;;;;;;;;;;;;;;;UAkBM;IACN,gBAAgB,YACJ,MAAM;;MAsBjB;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,kBAAkB,cACJ,MAAM,SAsBnB;;IAqBD,IAAI,WAAW,YAEd;IAED,gBAAgB,GAAI,QAAQ,MAAM,UAqBjC;IAED,qBAAqB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mBAAmB,aAMlB;IAED,OAAO,GAAI,OAAO,MAAM,EAAE,MAAM,MAAM,GAAG,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,UAAU,qBAAqB,UAWjG;CACF;AA2CD,wBAAgB,OAAO,cAEtB"}
@@ -185,7 +185,10 @@ export class MqttStore {
185
185
  // trace()
186
186
  if (wildcard === undefined || wildcard === "" || wildcard === null)
187
187
  return {};
188
- const topicRegex = new RegExp(wildcard.replace(/\+/g, "\\w*")); // + in mqtt is anything -> .*
188
+ // Anchored single-level match: MQTT `+` matches exactly one topic level (no `/`),
189
+ // so a value change deep under a tree (e.g. `switch/0/.../Dimming`) no longer
190
+ // satisfies a shallow wildcard (`switch/+`) the way the old unanchored regex did.
191
+ const topicRegex = getWildcardRegex(wildcard);
189
192
  return Object.fromEntries(Object.keys(this.messages)
190
193
  .filter((topic) => topic.match(topicRegex))
191
194
  .map((topic) => [topic, this.messages[topic]])
@@ -539,6 +542,18 @@ export class MqttStore {
539
542
  }
540
543
  }
541
544
  const SUPPRESSED_KEEPALIVE_OPTIONS = JSON.stringify({ "keepalive-options": ["suppress-republish"] });
545
+ // Compiled wildcard regexes are cached: the same handful of wildcards recompute
546
+ // on every value flush, so we avoid rebuilding the RegExp each time.
547
+ const wildcardRegexCache = new Map();
548
+ function getWildcardRegex(wildcard) {
549
+ let regex = wildcardRegexCache.get(wildcard);
550
+ if (!regex) {
551
+ // `+` -> one level (no slash); anchor so the match is the whole topic, not a prefix
552
+ regex = new RegExp("^" + wildcard.replace(/\+/g, "[^/]+") + "$");
553
+ wildcardRegexCache.set(wildcard, regex);
554
+ }
555
+ return regex;
556
+ }
542
557
  /**
543
558
  * Compute mean by providing existing mean, number of samples, and new sample.
544
559
  *
@@ -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,EA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x-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: ReturnType<typeof setInterval> | undefined\n queueWorker: ReturnType<typeof setTimeout> | undefined\n meanQueueWorkerPassDuration: number = 0\n urgentTopicPrefixes: string[] = []\n initialLoadComplete: boolean = false\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 ([_key, 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 initialLoadComplete: false,\n completeInitialLoad: 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 if (granted !== undefined && granted[0]) {\n Logger.log(`Subscribed to ${granted[0].topic} with Qos ${granted[0].qos}`)\n } else {\n Logger.log(`Subscribed to ${topic} with Qos unknown`)\n }\n })\n\n this.topicsSubscribed.add(topic)\n }\n }\n\n clearSubscribedTopics() {\n this.topicsSubscribed.clear()\n this.urgentTopicPrefixes = []\n this.initialLoadComplete = false\n runInAction(() => {\n this.portalId = undefined\n })\n }\n\n addMessage = (topic: string, message: { value: string | undefined }) => {\n // Logger.log(`DEBUG: addMessage: topic: ${topic}, urgentPrefixes: ${JSON.stringify(this.urgentTopicPrefixes)}`)\n if (this.initialLoadComplete && 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\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\n }\n }\n\n completeInitialLoad = () => {\n this.addMessagesFromQueue()\n this.initialLoadComplete = true\n }\n\n addMessagesFromQueue = () => {\n // keys() avoids materializing all values just to check emptiness\n if (Object.keys(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 clearTimeout(this.queueWorker)\n }\n this.queueWorker = undefined\n }\n\n setPortalId = (portalId: string) => {\n this.portalId = portalId\n this.urgentTopicPrefixes = [\n `N/${portalId}/switch/`,\n `N/${portalId}/system/0/SwitchableOutput`,\n `N/${portalId}/settings/0/Settings/Gui2/Switchpane/Preset/`,\n ]\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.clear()\n this.urgentTopicPrefixes = []\n this.initialLoadComplete = false\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 const str = message.toString()\n if (str === \"\") return\n\n const parsed = getMessageJson(str)\n\n if (topic.endsWith(\"/system/0/Serial\") && !this.portalId) {\n if (this.portalId !== parsed.value && parsed.value !== undefined) {\n this.setPortalId(parsed.value)\n }\n\n runInAction(() => this.subscribeToAllTopics())\n }\n if (!this.initialLoadComplete && topic.endsWith(\"full_publish_completed\")) {\n const uniqueId = (parsed[\"full-publish-completed-echo\"] as string) || \"\"\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.completeInitialLoad()\n this.setupQueueWorker()\n }\n }\n\n this.addMessage(topic, parsed)\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 topic = `R/${this.portalId}/keepalive`\n\n Logger.log(`Sending keepalive for ${this.portalId} with ${SUPPRESSED_KEEPALIVE_OPTIONS}`)\n this.client?.publish(topic, SUPPRESSED_KEEPALIVE_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?.publish(topic, `{ \"keepalive-options\" : [ {\"full-publish-completed-echo\": \"${this.uniqueId}\" } ] }`)\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 return\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\nconst SUPPRESSED_KEEPALIVE_OPTIONS = JSON.stringify({ \"keepalive-options\": [\"suppress-republish\"] })\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,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,MAAM,OAAO,SAAS;IAmIpB;QAlIA;;;;;WAA0B;QAC1B;;;;;WAA+B;QAC/B;;;;mBAAiB,MAAM,CAAC,UAAU;WAAA;QAClC;;;;mBAAyB,EAAE;WAAA;QAC3B;;;;mBAA6B,EAAE;WAAA;QAC/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AA;AAEpG,gFAAgF;AAChF,qEAAqE;AACrE,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAkB,CAAA;AAEpD,SAAS,gBAAgB,CAAC,QAAgB;IACxC,IAAI,KAAK,GAAG,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,oFAAoF;QACpF,KAAK,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC,CAAA;QAChE,kBAAkB,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IACzC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;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,MAAM,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,GAAG,EAAE,CAAC,eAAe,EAAE,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: ReturnType<typeof setInterval> | undefined\n queueWorker: ReturnType<typeof setTimeout> | undefined\n meanQueueWorkerPassDuration: number = 0\n urgentTopicPrefixes: string[] = []\n initialLoadComplete: boolean = false\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 // Anchored single-level match: MQTT `+` matches exactly one topic level (no `/`),\n // so a value change deep under a tree (e.g. `switch/0/.../Dimming`) no longer\n // satisfies a shallow wildcard (`switch/+`) the way the old unanchored regex did.\n const topicRegex = getWildcardRegex(wildcard)\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 ([_key, 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 initialLoadComplete: false,\n completeInitialLoad: 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 if (granted !== undefined && granted[0]) {\n Logger.log(`Subscribed to ${granted[0].topic} with Qos ${granted[0].qos}`)\n } else {\n Logger.log(`Subscribed to ${topic} with Qos unknown`)\n }\n })\n\n this.topicsSubscribed.add(topic)\n }\n }\n\n clearSubscribedTopics() {\n this.topicsSubscribed.clear()\n this.urgentTopicPrefixes = []\n this.initialLoadComplete = false\n runInAction(() => {\n this.portalId = undefined\n })\n }\n\n addMessage = (topic: string, message: { value: string | undefined }) => {\n // Logger.log(`DEBUG: addMessage: topic: ${topic}, urgentPrefixes: ${JSON.stringify(this.urgentTopicPrefixes)}`)\n if (this.initialLoadComplete && 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\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\n }\n }\n\n completeInitialLoad = () => {\n this.addMessagesFromQueue()\n this.initialLoadComplete = true\n }\n\n addMessagesFromQueue = () => {\n // keys() avoids materializing all values just to check emptiness\n if (Object.keys(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 clearTimeout(this.queueWorker)\n }\n this.queueWorker = undefined\n }\n\n setPortalId = (portalId: string) => {\n this.portalId = portalId\n this.urgentTopicPrefixes = [\n `N/${portalId}/switch/`,\n `N/${portalId}/system/0/SwitchableOutput`,\n `N/${portalId}/settings/0/Settings/Gui2/Switchpane/Preset/`,\n ]\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.clear()\n this.urgentTopicPrefixes = []\n this.initialLoadComplete = false\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 const str = message.toString()\n if (str === \"\") return\n\n const parsed = getMessageJson(str)\n\n if (topic.endsWith(\"/system/0/Serial\") && !this.portalId) {\n if (this.portalId !== parsed.value && parsed.value !== undefined) {\n this.setPortalId(parsed.value)\n }\n\n runInAction(() => this.subscribeToAllTopics())\n }\n if (!this.initialLoadComplete && topic.endsWith(\"full_publish_completed\")) {\n const uniqueId = (parsed[\"full-publish-completed-echo\"] as string) || \"\"\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.completeInitialLoad()\n this.setupQueueWorker()\n }\n }\n\n this.addMessage(topic, parsed)\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 topic = `R/${this.portalId}/keepalive`\n\n Logger.log(`Sending keepalive for ${this.portalId} with ${SUPPRESSED_KEEPALIVE_OPTIONS}`)\n this.client?.publish(topic, SUPPRESSED_KEEPALIVE_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?.publish(topic, `{ \"keepalive-options\" : [ {\"full-publish-completed-echo\": \"${this.uniqueId}\" } ] }`)\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 return\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\nconst SUPPRESSED_KEEPALIVE_OPTIONS = JSON.stringify({ \"keepalive-options\": [\"suppress-republish\"] })\n\n// Compiled wildcard regexes are cached: the same handful of wildcards recompute\n// on every value flush, so we avoid rebuilding the RegExp each time.\nconst wildcardRegexCache = new Map<string, RegExp>()\n\nfunction getWildcardRegex(wildcard: string): RegExp {\n let regex = wildcardRegexCache.get(wildcard)\n if (!regex) {\n // `+` -> one level (no slash); anchor so the match is the whole topic, not a prefix\n regex = new RegExp(\"^\" + wildcard.replace(/\\+/g, \"[^/]+\") + \"$\")\n wildcardRegexCache.set(wildcard, regex)\n }\n return regex\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 +1 @@
1
- {"version":3,"file":"SwitchingDevice.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchingPane/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,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useEffect, useMemo } from "react";
2
2
  import { useMqtt, useTopicsState } from "../Mqtt";
3
3
  import Logger from "../../utils/logger";
4
4
  import { useSwitchingDevicesStore } from "./SwitchingDevices.store";
5
- import { autorun } from "mobx";
5
+ import { untracked } from "mobx";
6
6
  export const getSwitchingDeviceStateTopics = (portalId, tree, instanceId) => ({
7
7
  productName: `N/${portalId}/${tree}/${instanceId}/ProductName`,
8
8
  customName: `N/${portalId}/${tree}/${instanceId}/CustomName`,
@@ -23,24 +23,21 @@ export function useSwitchingDevices() {
23
23
  const messagesForSwitchingDevices = mqtt.messagesByWildcard(topics.devices);
24
24
  // Examine MQTT to find all available switching devices
25
25
  useEffect(() => {
26
- if (!messagesForSwitchingDevices || Object.entries(messagesForSwitchingDevices).length === 0) {
26
+ if (!messagesForSwitchingDevices || Object.keys(messagesForSwitchingDevices).length === 0) {
27
27
  Logger.log("Waiting for switching devices...");
28
+ return;
28
29
  }
29
- else {
30
- const deviceInstances = Object.values(messagesForSwitchingDevices);
31
- const dispose = autorun(() => {
32
- const oldDevices = switchingDevicesStore.devices;
33
- const newDevices = deviceInstances.map((deviceId) => mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, "switch", deviceId)));
34
- // TODO: check unordered structural identify of old and new state
35
- // TODO: to avoid unnecessary re-rendering: O(n^2) baby
36
- if (oldDevices.length === 0 ||
37
- oldDevices.length !== newDevices.length ||
38
- !newDevices.every((id) => deviceInstances.includes(id))) {
39
- Logger.log(`New switching devices instances: ${JSON.stringify(deviceInstances)}`);
40
- switchingDevicesStore.setDevices(newDevices);
41
- }
42
- });
43
- return () => dispose();
30
+ const deviceInstances = Object.values(messagesForSwitchingDevices);
31
+ // NOTE: the store is typed as instance ids but holds device state snapshots at runtime
32
+ const oldDevices = switchingDevicesStore.devices;
33
+ const instanceSet = new Set(deviceInstances);
34
+ if (oldDevices.length !== deviceInstances.length ||
35
+ !oldDevices.every((device) => instanceSet.has(device.instance))) {
36
+ Logger.log(`New switching devices instances: ${JSON.stringify(deviceInstances)}`);
37
+ // NOTE: snapshot device state untracked — per-device values are observed live via useSwitchingDevice,
38
+ // NOTE: the store list only needs refreshing when the set of devices changes
39
+ const newDevices = untracked(() => deviceInstances.map((deviceId) => mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, "switch", deviceId))));
40
+ switchingDevicesStore.setDevices(newDevices);
44
41
  }
45
42
  }, [messagesForSwitchingDevices, mqtt, switchingDevicesStore]);
46
43
  return switchingDevicesStore;
@@ -1 +1 @@
1
- {"version":3,"file":"SwitchingDevice.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchingPane/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,MAAM,6BAA6B,GAAG,CAC3C,QAAkB,EAClB,IAA0B,EAC1B,UAAqC,EACrC,EAAE,CAAC,CAAC;IACJ,WAAW,EAAE,KAAK,QAAQ,IAAI,IAAI,IAAI,UAAU,cAAc;IAC9D,UAAU,EAAE,KAAK,QAAQ,IAAI,IAAI,IAAI,UAAU,aAAa;IAC5D,QAAQ,EAAE,KAAK,QAAQ,IAAI,IAAI,IAAI,UAAU,iBAAiB;CAC/D,CAAC,CAAA;AAEF,MAAM,UAAU,kBAAkB,CAAC,UAAqC;IACtE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAA;IAC9B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,6BAA6B,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,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K,UAAU,CAAC,MAAM;oBACvC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,EACvD,CAAC;oBACD,MAAM,CAAC,GAAG,CAAC,oCAAoC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;oBACjF,qBAAqB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;gBAC9C,CAAC;YACH,CAAC,CAAC,CAAA;YACF,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAA;QACxB,CAAC;IACH,CAAC,EAAE,CAAC,2BAA2B,EAAE,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAA;IAE9D,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, mqtt, switchingDevicesStore])\n\n return switchingDevicesStore\n}\n"]}
1
+ {"version":3,"file":"SwitchingDevice.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchingPane/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,EA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,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1F,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAA;YAC9C,OAAM;QACR,CAAC;QAED,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,2BAA2B,CAAgC,CAAA;QACjG,uFAAuF;QACvF,MAAM,UAAU,GAAG,qBAAqB,CAAC,OAA4C,CAAA;QACrF,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAA;QAC5C,IACE,UAAU,CAAC,MAAM,KAAK,eAAe,CAAC,MAAM;YAC5C,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAC/D,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,oCAAoC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;YACjF,sGAAsG;YACtG,6EAA6E;YAC7E,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,EAAE,CAChC,eAAe,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC/B,IAAI,CAAC,gBAAgB,CAAC,6BAA6B,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CACxF,CACwC,CAAA;YAC3C,qBAAqB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;QAC9C,CAAC;IACH,CAAC,EAAE,CAAC,2BAA2B,EAAE,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAA;IAE9D,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 { untracked } 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.keys(messagesForSwitchingDevices).length === 0) {\n Logger.log(\"Waiting for switching devices...\")\n return\n }\n\n const deviceInstances = Object.values(messagesForSwitchingDevices) as SwitchingDeviceInstanceId[]\n // NOTE: the store is typed as instance ids but holds device state snapshots at runtime\n const oldDevices = switchingDevicesStore.devices as unknown as SwitchingDeviceState[]\n const instanceSet = new Set(deviceInstances)\n if (\n oldDevices.length !== deviceInstances.length ||\n !oldDevices.every((device) => instanceSet.has(device.instance))\n ) {\n Logger.log(`New switching devices instances: ${JSON.stringify(deviceInstances)}`)\n // NOTE: snapshot device state untracked — per-device values are observed live via useSwitchingDevice,\n // NOTE: the store list only needs refreshing when the set of devices changes\n const newDevices = untracked(() =>\n deviceInstances.map((deviceId) =>\n mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, \"switch\", deviceId))\n )\n ) as unknown as SwitchingDeviceInstanceId[]\n switchingDevicesStore.setDevices(newDevices)\n }\n }, [messagesForSwitchingDevices, mqtt, switchingDevicesStore])\n\n return switchingDevicesStore\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SwitchingPane.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchingPane/SwitchingPane.provider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiC,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AACrG,OAAO,EAIL,kBAAkB,EAKnB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAA8B,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAYpF,eAAO,MAAM,gBAAgB,GAAI,yBAAyB,MAAM,uDA6T/D,CAAA;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM;;cAQ8B,yBAAyB;cACjC,kBAAkB;EAEhG;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM;;cAQ0B,yBAAyB;aAC5B,cAAc;EAEzF;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAGtD"}
1
+ {"version":3,"file":"SwitchingPane.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchingPane/SwitchingPane.provider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiC,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AACrG,OAAO,EAIL,kBAAkB,EAKnB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAA8B,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAYpF,eAAO,MAAM,gBAAgB,GAAI,yBAAyB,MAAM,uDA8Q/D,CAAA;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM;;cAQ8B,yBAAyB;cACjC,kBAAkB;EAEhG;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM;;cAQ0B,yBAAyB;aAC5B,cAAc;EAEzF;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAGtD"}
@@ -1,4 +1,4 @@
1
- import { autorun } from "mobx";
1
+ import { runInAction, untracked } from "mobx";
2
2
  import Logger from "../../utils/logger";
3
3
  import { useMqtt } from "../Mqtt";
4
4
  import { useMemo, useEffect } from "react";
@@ -9,153 +9,94 @@ import { getGenericInputStateTopics } from "./GenericInput.provider";
9
9
  import { remapGenericInputType, SWITCHABLE_OUTPUT_FUNCTION, SWITCHABLE_OUTPUT_VISIBILITY, } from "../../utils/constants";
10
10
  const hasMessages = (messages) => messages && Object.keys(messages).length > 0;
11
11
  export const useSwitchingPane = (gxDeviceRelaysGroupName) => {
12
- const switchingPaneStore = useSwitchingPaneStore();
13
- const getTopics = (portalId) => ({
14
- switchableOutputs: `N/${portalId}/(${SWITCHABLE_OUTPUT_TREES.join("|")})/+/SwitchableOutput/+/Settings/+`,
15
- genericInputs: `N/${portalId}/(${SWITCHABLE_OUTPUT_TREES.join("|")})/+/GenericInput/+/Settings/+`,
16
- switchingDevices: `N/${portalId}/switch/+`,
17
- });
12
+ const store = useSwitchingPaneStore();
18
13
  const mqtt = useMqtt();
19
- const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId]);
20
- const messagesForSwitchableOutputs = mqtt.messagesByWildcard(topics.switchableOutputs);
21
- const messagesForGenericInputs = mqtt.messagesByWildcard(topics.genericInputs);
22
- const messagesForSwitchingDevices = mqtt.messagesByWildcard(topics.switchingDevices);
23
- // Examine MQTT to find all available switchable outputs, generic inputs, and their group assignments
14
+ const topics = useMemo(() => ({
15
+ systemOutputs: `N/${mqtt.portalId}/system/+/SwitchableOutput/+/Settings/+`,
16
+ switchOutputs: `N/${mqtt.portalId}/switch/+/SwitchableOutput/+/Settings/+`,
17
+ genericInputs: `N/${mqtt.portalId}/switch/+/GenericInput/+/Settings/+`,
18
+ // NOTE: deliberately precise (not `switch/+`) so that high-frequency operational
19
+ // NOTE: values (State, Dimming, Status, ...) do not invalidate the grouping below
20
+ switchingDeviceInstances: `N/${mqtt.portalId}/switch/+/DeviceInstance`,
21
+ switchingDeviceCustomNames: `N/${mqtt.portalId}/switch/+/CustomName`,
22
+ switchingDeviceProductNames: `N/${mqtt.portalId}/switch/+/ProductName`,
23
+ }), [mqtt.portalId]);
24
+ const messagesForSystemOutputs = mqtt.messagesByWildcard(topics.systemOutputs);
25
+ const messagesForSwitchOutputs = mqtt.messagesByWildcard(topics.switchOutputs);
26
+ const messagesForInputs = mqtt.messagesByWildcard(topics.genericInputs);
27
+ const messagesForSwitchingDeviceInstances = mqtt.messagesByWildcard(topics.switchingDeviceInstances);
28
+ const messagesForSwitchingDeviceCustomNames = mqtt.messagesByWildcard(topics.switchingDeviceCustomNames);
29
+ const messagesForSwitchingDeviceProductNames = mqtt.messagesByWildcard(topics.switchingDeviceProductNames);
24
30
  useEffect(() => {
25
- if (!hasMessages(messagesForSwitchableOutputs) && !hasMessages(messagesForGenericInputs)) {
31
+ if (!hasMessages(messagesForSystemOutputs) &&
32
+ !hasMessages(messagesForSwitchOutputs) &&
33
+ !hasMessages(messagesForInputs)) {
26
34
  Logger.log("Waiting for switchable outputs or generic inputs...");
27
35
  return;
28
36
  }
29
- // All switchable outputs in array sorted by topic
30
- const availableSwitchableOutputs = messagesForSwitchableOutputs
31
- ? Object.keys(messagesForSwitchableOutputs)
32
- .filter((key) => key.endsWith("/Settings/Group"))
33
- .sort()
34
- : [];
35
- // All switchable outputs group assignments in array sorted by topic
36
- const customGroupAssigments = availableSwitchableOutputs.map((topic) => {
37
- return messagesForSwitchableOutputs[topic];
38
- });
39
- // All switchable outputs types in array sorted by topic
40
- const availableSwitchableOutputTypes = availableSwitchableOutputs.map((topic) => {
41
- return Number(messagesForSwitchableOutputs[`${topic.slice(0, -"/Group".length)}/Type`]);
42
- });
43
- // All switchable outputs names in array sorted by topic
44
- const availableSwitchableOutputNames = availableSwitchableOutputs.map((topic) => {
45
- return messagesForSwitchableOutputs[`${topic.slice(0, -"/Group".length)}/CustomName`];
46
- });
47
- // All switchable outputs visibility in array sorted by topic
48
- const availableSwitchableOutputVisibilityFlags = availableSwitchableOutputs.map((topic) => {
49
- return Number(messagesForSwitchableOutputs[`${topic.slice(0, -"/Group".length)}/ShowUIControl`]);
50
- });
51
- // All switchable outputs functions in array sorted by topic
52
- const availableSwitchableOutputFunctions = availableSwitchableOutputs.map((topic) => {
53
- return Number(messagesForSwitchableOutputs[`${topic.slice(0, -"/Group".length)}/Function`]);
54
- });
55
- // All generic inputs in array sorted by topic
56
- const availableGenericInputs = messagesForGenericInputs
57
- ? Object.keys(messagesForGenericInputs)
58
- .filter((key) => key.endsWith("/Settings/Group"))
59
- .sort()
60
- : [];
61
- // All generic input group assignments in array sorted by topic
62
- const genericInputGroupAssignments = availableGenericInputs.map((topic) => {
63
- return messagesForGenericInputs[topic];
64
- });
65
- // All generic input types in array sorted by topic
66
- const availableGenericInputTypes = availableGenericInputs.map((topic) => {
67
- return Number(messagesForGenericInputs[`${topic.slice(0, -"/Group".length)}/Type`]);
68
- });
69
- // All generic input names in array sorted by topic
70
- const availableGenericInputNames = availableGenericInputs.map((topic) => {
71
- return messagesForGenericInputs[`${topic.slice(0, -"/Group".length)}/CustomName`];
72
- });
73
- // All generic input visibility in array sorted by topic
74
- const availableGenericInputVisibilityFlags = availableGenericInputs.map((topic) => {
75
- return Number(messagesForGenericInputs[`${topic.slice(0, -"/Group".length)}/ShowUIInput`]);
76
- });
77
- // All switching devices in array sorted by instance number
78
- const availableSwitchingDevices = Object.keys(messagesForSwitchingDevices)
79
- .filter((key) => key.endsWith("/DeviceInstance"))
37
+ // --- Phase A: Extract comparison arrays from wildcard messages (cheap) ---
38
+ const messagesForOutputs = Object.assign(Object.assign({}, messagesForSystemOutputs), messagesForSwitchOutputs);
39
+ const outputGroupTopics = Object.keys(messagesForOutputs)
40
+ .filter((k) => k.endsWith("/Settings/Group"))
80
41
  .sort();
81
- // All switching device names in array sorted by instance number
82
- const availableSwitchingDeviceNames = availableSwitchingDevices.map((topic) => {
83
- const topicPrefix = topic.slice(0, -"/DeviceInstance".length);
84
- return (messagesForSwitchingDevices[`${topicPrefix}/CustomName`] ||
85
- messagesForSwitchingDevices[`${topicPrefix}/ProductName`]);
42
+ const customGroupAssignments = outputGroupTopics.map((t) => messagesForOutputs[t]);
43
+ const outputTypes = outputGroupTopics.map((t) => Number(messagesForOutputs[`${t.slice(0, -"/Group".length)}/Type`]));
44
+ const outputNames = outputGroupTopics.map((t) => messagesForOutputs[`${t.slice(0, -"/Group".length)}/CustomName`]);
45
+ const outputVisibilityFlags = outputGroupTopics.map((t) => Number(messagesForOutputs[`${t.slice(0, -"/Group".length)}/ShowUIControl`]));
46
+ const outputFunctions = outputGroupTopics.map((t) => Number(messagesForOutputs[`${t.slice(0, -"/Group".length)}/Function`]));
47
+ const inputGroupTopics = Object.keys(messagesForInputs)
48
+ .filter((k) => k.endsWith("/Settings/Group"))
49
+ .sort();
50
+ const genericInputGroupAssignments = inputGroupTopics.map((t) => messagesForInputs[t]);
51
+ const genericInputTypes = inputGroupTopics.map((t) => Number(messagesForInputs[`${t.slice(0, -"/Group".length)}/Type`]));
52
+ const genericInputNames = inputGroupTopics.map((t) => messagesForInputs[`${t.slice(0, -"/Group".length)}/CustomName`]);
53
+ const genericInputVisibilityFlags = inputGroupTopics.map((t) => Number(messagesForInputs[`${t.slice(0, -"/Group".length)}/ShowUIInput`]));
54
+ const switchingDevices = Object.keys(messagesForSwitchingDeviceInstances).sort();
55
+ const switchingDeviceNames = switchingDevices.map((t) => {
56
+ const prefix = t.slice(0, -"/DeviceInstance".length);
57
+ return (messagesForSwitchingDeviceCustomNames[`${prefix}/CustomName`] ||
58
+ messagesForSwitchingDeviceProductNames[`${prefix}/ProductName`]);
86
59
  });
87
- const dispose = autorun(() => {
88
- const oldAssignments = switchingPaneStore.customGroupAssignments;
89
- const newAssignments = customGroupAssigments;
90
- const groupAssignmentsChanged = !arraysEqual(oldAssignments, newAssignments);
91
- if (groupAssignmentsChanged) {
92
- switchingPaneStore.setCustomGroupAssignments(newAssignments);
93
- }
94
- const oldOutputTypes = switchingPaneStore.outputTypes;
95
- const newOutputTypes = availableSwitchableOutputTypes;
96
- const outputTypesChanged = !arraysEqual(oldOutputTypes, newOutputTypes);
97
- if (outputTypesChanged) {
98
- switchingPaneStore.setOutputTypes(newOutputTypes);
99
- }
100
- const oldOutputNames = switchingPaneStore.outputNames;
101
- const newOutputNames = availableSwitchableOutputNames;
102
- const outputNamesChanged = !arraysEqual(oldOutputNames, newOutputNames);
103
- if (outputNamesChanged) {
104
- switchingPaneStore.setOutputNames(newOutputNames);
105
- }
106
- const oldOutputVisibilityFlags = switchingPaneStore.outputVisibilityFlags;
107
- const newOutputVisibilityFlags = availableSwitchableOutputVisibilityFlags;
108
- const outputVisibilityFlagsChanged = !arraysEqual(oldOutputVisibilityFlags, newOutputVisibilityFlags);
109
- if (outputVisibilityFlagsChanged) {
110
- switchingPaneStore.setOutputVisibilityFlags(newOutputVisibilityFlags);
111
- }
112
- const oldOutputFunctions = switchingPaneStore.outputFunctions;
113
- const newOutputFunctions = availableSwitchableOutputFunctions;
114
- const outputFunctionsChanged = !arraysEqual(oldOutputFunctions, newOutputFunctions);
115
- if (outputFunctionsChanged) {
116
- switchingPaneStore.setOutputFunctions(newOutputFunctions);
117
- }
118
- const oldSwitchingDevices = switchingPaneStore.switchingDevices;
119
- const newSwitchingDevices = availableSwitchingDevices;
120
- const switchingDevicesChanged = !arraysEqual(oldSwitchingDevices, newSwitchingDevices);
121
- if (switchingDevicesChanged) {
122
- switchingPaneStore.setSwitchingDevices(newSwitchingDevices);
123
- }
124
- const oldSwitchingDeviceNames = switchingPaneStore.switchingDeviceNames;
125
- const newSwitchingDeviceNames = availableSwitchingDeviceNames;
126
- const switchingDeviceNamesChanged = !arraysEqual(oldSwitchingDeviceNames, newSwitchingDeviceNames);
127
- if (switchingDeviceNamesChanged) {
128
- switchingPaneStore.setSwitchingDeviceNames(newSwitchingDeviceNames);
129
- }
130
- const oldGiAssignments = switchingPaneStore.genericInputGroupAssignments;
131
- const newGiAssignments = genericInputGroupAssignments;
132
- const giGroupAssignmentsChanged = !arraysEqual(oldGiAssignments, newGiAssignments);
133
- if (giGroupAssignmentsChanged) {
134
- switchingPaneStore.setGenericInputGroupAssignments(newGiAssignments);
135
- }
136
- const oldGiTypes = switchingPaneStore.genericInputTypes;
137
- const newGiTypes = availableGenericInputTypes;
138
- const giTypesChanged = !arraysEqual(oldGiTypes, newGiTypes);
139
- if (giTypesChanged) {
140
- switchingPaneStore.setGenericInputTypes(newGiTypes);
141
- }
142
- const oldGiNames = switchingPaneStore.genericInputNames;
143
- const newGiNames = availableGenericInputNames;
144
- const giNamesChanged = !arraysEqual(oldGiNames, newGiNames);
145
- if (giNamesChanged) {
146
- switchingPaneStore.setGenericInputNames(newGiNames);
147
- }
148
- const oldGiVisibilityFlags = switchingPaneStore.genericInputVisibilityFlags;
149
- const newGiVisibilityFlags = availableGenericInputVisibilityFlags;
150
- const giVisibilityFlagsChanged = !arraysEqual(oldGiVisibilityFlags, newGiVisibilityFlags);
151
- if (giVisibilityFlagsChanged) {
152
- switchingPaneStore.setGenericInputVisibilityFlags(newGiVisibilityFlags);
153
- }
154
- // On initial population (all old arrays empty), skip per-field logging
155
- const isInitialLoad = oldAssignments.length === 0 &&
156
- oldOutputTypes.length === 0 &&
157
- oldSwitchingDevices.length === 0 &&
158
- oldGiAssignments.length === 0;
60
+ // --- Phase B: comparison guard, batched in a single action ---
61
+ runInAction(() => {
62
+ var _a, _b;
63
+ const groupAssignmentsChanged = !arraysEqual(store.customGroupAssignments, customGroupAssignments);
64
+ if (groupAssignmentsChanged)
65
+ store.setCustomGroupAssignments(customGroupAssignments);
66
+ const outputTypesChanged = !arraysEqual(store.outputTypes, outputTypes);
67
+ if (outputTypesChanged)
68
+ store.setOutputTypes(outputTypes);
69
+ const outputNamesChanged = !arraysEqual(store.outputNames, outputNames);
70
+ if (outputNamesChanged)
71
+ store.setOutputNames(outputNames);
72
+ const outputVisibilityFlagsChanged = !arraysEqual(store.outputVisibilityFlags, outputVisibilityFlags);
73
+ if (outputVisibilityFlagsChanged)
74
+ store.setOutputVisibilityFlags(outputVisibilityFlags);
75
+ const outputFunctionsChanged = !arraysEqual(store.outputFunctions, outputFunctions);
76
+ if (outputFunctionsChanged)
77
+ store.setOutputFunctions(outputFunctions);
78
+ const switchingDevicesChanged = !arraysEqual(store.switchingDevices, switchingDevices);
79
+ if (switchingDevicesChanged)
80
+ store.setSwitchingDevices(switchingDevices);
81
+ const switchingDeviceNamesChanged = !arraysEqual(store.switchingDeviceNames, switchingDeviceNames);
82
+ if (switchingDeviceNamesChanged)
83
+ store.setSwitchingDeviceNames(switchingDeviceNames);
84
+ const giGroupAssignmentsChanged = !arraysEqual(store.genericInputGroupAssignments, genericInputGroupAssignments);
85
+ if (giGroupAssignmentsChanged)
86
+ store.setGenericInputGroupAssignments(genericInputGroupAssignments);
87
+ const giTypesChanged = !arraysEqual(store.genericInputTypes, genericInputTypes);
88
+ if (giTypesChanged)
89
+ store.setGenericInputTypes(genericInputTypes);
90
+ const giNamesChanged = !arraysEqual(store.genericInputNames, genericInputNames);
91
+ if (giNamesChanged)
92
+ store.setGenericInputNames(genericInputNames);
93
+ const giVisibilityFlagsChanged = !arraysEqual(store.genericInputVisibilityFlags, genericInputVisibilityFlags);
94
+ if (giVisibilityFlagsChanged)
95
+ store.setGenericInputVisibilityFlags(genericInputVisibilityFlags);
96
+ const isInitialLoad = store.customGroupAssignments.length === 0 &&
97
+ store.outputTypes.length === 0 &&
98
+ store.switchingDevices.length === 0 &&
99
+ store.genericInputGroupAssignments.length === 0;
159
100
  if (!isInitialLoad) {
160
101
  if (groupAssignmentsChanged)
161
102
  Logger.log(`Switchable outputs group assignments changed, recomputing...`);
@@ -191,83 +132,90 @@ export const useSwitchingPane = (gxDeviceRelaysGroupName) => {
191
132
  giTypesChanged ||
192
133
  giNamesChanged ||
193
134
  giVisibilityFlagsChanged) {
194
- // Collect all switching pane items (switchable outputs + generic inputs) with their group info
195
135
  const items = [];
196
- availableSwitchableOutputs.forEach((output, index) => {
197
- const swo = extractSwitchableOutputInfo(output);
198
- const switchingDevice = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, swo.tree, swo.deviceId));
199
- const customGroupAssignment = customGroupAssigments[index].trim();
200
- const deviceName = switchingDevice.customName || switchingDevice.productName || gxDeviceRelaysGroupName;
201
- const groupName = customGroupAssignment === "" ? deviceName : customGroupAssignment;
202
- const switchableOutput = mqtt.messagesByTopics(getSwitchableOutputStateTopics(mqtt.portalId, swo.tree, swo.deviceId, swo.outputId));
203
- if (!(switchableOutput.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE ||
204
- switchableOutput.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE_LOCAL_UI)) {
205
- return;
136
+ for (const topic of outputGroupTopics) {
137
+ const info = extractSwitchableOutputInfo(topic);
138
+ const { deviceName, output } = untracked(() => {
139
+ const device = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, info.tree, info.deviceId));
140
+ const out = mqtt.messagesByTopics(getSwitchableOutputStateTopics(mqtt.portalId, info.tree, info.deviceId, info.outputId));
141
+ return {
142
+ deviceName: device.customName || device.productName || gxDeviceRelaysGroupName,
143
+ output: out,
144
+ };
145
+ });
146
+ if (!(output.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE ||
147
+ output.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE_LOCAL_UI)) {
148
+ continue;
206
149
  }
207
150
  // GX system relays: only show when Function is Manual (matching gui-v2)
208
- if (swo.tree === "system" &&
209
- switchableOutput.function != null &&
210
- switchableOutput.function !== SWITCHABLE_OUTPUT_FUNCTION.MANUAL) {
211
- return;
151
+ if (info.tree === "system" &&
152
+ output.function != null &&
153
+ output.function !== SWITCHABLE_OUTPUT_FUNCTION.MANUAL) {
154
+ continue;
212
155
  }
156
+ const customGroup = ((_a = messagesForOutputs[topic]) !== null && _a !== void 0 ? _a : "").trim();
213
157
  items.push({
214
- groupName,
215
- item: Object.assign(Object.assign({}, switchableOutput), { kind: "switchableOutput", tree: swo.tree, deviceId: swo.deviceId, outputId: swo.outputId, parentDeviceName: deviceName }),
158
+ groupName: customGroup === "" ? deviceName : customGroup,
159
+ item: Object.assign(Object.assign({}, output), { kind: "switchableOutput", tree: info.tree, deviceId: info.deviceId, outputId: info.outputId, parentDeviceName: deviceName }),
160
+ });
161
+ }
162
+ for (const topic of inputGroupTopics) {
163
+ const info = extractGenericInputInfo(topic);
164
+ const { deviceName, input } = untracked(() => {
165
+ const device = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, info.tree, info.deviceId));
166
+ const inp = mqtt.messagesByTopics(getGenericInputStateTopics(mqtt.portalId, info.tree, info.deviceId, info.inputId));
167
+ return {
168
+ deviceName: device.customName || device.productName || gxDeviceRelaysGroupName,
169
+ input: inp,
170
+ };
216
171
  });
217
- });
218
- availableGenericInputs.forEach((input, index) => {
219
- const gi = extractGenericInputInfo(input);
220
- const switchingDevice = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, gi.tree, gi.deviceId));
221
- const customGroupAssignment = genericInputGroupAssignments[index].trim();
222
- const deviceName = switchingDevice.customName || switchingDevice.productName || gxDeviceRelaysGroupName;
223
- const groupName = customGroupAssignment === "" ? deviceName : customGroupAssignment;
224
- const genericInput = mqtt.messagesByTopics(getGenericInputStateTopics(mqtt.portalId, gi.tree, gi.deviceId, gi.inputId));
225
- if (!(genericInput.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE ||
226
- genericInput.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE_LOCAL_UI)) {
227
- return;
172
+ if (!(input.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE ||
173
+ input.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE_LOCAL_UI)) {
174
+ continue;
228
175
  }
176
+ const customGroup = ((_b = messagesForInputs[topic]) !== null && _b !== void 0 ? _b : "").trim();
229
177
  items.push({
230
- groupName,
231
- item: Object.assign(Object.assign({}, genericInput), { kind: "genericInput", tree: gi.tree, deviceId: gi.deviceId, outputId: gi.inputId, parentDeviceName: deviceName, type: remapGenericInputType(genericInput.type) }),
178
+ groupName: customGroup === "" ? deviceName : customGroup,
179
+ item: Object.assign(Object.assign({}, input), { kind: "genericInput", tree: info.tree, deviceId: info.deviceId, outputId: info.inputId, parentDeviceName: deviceName, type: remapGenericInputType(input.type) }),
232
180
  });
233
- });
234
- // Distribute items to groups
235
- const newGroups = {};
236
- items.forEach(({ groupName, item }) => {
237
- newGroups[groupName] || (newGroups[groupName] = []);
238
- newGroups[groupName].push(item);
239
- });
240
- // Sort items in each group by display name
241
- Object.values(newGroups).forEach((array) => {
242
- array.sort((a, b) => {
181
+ }
182
+ const groups = {};
183
+ for (const { groupName, item } of items) {
184
+ ;
185
+ (groups[groupName] || (groups[groupName] = [])).push(item);
186
+ }
187
+ for (const arr of Object.values(groups)) {
188
+ arr.sort((a, b) => {
243
189
  const aName = getSwitchingPaneItemNameForDisplay(a, a.parentDeviceName);
244
190
  const bName = getSwitchingPaneItemNameForDisplay(b, b.parentDeviceName);
245
191
  return aName.localeCompare(bName);
246
192
  });
247
- });
248
- Logger.log(`New switching pane groups: ${JSON.stringify(Object.keys(newGroups))}`);
249
- switchingPaneStore.setGroups(newGroups);
193
+ }
194
+ Logger.log(`New switching pane groups: ${JSON.stringify(Object.keys(groups))}`);
195
+ store.setGroups(groups);
250
196
  }
251
197
  });
252
- return () => dispose();
253
198
  }, [
254
- messagesForSwitchableOutputs,
255
- messagesForGenericInputs,
256
- messagesForSwitchingDevices,
199
+ messagesForSystemOutputs,
200
+ messagesForSwitchOutputs,
201
+ messagesForInputs,
202
+ messagesForSwitchingDeviceInstances,
203
+ messagesForSwitchingDeviceCustomNames,
204
+ messagesForSwitchingDeviceProductNames,
257
205
  gxDeviceRelaysGroupName,
258
206
  mqtt,
259
- switchingPaneStore,
207
+ store,
260
208
  ]);
261
- return switchingPaneStore;
209
+ return store;
262
210
  };
263
211
  export function extractSwitchableOutputInfo(topic) {
264
212
  var _a;
265
213
  const pattern = new RegExp(`/(${SWITCHABLE_OUTPUT_TREES.join("|")})/`);
266
214
  const match = topic.match(pattern);
267
- const switchStart = match ? match.index + match[0].length : -1; // length of `/system/`, or `/switch/`, or ...
268
- const outputStart = topic.indexOf("/SwitchableOutput/") + 18; // length of `/SwitchableOutput/`
215
+ const switchStart = match ? match.index + match[0].length : -1;
216
+ const outputStart = topic.indexOf("/SwitchableOutput/") + 18;
269
217
  return {
270
- tree: (_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : null, // "switch", "system", ...
218
+ tree: (_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : null,
271
219
  deviceId: Number(topic.substring(switchStart, topic.indexOf("/", switchStart))),
272
220
  outputId: topic.substring(outputStart, topic.indexOf("/", outputStart)),
273
221
  };
@@ -277,7 +225,7 @@ export function extractGenericInputInfo(topic) {
277
225
  const pattern = new RegExp(`/(${SWITCHABLE_OUTPUT_TREES.join("|")})/`);
278
226
  const match = topic.match(pattern);
279
227
  const treeEnd = match ? match.index + match[0].length : -1;
280
- const inputStart = topic.indexOf("/GenericInput/") + 14; // length of `/GenericInput/`
228
+ const inputStart = topic.indexOf("/GenericInput/") + 14;
281
229
  return {
282
230
  tree: (_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : null,
283
231
  deviceId: Number(topic.substring(treeEnd, topic.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AAA;IACvC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAClE,CAAC","sourcesContent":["import { autorun } from \"mobx\"\nimport Logger from \"../../utils/logger\"\nimport { PortalId, useMqtt } from \"../Mqtt\"\nimport { useMemo, useEffect } from \"react\"\nimport { useSwitchingPaneStore } from \"./SwitchingPane.store\"\nimport { getSwitchingDeviceStateTopics, SwitchingDeviceInstanceId } from \"./SwitchingDevice.provider\"\nimport {\n getSwitchingPaneItemNameForDisplay,\n getSwitchableOutputStateTopics,\n SWITCHABLE_OUTPUT_TREES,\n SwitchableOutputId,\n SwitchableOutputState,\n SwitchableOutputTree,\n GenericInputState,\n SwitchingPaneItem,\n} from \"./SwitchableOutput.provider\"\nimport { getGenericInputStateTopics, GenericInputId } from \"./GenericInput.provider\"\nimport {\n GenericInputType,\n remapGenericInputType,\n SwitchableOutputType,\n SwitchableOutputVisibility,\n SWITCHABLE_OUTPUT_FUNCTION,\n SWITCHABLE_OUTPUT_VISIBILITY,\n} from \"../../utils/constants\"\n\nconst hasMessages = (messages: Record<string, string> | undefined) => messages && Object.keys(messages).length > 0\n\nexport const useSwitchingPane = (gxDeviceRelaysGroupName: string) => {\n const switchingPaneStore = useSwitchingPaneStore()\n\n const getTopics = (portalId: PortalId) => ({\n switchableOutputs: `N/${portalId}/(${SWITCHABLE_OUTPUT_TREES.join(\"|\")})/+/SwitchableOutput/+/Settings/+`,\n genericInputs: `N/${portalId}/(${SWITCHABLE_OUTPUT_TREES.join(\"|\")})/+/GenericInput/+/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 messagesForGenericInputs = mqtt.messagesByWildcard(topics.genericInputs)\n const messagesForSwitchingDevices = mqtt.messagesByWildcard(topics.switchingDevices)\n\n // Examine MQTT to find all available switchable outputs, generic inputs, and their group assignments\n useEffect(() => {\n if (!hasMessages(messagesForSwitchableOutputs) && !hasMessages(messagesForGenericInputs)) {\n Logger.log(\"Waiting for switchable outputs or generic inputs...\")\n return\n }\n\n // All switchable outputs in array sorted by topic\n const availableSwitchableOutputs = messagesForSwitchableOutputs\n ? (Object.keys(messagesForSwitchableOutputs)\n .filter((key) => key.endsWith(\"/Settings/Group\"))\n .sort() as string[])\n : []\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 Number(messagesForSwitchableOutputs[`${topic.slice(0, -\"/Group\".length)}/Type`]) as SwitchableOutputType\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 Number(\n messagesForSwitchableOutputs[`${topic.slice(0, -\"/Group\".length)}/ShowUIControl`]\n ) as SwitchableOutputVisibility\n })\n // All switchable outputs functions in array sorted by topic\n const availableSwitchableOutputFunctions = availableSwitchableOutputs.map((topic) => {\n return Number(messagesForSwitchableOutputs[`${topic.slice(0, -\"/Group\".length)}/Function`])\n })\n\n // All generic inputs in array sorted by topic\n const availableGenericInputs = messagesForGenericInputs\n ? (Object.keys(messagesForGenericInputs)\n .filter((key) => key.endsWith(\"/Settings/Group\"))\n .sort() as string[])\n : []\n\n // All generic input group assignments in array sorted by topic\n const genericInputGroupAssignments = availableGenericInputs.map((topic) => {\n return messagesForGenericInputs[topic]\n })\n // All generic input types in array sorted by topic\n const availableGenericInputTypes = availableGenericInputs.map((topic) => {\n return Number(messagesForGenericInputs[`${topic.slice(0, -\"/Group\".length)}/Type`]) as GenericInputType\n })\n // All generic input names in array sorted by topic\n const availableGenericInputNames = availableGenericInputs.map((topic) => {\n return messagesForGenericInputs[`${topic.slice(0, -\"/Group\".length)}/CustomName`]\n })\n // All generic input visibility in array sorted by topic\n const availableGenericInputVisibilityFlags = availableGenericInputs.map((topic) => {\n return Number(\n messagesForGenericInputs[`${topic.slice(0, -\"/Group\".length)}/ShowUIInput`]\n ) as SwitchableOutputVisibility\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 = switchingPaneStore.customGroupAssignments\n const newAssignments = customGroupAssigments\n const groupAssignmentsChanged = !arraysEqual(oldAssignments, newAssignments)\n if (groupAssignmentsChanged) {\n switchingPaneStore.setCustomGroupAssignments(newAssignments)\n }\n\n const oldOutputTypes = switchingPaneStore.outputTypes\n const newOutputTypes = availableSwitchableOutputTypes\n const outputTypesChanged = !arraysEqual(oldOutputTypes, newOutputTypes)\n if (outputTypesChanged) {\n switchingPaneStore.setOutputTypes(newOutputTypes)\n }\n\n const oldOutputNames = switchingPaneStore.outputNames\n const newOutputNames = availableSwitchableOutputNames\n const outputNamesChanged = !arraysEqual(oldOutputNames, newOutputNames)\n if (outputNamesChanged) {\n switchingPaneStore.setOutputNames(newOutputNames)\n }\n\n const oldOutputVisibilityFlags = switchingPaneStore.outputVisibilityFlags\n const newOutputVisibilityFlags = availableSwitchableOutputVisibilityFlags\n const outputVisibilityFlagsChanged = !arraysEqual(oldOutputVisibilityFlags, newOutputVisibilityFlags)\n if (outputVisibilityFlagsChanged) {\n switchingPaneStore.setOutputVisibilityFlags(newOutputVisibilityFlags)\n }\n\n const oldOutputFunctions = switchingPaneStore.outputFunctions\n const newOutputFunctions = availableSwitchableOutputFunctions\n const outputFunctionsChanged = !arraysEqual(oldOutputFunctions, newOutputFunctions)\n if (outputFunctionsChanged) {\n switchingPaneStore.setOutputFunctions(newOutputFunctions)\n }\n\n const oldSwitchingDevices = switchingPaneStore.switchingDevices\n const newSwitchingDevices = availableSwitchingDevices\n const switchingDevicesChanged = !arraysEqual(oldSwitchingDevices, newSwitchingDevices)\n if (switchingDevicesChanged) {\n switchingPaneStore.setSwitchingDevices(newSwitchingDevices)\n }\n\n const oldSwitchingDeviceNames = switchingPaneStore.switchingDeviceNames\n const newSwitchingDeviceNames = availableSwitchingDeviceNames\n const switchingDeviceNamesChanged = !arraysEqual(oldSwitchingDeviceNames, newSwitchingDeviceNames)\n if (switchingDeviceNamesChanged) {\n switchingPaneStore.setSwitchingDeviceNames(newSwitchingDeviceNames)\n }\n\n const oldGiAssignments = switchingPaneStore.genericInputGroupAssignments\n const newGiAssignments = genericInputGroupAssignments\n const giGroupAssignmentsChanged = !arraysEqual(oldGiAssignments, newGiAssignments)\n if (giGroupAssignmentsChanged) {\n switchingPaneStore.setGenericInputGroupAssignments(newGiAssignments)\n }\n\n const oldGiTypes = switchingPaneStore.genericInputTypes\n const newGiTypes = availableGenericInputTypes\n const giTypesChanged = !arraysEqual(oldGiTypes, newGiTypes)\n if (giTypesChanged) {\n switchingPaneStore.setGenericInputTypes(newGiTypes)\n }\n\n const oldGiNames = switchingPaneStore.genericInputNames\n const newGiNames = availableGenericInputNames\n const giNamesChanged = !arraysEqual(oldGiNames, newGiNames)\n if (giNamesChanged) {\n switchingPaneStore.setGenericInputNames(newGiNames)\n }\n\n const oldGiVisibilityFlags = switchingPaneStore.genericInputVisibilityFlags\n const newGiVisibilityFlags = availableGenericInputVisibilityFlags\n const giVisibilityFlagsChanged = !arraysEqual(oldGiVisibilityFlags, newGiVisibilityFlags)\n if (giVisibilityFlagsChanged) {\n switchingPaneStore.setGenericInputVisibilityFlags(newGiVisibilityFlags)\n }\n\n // On initial population (all old arrays empty), skip per-field logging\n const isInitialLoad =\n oldAssignments.length === 0 &&\n oldOutputTypes.length === 0 &&\n oldSwitchingDevices.length === 0 &&\n oldGiAssignments.length === 0\n\n if (!isInitialLoad) {\n if (groupAssignmentsChanged) Logger.log(`Switchable outputs group assignments changed, recomputing...`)\n if (outputTypesChanged) Logger.log(`Switchable outputs types changed, recomputing...`)\n if (outputNamesChanged) Logger.log(`Switchable outputs names changed, recomputing...`)\n if (outputVisibilityFlagsChanged) Logger.log(`Switchable outputs visibility flags changed, recomputing...`)\n if (outputFunctionsChanged) Logger.log(`Switchable outputs functions changed, recomputing...`)\n if (switchingDevicesChanged) Logger.log(`Switching devices changed, recomputing...`)\n if (switchingDeviceNamesChanged) Logger.log(`Switching device names changed, recomputing...`)\n if (giGroupAssignmentsChanged) Logger.log(`Generic input group assignments changed, recomputing...`)\n if (giTypesChanged) Logger.log(`Generic input types changed, recomputing...`)\n if (giNamesChanged) Logger.log(`Generic input names changed, recomputing...`)\n if (giVisibilityFlagsChanged) Logger.log(`Generic input visibility flags changed, recomputing...`)\n }\n\n if (\n groupAssignmentsChanged ||\n outputTypesChanged ||\n outputNamesChanged ||\n outputVisibilityFlagsChanged ||\n outputFunctionsChanged ||\n switchingDevicesChanged ||\n switchingDeviceNamesChanged ||\n giGroupAssignmentsChanged ||\n giTypesChanged ||\n giNamesChanged ||\n giVisibilityFlagsChanged\n ) {\n // Collect all switching pane items (switchable outputs + generic inputs) with their group info\n const items: { groupName: string; item: SwitchingPaneItem }[] = []\n\n availableSwitchableOutputs.forEach((output, index) => {\n const swo = extractSwitchableOutputInfo(output)\n const switchingDevice = mqtt.messagesByTopics(\n getSwitchingDeviceStateTopics(mqtt.portalId, swo.tree, swo.deviceId)\n ) as unknown as Record<string, string>\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 if (\n !(\n switchableOutput.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE ||\n switchableOutput.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE_LOCAL_UI\n )\n ) {\n return\n }\n\n // GX system relays: only show when Function is Manual (matching gui-v2)\n if (\n swo.tree === \"system\" &&\n switchableOutput.function != null &&\n switchableOutput.function !== SWITCHABLE_OUTPUT_FUNCTION.MANUAL\n ) {\n return\n }\n\n items.push({\n groupName,\n item: {\n ...switchableOutput,\n kind: \"switchableOutput\",\n tree: swo.tree,\n deviceId: swo.deviceId,\n outputId: swo.outputId,\n parentDeviceName: deviceName as string,\n },\n })\n })\n\n availableGenericInputs.forEach((input, index) => {\n const gi = extractGenericInputInfo(input)\n const switchingDevice = mqtt.messagesByTopics(\n getSwitchingDeviceStateTopics(mqtt.portalId, gi.tree, gi.deviceId)\n ) as unknown as Record<string, string>\n const customGroupAssignment = genericInputGroupAssignments[index].trim()\n const deviceName = switchingDevice.customName || switchingDevice.productName || gxDeviceRelaysGroupName\n const groupName = customGroupAssignment === \"\" ? deviceName : customGroupAssignment\n const genericInput = mqtt.messagesByTopics(\n getGenericInputStateTopics(mqtt.portalId, gi.tree, gi.deviceId, gi.inputId)\n ) as unknown as GenericInputState\n\n if (\n !(\n genericInput.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE ||\n genericInput.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE_LOCAL_UI\n )\n ) {\n return\n }\n\n items.push({\n groupName,\n item: {\n ...genericInput,\n kind: \"genericInput\",\n tree: gi.tree,\n deviceId: gi.deviceId,\n outputId: gi.inputId,\n parentDeviceName: deviceName as string,\n type: remapGenericInputType(genericInput.type as number),\n },\n })\n })\n\n // Distribute items to groups\n const newGroups: { [key: string]: SwitchingPaneItem[] } = {}\n items.forEach(({ groupName, item }) => {\n newGroups[groupName] ||= []\n newGroups[groupName].push(item)\n })\n\n // Sort items in each group by display name\n Object.values(newGroups).forEach((array) => {\n array.sort((a, b) => {\n const aName = getSwitchingPaneItemNameForDisplay(a, a.parentDeviceName)\n const bName = getSwitchingPaneItemNameForDisplay(b, b.parentDeviceName)\n return aName.localeCompare(bName)\n })\n })\n\n Logger.log(`New switching pane groups: ${JSON.stringify(Object.keys(newGroups))}`)\n switchingPaneStore.setGroups(newGroups)\n }\n })\n return () => dispose()\n }, [\n messagesForSwitchableOutputs,\n messagesForGenericInputs,\n messagesForSwitchingDevices,\n gxDeviceRelaysGroupName,\n mqtt,\n switchingPaneStore,\n ])\n\n return switchingPaneStore\n}\n\nexport function 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: Number(topic.substring(switchStart, topic.indexOf(\"/\", switchStart))) as SwitchingDeviceInstanceId,\n outputId: topic.substring(outputStart, topic.indexOf(\"/\", outputStart)) as SwitchableOutputId,\n }\n}\n\nexport function extractGenericInputInfo(topic: string) {\n const pattern = new RegExp(`/(${SWITCHABLE_OUTPUT_TREES.join(\"|\")})/`)\n const match = topic.match(pattern)\n const treeEnd = match ? match.index! + match[0].length : -1\n const inputStart = topic.indexOf(\"/GenericInput/\") + 14 // length of `/GenericInput/`\n\n return {\n tree: (match?.[1] as SwitchableOutputTree) ?? null,\n deviceId: Number(topic.substring(treeEnd, topic.indexOf(\"/\", treeEnd))) as SwitchingDeviceInstanceId,\n inputId: topic.substring(inputStart, topic.indexOf(\"/\", inputStart)) as GenericInputId,\n }\n}\n\nexport function arraysEqual<T>(a: T[], b: T[]): boolean {\n if (a.length !== b.length) return false\n return a.every((element, index) => Object.is(element, b[index]))\n}\n"]}
1
+ {"version":3,"file":"SwitchingPane.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchingPane/SwitchingPane.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAC7C,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,6BAA6B,EAA6B,MAAM,4BAA4B,CAAA;AACrG,OAAO,EACL,kCAAkC,EAClC,8BAA8B,EAC9B,uBAAuB,GAMxB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,0BAA0B,EAAkB,MAAM,yBAAyB,CAAA;AACpF,OAAO,EAEL,qBAAqB,EAGrB,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,uBAAuB,CAAA;AAE9B,MAAM,WAAW,GAAG,CAAC,QAA4C,EAAE,EAAE,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;AAElH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,uBAA+B,EAAE,EAAE;IAClE,MAAM,KAAK,GAAG,qBAAqB,EAAE,CAAA;IACrC,MAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IAEtB,MAAM,MAAM,GAAG,OAAO,CACpB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AAA;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAI,CAAM,EAAE,CAAM;IAC3C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IACvC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAClE,CAAC","sourcesContent":["import { runInAction, untracked } from \"mobx\"\nimport Logger from \"../../utils/logger\"\nimport { useMqtt } from \"../Mqtt\"\nimport { useMemo, useEffect } from \"react\"\nimport { useSwitchingPaneStore } from \"./SwitchingPane.store\"\nimport { getSwitchingDeviceStateTopics, SwitchingDeviceInstanceId } from \"./SwitchingDevice.provider\"\nimport {\n getSwitchingPaneItemNameForDisplay,\n getSwitchableOutputStateTopics,\n SWITCHABLE_OUTPUT_TREES,\n SwitchableOutputId,\n SwitchableOutputState,\n SwitchableOutputTree,\n GenericInputState,\n SwitchingPaneItem,\n} from \"./SwitchableOutput.provider\"\nimport { getGenericInputStateTopics, GenericInputId } from \"./GenericInput.provider\"\nimport {\n GenericInputType,\n remapGenericInputType,\n SwitchableOutputType,\n SwitchableOutputVisibility,\n SWITCHABLE_OUTPUT_FUNCTION,\n SWITCHABLE_OUTPUT_VISIBILITY,\n} from \"../../utils/constants\"\n\nconst hasMessages = (messages: Record<string, string> | undefined) => messages && Object.keys(messages).length > 0\n\nexport const useSwitchingPane = (gxDeviceRelaysGroupName: string) => {\n const store = useSwitchingPaneStore()\n const mqtt = useMqtt()\n\n const topics = useMemo(\n () => ({\n systemOutputs: `N/${mqtt.portalId}/system/+/SwitchableOutput/+/Settings/+`,\n switchOutputs: `N/${mqtt.portalId}/switch/+/SwitchableOutput/+/Settings/+`,\n genericInputs: `N/${mqtt.portalId}/switch/+/GenericInput/+/Settings/+`,\n // NOTE: deliberately precise (not `switch/+`) so that high-frequency operational\n // NOTE: values (State, Dimming, Status, ...) do not invalidate the grouping below\n switchingDeviceInstances: `N/${mqtt.portalId}/switch/+/DeviceInstance`,\n switchingDeviceCustomNames: `N/${mqtt.portalId}/switch/+/CustomName`,\n switchingDeviceProductNames: `N/${mqtt.portalId}/switch/+/ProductName`,\n }),\n [mqtt.portalId]\n )\n\n const messagesForSystemOutputs = mqtt.messagesByWildcard(topics.systemOutputs)\n const messagesForSwitchOutputs = mqtt.messagesByWildcard(topics.switchOutputs)\n const messagesForInputs = mqtt.messagesByWildcard(topics.genericInputs)\n const messagesForSwitchingDeviceInstances = mqtt.messagesByWildcard(topics.switchingDeviceInstances)\n const messagesForSwitchingDeviceCustomNames = mqtt.messagesByWildcard(topics.switchingDeviceCustomNames)\n const messagesForSwitchingDeviceProductNames = mqtt.messagesByWildcard(topics.switchingDeviceProductNames)\n\n useEffect(() => {\n if (\n !hasMessages(messagesForSystemOutputs) &&\n !hasMessages(messagesForSwitchOutputs) &&\n !hasMessages(messagesForInputs)\n ) {\n Logger.log(\"Waiting for switchable outputs or generic inputs...\")\n return\n }\n\n // --- Phase A: Extract comparison arrays from wildcard messages (cheap) ---\n\n const messagesForOutputs = { ...messagesForSystemOutputs, ...messagesForSwitchOutputs }\n\n const outputGroupTopics = Object.keys(messagesForOutputs)\n .filter((k) => k.endsWith(\"/Settings/Group\"))\n .sort()\n\n const customGroupAssignments = outputGroupTopics.map((t) => messagesForOutputs[t])\n const outputTypes = outputGroupTopics.map(\n (t) => Number(messagesForOutputs[`${t.slice(0, -\"/Group\".length)}/Type`]) as SwitchableOutputType\n )\n const outputNames = outputGroupTopics.map((t) => messagesForOutputs[`${t.slice(0, -\"/Group\".length)}/CustomName`])\n const outputVisibilityFlags = outputGroupTopics.map(\n (t) => Number(messagesForOutputs[`${t.slice(0, -\"/Group\".length)}/ShowUIControl`]) as SwitchableOutputVisibility\n )\n const outputFunctions = outputGroupTopics.map((t) =>\n Number(messagesForOutputs[`${t.slice(0, -\"/Group\".length)}/Function`])\n )\n\n const inputGroupTopics = Object.keys(messagesForInputs)\n .filter((k) => k.endsWith(\"/Settings/Group\"))\n .sort()\n\n const genericInputGroupAssignments = inputGroupTopics.map((t) => messagesForInputs[t])\n const genericInputTypes = inputGroupTopics.map(\n (t) => Number(messagesForInputs[`${t.slice(0, -\"/Group\".length)}/Type`]) as GenericInputType\n )\n const genericInputNames = inputGroupTopics.map(\n (t) => messagesForInputs[`${t.slice(0, -\"/Group\".length)}/CustomName`]\n )\n const genericInputVisibilityFlags = inputGroupTopics.map(\n (t) => Number(messagesForInputs[`${t.slice(0, -\"/Group\".length)}/ShowUIInput`]) as SwitchableOutputVisibility\n )\n\n const switchingDevices = Object.keys(messagesForSwitchingDeviceInstances).sort()\n const switchingDeviceNames = switchingDevices.map((t) => {\n const prefix = t.slice(0, -\"/DeviceInstance\".length)\n return (\n messagesForSwitchingDeviceCustomNames[`${prefix}/CustomName`] ||\n messagesForSwitchingDeviceProductNames[`${prefix}/ProductName`]\n )\n })\n\n // --- Phase B: comparison guard, batched in a single action ---\n\n runInAction(() => {\n const groupAssignmentsChanged = !arraysEqual(store.customGroupAssignments, customGroupAssignments)\n if (groupAssignmentsChanged) store.setCustomGroupAssignments(customGroupAssignments)\n\n const outputTypesChanged = !arraysEqual(store.outputTypes, outputTypes)\n if (outputTypesChanged) store.setOutputTypes(outputTypes)\n\n const outputNamesChanged = !arraysEqual(store.outputNames, outputNames)\n if (outputNamesChanged) store.setOutputNames(outputNames)\n\n const outputVisibilityFlagsChanged = !arraysEqual(store.outputVisibilityFlags, outputVisibilityFlags)\n if (outputVisibilityFlagsChanged) store.setOutputVisibilityFlags(outputVisibilityFlags)\n\n const outputFunctionsChanged = !arraysEqual(store.outputFunctions, outputFunctions)\n if (outputFunctionsChanged) store.setOutputFunctions(outputFunctions)\n\n const switchingDevicesChanged = !arraysEqual(store.switchingDevices, switchingDevices)\n if (switchingDevicesChanged) store.setSwitchingDevices(switchingDevices)\n\n const switchingDeviceNamesChanged = !arraysEqual(store.switchingDeviceNames, switchingDeviceNames)\n if (switchingDeviceNamesChanged) store.setSwitchingDeviceNames(switchingDeviceNames)\n\n const giGroupAssignmentsChanged = !arraysEqual(store.genericInputGroupAssignments, genericInputGroupAssignments)\n if (giGroupAssignmentsChanged) store.setGenericInputGroupAssignments(genericInputGroupAssignments)\n\n const giTypesChanged = !arraysEqual(store.genericInputTypes, genericInputTypes)\n if (giTypesChanged) store.setGenericInputTypes(genericInputTypes)\n\n const giNamesChanged = !arraysEqual(store.genericInputNames, genericInputNames)\n if (giNamesChanged) store.setGenericInputNames(genericInputNames)\n\n const giVisibilityFlagsChanged = !arraysEqual(store.genericInputVisibilityFlags, genericInputVisibilityFlags)\n if (giVisibilityFlagsChanged) store.setGenericInputVisibilityFlags(genericInputVisibilityFlags)\n\n const isInitialLoad =\n store.customGroupAssignments.length === 0 &&\n store.outputTypes.length === 0 &&\n store.switchingDevices.length === 0 &&\n store.genericInputGroupAssignments.length === 0\n\n if (!isInitialLoad) {\n if (groupAssignmentsChanged) Logger.log(`Switchable outputs group assignments changed, recomputing...`)\n if (outputTypesChanged) Logger.log(`Switchable outputs types changed, recomputing...`)\n if (outputNamesChanged) Logger.log(`Switchable outputs names changed, recomputing...`)\n if (outputVisibilityFlagsChanged) Logger.log(`Switchable outputs visibility flags changed, recomputing...`)\n if (outputFunctionsChanged) Logger.log(`Switchable outputs functions changed, recomputing...`)\n if (switchingDevicesChanged) Logger.log(`Switching devices changed, recomputing...`)\n if (switchingDeviceNamesChanged) Logger.log(`Switching device names changed, recomputing...`)\n if (giGroupAssignmentsChanged) Logger.log(`Generic input group assignments changed, recomputing...`)\n if (giTypesChanged) Logger.log(`Generic input types changed, recomputing...`)\n if (giNamesChanged) Logger.log(`Generic input names changed, recomputing...`)\n if (giVisibilityFlagsChanged) Logger.log(`Generic input visibility flags changed, recomputing...`)\n }\n\n if (\n groupAssignmentsChanged ||\n outputTypesChanged ||\n outputNamesChanged ||\n outputVisibilityFlagsChanged ||\n outputFunctionsChanged ||\n switchingDevicesChanged ||\n switchingDeviceNamesChanged ||\n giGroupAssignmentsChanged ||\n giTypesChanged ||\n giNamesChanged ||\n giVisibilityFlagsChanged\n ) {\n const items: { groupName: string; item: SwitchingPaneItem }[] = []\n\n for (const topic of outputGroupTopics) {\n const info = extractSwitchableOutputInfo(topic)\n\n const { deviceName, output } = untracked(() => {\n const device = mqtt.messagesByTopics(\n getSwitchingDeviceStateTopics(mqtt.portalId, info.tree, info.deviceId)\n ) as unknown as Record<string, string>\n const out = mqtt.messagesByTopics(\n getSwitchableOutputStateTopics(mqtt.portalId, info.tree, info.deviceId, info.outputId)\n ) as unknown as SwitchableOutputState\n return {\n deviceName: device.customName || device.productName || gxDeviceRelaysGroupName,\n output: out,\n }\n })\n\n if (\n !(\n output.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE ||\n output.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE_LOCAL_UI\n )\n ) {\n continue\n }\n\n // GX system relays: only show when Function is Manual (matching gui-v2)\n if (\n info.tree === \"system\" &&\n output.function != null &&\n output.function !== SWITCHABLE_OUTPUT_FUNCTION.MANUAL\n ) {\n continue\n }\n\n const customGroup = (messagesForOutputs[topic] ?? \"\").trim()\n\n items.push({\n groupName: customGroup === \"\" ? deviceName : customGroup,\n item: {\n ...output,\n kind: \"switchableOutput\",\n tree: info.tree,\n deviceId: info.deviceId,\n outputId: info.outputId,\n parentDeviceName: deviceName as string,\n },\n })\n }\n\n for (const topic of inputGroupTopics) {\n const info = extractGenericInputInfo(topic)\n\n const { deviceName, input } = untracked(() => {\n const device = mqtt.messagesByTopics(\n getSwitchingDeviceStateTopics(mqtt.portalId, info.tree, info.deviceId)\n ) as unknown as Record<string, string>\n const inp = mqtt.messagesByTopics(\n getGenericInputStateTopics(mqtt.portalId, info.tree, info.deviceId, info.inputId)\n ) as unknown as GenericInputState\n return {\n deviceName: device.customName || device.productName || gxDeviceRelaysGroupName,\n input: inp,\n }\n })\n\n if (\n !(\n input.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE ||\n input.showUIControl & SWITCHABLE_OUTPUT_VISIBILITY.VISIBLE_LOCAL_UI\n )\n ) {\n continue\n }\n\n const customGroup = (messagesForInputs[topic] ?? \"\").trim()\n\n items.push({\n groupName: customGroup === \"\" ? deviceName : customGroup,\n item: {\n ...input,\n kind: \"genericInput\",\n tree: info.tree,\n deviceId: info.deviceId,\n outputId: info.inputId,\n parentDeviceName: deviceName as string,\n type: remapGenericInputType(input.type as number),\n },\n })\n }\n\n const groups: { [key: string]: SwitchingPaneItem[] } = {}\n for (const { groupName, item } of items) {\n ;(groups[groupName] ||= []).push(item)\n }\n\n for (const arr of Object.values(groups)) {\n arr.sort((a, b) => {\n const aName = getSwitchingPaneItemNameForDisplay(a, a.parentDeviceName)\n const bName = getSwitchingPaneItemNameForDisplay(b, b.parentDeviceName)\n return aName.localeCompare(bName)\n })\n }\n\n Logger.log(`New switching pane groups: ${JSON.stringify(Object.keys(groups))}`)\n store.setGroups(groups)\n }\n })\n }, [\n messagesForSystemOutputs,\n messagesForSwitchOutputs,\n messagesForInputs,\n messagesForSwitchingDeviceInstances,\n messagesForSwitchingDeviceCustomNames,\n messagesForSwitchingDeviceProductNames,\n gxDeviceRelaysGroupName,\n mqtt,\n store,\n ])\n\n return store\n}\n\nexport function 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\n const outputStart = topic.indexOf(\"/SwitchableOutput/\") + 18\n\n return {\n tree: (match?.[1] as SwitchableOutputTree) ?? null,\n deviceId: Number(topic.substring(switchStart, topic.indexOf(\"/\", switchStart))) as SwitchingDeviceInstanceId,\n outputId: topic.substring(outputStart, topic.indexOf(\"/\", outputStart)) as SwitchableOutputId,\n }\n}\n\nexport function extractGenericInputInfo(topic: string) {\n const pattern = new RegExp(`/(${SWITCHABLE_OUTPUT_TREES.join(\"|\")})/`)\n const match = topic.match(pattern)\n const treeEnd = match ? match.index! + match[0].length : -1\n const inputStart = topic.indexOf(\"/GenericInput/\") + 14\n\n return {\n tree: (match?.[1] as SwitchableOutputTree) ?? null,\n deviceId: Number(topic.substring(treeEnd, topic.indexOf(\"/\", treeEnd))) as SwitchingDeviceInstanceId,\n inputId: topic.substring(inputStart, topic.indexOf(\"/\", inputStart)) as GenericInputId,\n }\n}\n\nexport function arraysEqual<T>(a: T[], b: T[]): boolean {\n if (a.length !== b.length) return false\n return a.every((element, index) => Object.is(element, b[index]))\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SwitchingPane.store.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchingPane/SwitchingPane.store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAI1G,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAAA;KAAE,CAAA;IAE9C,sBAAsB,EAAE,MAAM,EAAE,CAAA;IAEhC,WAAW,EAAE,oBAAoB,EAAE,CAAA;IAEnC,WAAW,EAAE,MAAM,EAAE,CAAA;IAErB,qBAAqB,EAAE,0BAA0B,EAAE,CAAA;IAEnD,eAAe,EAAE,MAAM,EAAE,CAAA;IAEzB,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAE1B,oBAAoB,EAAE,MAAM,EAAE,CAAA;IAE9B,4BAA4B,EAAE,MAAM,EAAE,CAAA;IAEtC,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;IAErC,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAE3B,2BAA2B,EAAE,0BAA0B,EAAE,CAAA;CAC1D;AAED,qBAAa,kBAAkB;IAC7B,M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;;mBAAiC,CAAC,KAAmC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,2BAA2B,GAAG,KAAK,CAAC;WAAA;QA3BlH,kBAAkB,CAAC,IAAI,EAAE;YACvB,SAAS,EAAE,MAAM;YACjB,yBAAyB,EAAE,MAAM;YACjC,cAAc,EAAE,MAAM;YACtB,wBAAwB,EAAE,MAAM;YAChC,kBAAkB,EAAE,MAAM;YAC1B,mBAAmB,EAAE,MAAM;YAC3B,uBAAuB,EAAE,MAAM;YAC/B,+BAA+B,EAAE,MAAM;YACvC,oBAAoB,EAAE,MAAM;YAC5B,oBAAoB,EAAE,MAAM;YAC5B,8BAA8B,EAAE,MAAM;SACvC,CAAC,CAAA;IACJ,CAAC;CAeF;AAED,SAAS,eAAe;IACtB,MAAM,MAAM,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,kBAAkB,EAAE,CAAA;IAChD,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,qBAAqB;IACnC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,EAAE,EAAE,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import { action, makeAutoObservable } from \"mobx\"\nimport { useMemo } from \"react\"\nimport { SwitchingPaneItem } from \"./SwitchableOutput.provider\"\nimport { GenericInputType, SwitchableOutputType, SwitchableOutputVisibility } from \"../../utils/constants\"\n\nlet store: SwitchingPaneStore\n\nexport interface SwitchingPaneState {\n groups: { [key: string]: SwitchingPaneItem[] }\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: SwitchableOutputVisibility[]\n // function of switchable outputs sorted by their topic path\n outputFunctions: number[]\n // switching devices\n switchingDevices: string[]\n // switching devices custom names\n switchingDeviceNames: string[]\n // custom group assignments for available generic inputs sorted by their topic path\n genericInputGroupAssignments: string[]\n // types of generic inputs sorted by their topic path\n genericInputTypes: GenericInputType[]\n // custom names of generic inputs sorted by their topic path\n genericInputNames: string[]\n // visibility status of generic inputs sorted by their topic path\n genericInputVisibilityFlags: SwitchableOutputVisibility[]\n}\n\nexport class SwitchingPaneStore {\n groups: { [key: string]: SwitchingPaneItem[] } = {}\n customGroupAssignments: string[] = []\n outputTypes: SwitchableOutputType[] = []\n outputNames: string[] = []\n outputVisibilityFlags: SwitchableOutputVisibility[] = []\n outputFunctions: number[] = []\n switchingDevices: string[] = []\n switchingDeviceNames: string[] = []\n genericInputGroupAssignments: string[] = []\n genericInputTypes: GenericInputType[] = []\n genericInputNames: string[] = []\n genericInputVisibilityFlags: SwitchableOutputVisibility[] = []\n\n constructor() {\n makeAutoObservable(this, {\n setGroups: action,\n setCustomGroupAssignments: action,\n setOutputTypes: action,\n setOutputVisibilityFlags: action,\n setOutputFunctions: action,\n setSwitchingDevices: action,\n setSwitchingDeviceNames: action,\n setGenericInputGroupAssignments: action,\n setGenericInputTypes: action,\n setGenericInputNames: action,\n setGenericInputVisibilityFlags: action,\n })\n }\n\n setGroups = (groups: { [key: string]: SwitchingPaneItem[] }) => (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: SwitchableOutputVisibility[]) =>\n (this.outputVisibilityFlags = outputVisibilityFlags)\n setOutputFunctions = (outputFunctions: number[]) => (this.outputFunctions = outputFunctions)\n setSwitchingDevices = (switchingDevices: string[]) => (this.switchingDevices = switchingDevices)\n setSwitchingDeviceNames = (switchingDeviceNames: string[]) => (this.switchingDeviceNames = switchingDeviceNames)\n setGenericInputGroupAssignments = (assignments: string[]) => (this.genericInputGroupAssignments = assignments)\n setGenericInputTypes = (types: GenericInputType[]) => (this.genericInputTypes = types)\n setGenericInputNames = (names: string[]) => (this.genericInputNames = names)\n setGenericInputVisibilityFlags = (flags: SwitchableOutputVisibility[]) => (this.genericInputVisibilityFlags = flags)\n}\n\nfunction initializeStore() {\n const _store = store ?? new SwitchingPaneStore()\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 useSwitchingPaneStore() {\n return useMemo(() => initializeStore(), [])\n}\n"]}
1
+ {"version":3,"file":"SwitchingPane.store.js","sourceRoot":"/","sources":["src/Modules/SwitchingPane/SwitchingPane.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,KAAyB,CAAA;AAiB7B,MAAM,OAAO,kBAAkB;IAc7B;QAbA;;;;mBAAiD,EAAE;WAAA;QACnD;;;;mBAAmC,EAAE;WAAA;QACrC;;;;mBAAsC,EAAE;WAAA;QACxC;;;;mBAAwB,EAAE;WAAA;QAC1B;;;;mBAAsD,EAAE;WAAA;QACxD;;;;mBAA4B,EAAE;WAAA;QAC9B;;;;mBAA6B,EAAE;WAAA;QAC/B;;;;mBAAiC,EAAE;WAAA;QACnC;;;;mBAAyC,EAAE;WAAA;QAC3C;;;;mBAAwC,EAAE;WAAA;QAC1C;;;;mBAA8B,EAAE;WAAA;QAChC;;;;mBAA4D,EAAE;WAAA;QAkB9D;;;;mBAAY,CAAC,MAA8C,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;WAAA;QACtF;;;;mBAA4B,CAAC,WAAqB,EAAE,E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AC1B,mBAAmB,EAAE,MAAM;YAC3B,uBAAuB,EAAE,MAAM;YAC/B,+BAA+B,EAAE,MAAM;YACvC,oBAAoB,EAAE,MAAM;YAC5B,oBAAoB,EAAE,MAAM;YAC5B,8BAA8B,EAAE,MAAM;SACvC,CAAC,CAAA;IACJ,CAAC;CAeF;AAED,SAAS,eAAe;IACtB,MAAM,MAAM,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,kBAAkB,EAAE,CAAA;IAChD,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,qBAAqB;IACnC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,EAAE,EAAE,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import { action, makeAutoObservable } from \"mobx\"\nimport { useMemo } from \"react\"\nimport { SwitchingPaneItem } from \"./SwitchableOutput.provider\"\nimport { GenericInputType, SwitchableOutputType, SwitchableOutputVisibility } from \"../../utils/constants\"\n\nlet store: SwitchingPaneStore\n\nexport interface SwitchingPaneState {\n groups: { [key: string]: SwitchingPaneItem[] }\n customGroupAssignments: string[]\n outputTypes: SwitchableOutputType[]\n outputNames: string[]\n outputVisibilityFlags: SwitchableOutputVisibility[]\n outputFunctions: number[]\n switchingDevices: string[]\n switchingDeviceNames: string[]\n genericInputGroupAssignments: string[]\n genericInputTypes: GenericInputType[]\n genericInputNames: string[]\n genericInputVisibilityFlags: SwitchableOutputVisibility[]\n}\n\nexport class SwitchingPaneStore {\n groups: { [key: string]: SwitchingPaneItem[] } = {}\n customGroupAssignments: string[] = []\n outputTypes: SwitchableOutputType[] = []\n outputNames: string[] = []\n outputVisibilityFlags: SwitchableOutputVisibility[] = []\n outputFunctions: number[] = []\n switchingDevices: string[] = []\n switchingDeviceNames: string[] = []\n genericInputGroupAssignments: string[] = []\n genericInputTypes: GenericInputType[] = []\n genericInputNames: string[] = []\n genericInputVisibilityFlags: SwitchableOutputVisibility[] = []\n\n constructor() {\n makeAutoObservable(this, {\n setGroups: action,\n setCustomGroupAssignments: action,\n setOutputTypes: action,\n setOutputVisibilityFlags: action,\n setOutputFunctions: action,\n setSwitchingDevices: action,\n setSwitchingDeviceNames: action,\n setGenericInputGroupAssignments: action,\n setGenericInputTypes: action,\n setGenericInputNames: action,\n setGenericInputVisibilityFlags: action,\n })\n }\n\n setGroups = (groups: { [key: string]: SwitchingPaneItem[] }) => (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: SwitchableOutputVisibility[]) =>\n (this.outputVisibilityFlags = outputVisibilityFlags)\n setOutputFunctions = (outputFunctions: number[]) => (this.outputFunctions = outputFunctions)\n setSwitchingDevices = (switchingDevices: string[]) => (this.switchingDevices = switchingDevices)\n setSwitchingDeviceNames = (switchingDeviceNames: string[]) => (this.switchingDeviceNames = switchingDeviceNames)\n setGenericInputGroupAssignments = (assignments: string[]) => (this.genericInputGroupAssignments = assignments)\n setGenericInputTypes = (types: GenericInputType[]) => (this.genericInputTypes = types)\n setGenericInputNames = (names: string[]) => (this.genericInputNames = names)\n setGenericInputVisibilityFlags = (flags: SwitchableOutputVisibility[]) => (this.genericInputVisibilityFlags = flags)\n}\n\nfunction initializeStore() {\n const _store = store ?? new SwitchingPaneStore()\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 useSwitchingPaneStore() {\n return useMemo(() => initializeStore(), [])\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Tanks.provider.d.ts","sourceRoot":"/","sources":["src/Modules/Tanks/Tanks.provider.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,QAAQ,0CAsCpB,CAAA"}
1
+ {"version":3,"file":"Tanks.provider.d.ts","sourceRoot":"/","sources":["src/Modules/Tanks/Tanks.provider.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,QAAQ,0CAuCpB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { autorun } from "mobx";
1
+ import { untracked } from "mobx";
2
2
  import Logger from "../../utils/logger";
3
3
  import { useMqtt } from "../Mqtt";
4
4
  import { getTankStateTopics } from "./Tank.provider";
@@ -13,24 +13,21 @@ export const useTanks = () => {
13
13
  const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId]);
14
14
  const messages = mqtt.messagesByWildcard(topics.tanks);
15
15
  useEffect(() => {
16
- if (!messages || Object.entries(messages).length === 0) {
16
+ if (!messages || Object.keys(messages).length === 0) {
17
17
  // Logger.log("Waiting for tanks...")
18
+ return;
18
19
  }
19
- else {
20
- const deviceInstances = Object.values(messages);
21
- const dispose = autorun(() => {
22
- const oldTanks = tanksStore.tanks;
23
- const newTanks = deviceInstances.map((tankInstanceId) => mqtt.messagesByTopics(getTankStateTopics(mqtt.portalId, tankInstanceId)));
24
- // TODO: check unordered structural identify of old and new state
25
- // TODO: to avoid unnecessary re-rendering: O(n^2) baby
26
- if (!oldTanks ||
27
- oldTanks.length !== newTanks.length ||
28
- !oldTanks.every((id) => deviceInstances.includes(id.instance))) {
29
- Logger.log(`New tanks instances: ${JSON.stringify(deviceInstances)}`);
30
- tanksStore.setTanks(newTanks);
31
- }
32
- });
33
- return () => dispose();
20
+ const deviceInstances = Object.values(messages);
21
+ const oldTanks = tanksStore.tanks;
22
+ const instanceSet = new Set(deviceInstances);
23
+ if (!oldTanks ||
24
+ oldTanks.length !== deviceInstances.length ||
25
+ !oldTanks.every((tank) => instanceSet.has(tank.instance))) {
26
+ Logger.log(`New tanks instances: ${JSON.stringify(deviceInstances)}`);
27
+ // NOTE: snapshot tank state untracked — per-tank values are observed live via useTank,
28
+ // NOTE: the store list only needs refreshing when the set of tanks changes
29
+ const newTanks = untracked(() => deviceInstances.map((tankInstanceId) => mqtt.messagesByTopics(getTankStateTopics(mqtt.portalId, tankInstanceId))));
30
+ tanksStore.setTanks(newTanks);
34
31
  }
35
32
  }, [messages, mqtt, tanksStore]);
36
33
  return tanksStore;
@@ -1 +1 @@
1
- {"version":3,"file":"Tanks.provider.js","sourceRoot":"/","sources":["src/Modules/Tanks/Tanks.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,kBAAkB,EAA6B,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE1C,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAElC,MAAM,SAAS,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,CAAC;QACzC,KAAK,EAAE,KAAK,QAAQ,wBAAwB;KAC7C,CAAC,CAAA;IAEF,MAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IACtB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEvE,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAEtD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,qCAAqC;QACvC,CAAC;aAAM,CAAC;YACN,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAqB,CAAA;YACnE,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE;gBAC3B,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAA;gBACjC,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CACtD,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAC/C,CAAA;gBAC3B,iEAAiE;gBACjE,uDAAuD;gBACvD,IACE,CAAC,QAAQ;oBACT,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM;oBACnC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAC9D,CAAC;oBACD,MAAM,CAAC,GAAG,CAAC,wBAAwB,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;oBACrE,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;gBAC/B,CAAC;YACH,CAAC,CAAC,CAAA;YACF,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAA;QACxB,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAA;IAEhC,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA","sourcesContent":["import { autorun } from \"mobx\"\nimport Logger from \"../../utils/logger\"\nimport { PortalId, useMqtt } from \"../Mqtt\"\nimport { getTankStateTopics, TankInstanceId, TankState } from \"./Tank.provider\"\nimport { useTanksStore } from \"./Tanks.store\"\nimport { useMemo, useEffect } from \"react\"\n\nexport const useTanks = () => {\n const tanksStore = useTanksStore()\n\n const getTopics = (portalId: PortalId) => ({\n tanks: `N/${portalId}/tank/+/DeviceInstance`,\n })\n\n const mqtt = useMqtt()\n const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId])\n\n const messages = mqtt.messagesByWildcard(topics.tanks)\n\n useEffect(() => {\n if (!messages || Object.entries(messages).length === 0) {\n // Logger.log(\"Waiting for tanks...\")\n } else {\n const deviceInstances = Object.values(messages) as TankInstanceId[]\n const dispose = autorun(() => {\n const oldTanks = tanksStore.tanks\n const newTanks = deviceInstances.map((tankInstanceId) =>\n mqtt.messagesByTopics(getTankStateTopics(mqtt.portalId, tankInstanceId))\n ) as unknown as TankState[]\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 !oldTanks ||\n oldTanks.length !== newTanks.length ||\n !oldTanks.every((id) => deviceInstances.includes(id.instance))\n ) {\n Logger.log(`New tanks instances: ${JSON.stringify(deviceInstances)}`)\n tanksStore.setTanks(newTanks)\n }\n })\n return () => dispose()\n }\n }, [messages, mqtt, tanksStore])\n\n return tanksStore\n}\n"]}
1
+ {"version":3,"file":"Tanks.provider.js","sourceRoot":"/","sources":["src/Modules/Tanks/Tanks.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAY,OAAO,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAA6B,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE1C,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAElC,MAAM,SAAS,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,CA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U,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAA;IAEhC,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA","sourcesContent":["import { untracked } from \"mobx\"\nimport Logger from \"../../utils/logger\"\nimport { PortalId, useMqtt } from \"../Mqtt\"\nimport { getTankStateTopics, TankInstanceId, TankState } from \"./Tank.provider\"\nimport { useTanksStore } from \"./Tanks.store\"\nimport { useMemo, useEffect } from \"react\"\n\nexport const useTanks = () => {\n const tanksStore = useTanksStore()\n\n const getTopics = (portalId: PortalId) => ({\n tanks: `N/${portalId}/tank/+/DeviceInstance`,\n })\n\n const mqtt = useMqtt()\n const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId])\n\n const messages = mqtt.messagesByWildcard(topics.tanks)\n\n useEffect(() => {\n if (!messages || Object.keys(messages).length === 0) {\n // Logger.log(\"Waiting for tanks...\")\n return\n }\n\n const deviceInstances = Object.values(messages) as TankInstanceId[]\n const oldTanks = tanksStore.tanks\n const instanceSet = new Set(deviceInstances)\n if (\n !oldTanks ||\n oldTanks.length !== deviceInstances.length ||\n !oldTanks.every((tank) => instanceSet.has(tank.instance))\n ) {\n Logger.log(`New tanks instances: ${JSON.stringify(deviceInstances)}`)\n // NOTE: snapshot tank state untracked — per-tank values are observed live via useTank,\n // NOTE: the store list only needs refreshing when the set of tanks changes\n const newTanks = untracked(() =>\n deviceInstances.map((tankInstanceId) =>\n mqtt.messagesByTopics(getTankStateTopics(mqtt.portalId, tankInstanceId))\n )\n ) as unknown as TankState[]\n tanksStore.setTanks(newTanks)\n }\n }, [messages, mqtt, tanksStore])\n\n return tanksStore\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Temperatures.provider.d.ts","sourceRoot":"/","sources":["src/Modules/Temperatures/Temperatures.provider.ts"],"names":[],"mappings":"AAOA,wBAAgB,eAAe,qDAsC9B"}
1
+ {"version":3,"file":"Temperatures.provider.d.ts","sourceRoot":"/","sources":["src/Modules/Temperatures/Temperatures.provider.ts"],"names":[],"mappings":"AAOA,wBAAgB,eAAe,qDAuC9B"}
@@ -3,7 +3,7 @@ import { useMqtt } from "../Mqtt";
3
3
  import { useTemperaturesStore } from "./Temperatures.store";
4
4
  import Logger from "../../utils/logger";
5
5
  import { getTemperatureStateTopics } from "./Temperature.provider";
6
- import { autorun } from "mobx";
6
+ import { untracked } from "mobx";
7
7
  export function useTemperatures() {
8
8
  const temperaturesStore = useTemperaturesStore();
9
9
  const mqtt = useMqtt();
@@ -13,24 +13,21 @@ export function useTemperatures() {
13
13
  const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId]);
14
14
  const messages = mqtt.messagesByWildcard(topics.temperatureInstances);
15
15
  useEffect(() => {
16
- if (!messages || Object.entries(messages).length === 0) {
16
+ if (!messages || Object.keys(messages).length === 0) {
17
17
  // Logger.log("Waiting for temperatures...");
18
+ return;
18
19
  }
19
- else {
20
- const deviceInstances = Object.values(messages);
21
- const dispose = autorun(() => {
22
- const oldTemperatures = temperaturesStore.temperatures;
23
- const newTemperatures = deviceInstances.map((temperatureInstanceId) => mqtt.messagesByTopics(getTemperatureStateTopics(mqtt.portalId, temperatureInstanceId)));
24
- // TODO: check unordered structural identify of old and new state
25
- // TODO: to avoid unnecessary re-rendering: O(n^2) baby
26
- if (!oldTemperatures ||
27
- oldTemperatures.length !== newTemperatures.length ||
28
- !oldTemperatures.every((id) => deviceInstances.includes(id.instance))) {
29
- Logger.log(`New temperatures instances: ${JSON.stringify(deviceInstances)}`);
30
- temperaturesStore.setTemperatures(newTemperatures);
31
- }
32
- });
33
- return () => dispose();
20
+ const deviceInstances = Object.values(messages);
21
+ const oldTemperatures = temperaturesStore.temperatures;
22
+ const instanceSet = new Set(deviceInstances);
23
+ if (!oldTemperatures ||
24
+ oldTemperatures.length !== deviceInstances.length ||
25
+ !oldTemperatures.every((temperature) => instanceSet.has(temperature.instance))) {
26
+ Logger.log(`New temperatures instances: ${JSON.stringify(deviceInstances)}`);
27
+ // NOTE: snapshot temperature state untracked — per-sensor values are observed live via useTemperature,
28
+ // NOTE: the store list only needs refreshing when the set of sensors changes
29
+ const newTemperatures = untracked(() => deviceInstances.map((temperatureInstanceId) => mqtt.messagesByTopics(getTemperatureStateTopics(mqtt.portalId, temperatureInstanceId))));
30
+ temperaturesStore.setTemperatures(newTemperatures);
34
31
  }
35
32
  }, [messages, mqtt, temperaturesStore]);
36
33
  return temperaturesStore;
@@ -1 +1 @@
1
- {"version":3,"file":"Temperatures.provider.js","sourceRoot":"/","sources":["src/Modules/Temperatures/Temperatures.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAY,OAAO,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,yBAAyB,EAA2C,MAAM,wBAAwB,CAAA;AAC3G,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,MAAM,UAAU,eAAe;IAC7B,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAA;IAChD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IAEtB,MAAM,SAAS,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,CAAC;QACzC,oBAAoB,EAAE,KAAK,QAAQ,+BAA+B;KACnE,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEvE,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAErE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,6CAA6C;QAC/C,CAAC;aAAM,CAAC;YACN,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAA4B,CAAA;YAC1E,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE;gBAC3B,MAAM,eAAe,GAAG,iBAAiB,CAAC,YAAY,CAAA;gBACtD,MAAM,eAAe,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,qBAAqB,EAAE,EAAE,CACpE,IAAI,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,IAAI,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CACtD,CAAA;gBAClC,iEAAiE;gBACjE,uDAAuD;gBACvD,IACE,CAAC,eAAe;oBAChB,eAAe,CAAC,MAAM,KAAK,eAAe,CAAC,MAAM;oBACjD,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EACrE,CAAC;oBACD,MAAM,CAAC,GAAG,CAAC,+BAA+B,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;oBAC5E,iBAAiB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;gBACpD,CAAC;YACH,CAAC,CAAC,CAAA;YACF,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAA;QACxB,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAA;IAEvC,OAAO,iBAAiB,CAAA;AAC1B,CAAC","sourcesContent":["import { useEffect, useMemo } from \"react\"\nimport { PortalId, useMqtt } from \"../Mqtt\"\nimport { useTemperaturesStore } from \"./Temperatures.store\"\nimport Logger from \"../../utils/logger\"\nimport { getTemperatureStateTopics, TemperatureInstanceId, TemperatureState } from \"./Temperature.provider\"\nimport { autorun } from \"mobx\"\n\nexport function useTemperatures() {\n const temperaturesStore = useTemperaturesStore()\n const mqtt = useMqtt()\n\n const getTopics = (portalId: PortalId) => ({\n temperatureInstances: `N/${portalId}/temperature/+/DeviceInstance`,\n })\n\n const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId])\n\n const messages = mqtt.messagesByWildcard(topics.temperatureInstances)\n\n useEffect(() => {\n if (!messages || Object.entries(messages).length === 0) {\n // Logger.log(\"Waiting for temperatures...\");\n } else {\n const deviceInstances = Object.values(messages) as TemperatureInstanceId[]\n const dispose = autorun(() => {\n const oldTemperatures = temperaturesStore.temperatures\n const newTemperatures = deviceInstances.map((temperatureInstanceId) =>\n mqtt.messagesByTopics(getTemperatureStateTopics(mqtt.portalId, temperatureInstanceId))\n ) as unknown as TemperatureState[]\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 !oldTemperatures ||\n oldTemperatures.length !== newTemperatures.length ||\n !oldTemperatures.every((id) => deviceInstances.includes(id.instance))\n ) {\n Logger.log(`New temperatures instances: ${JSON.stringify(deviceInstances)}`)\n temperaturesStore.setTemperatures(newTemperatures)\n }\n })\n return () => dispose()\n }\n }, [messages, mqtt, temperaturesStore])\n\n return temperaturesStore\n}\n"]}
1
+ {"version":3,"file":"Temperatures.provider.js","sourceRoot":"/","sources":["src/Modules/Temperatures/Temperatures.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAY,OAAO,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,yBAAyB,EAA2C,MAAM,wBAAwB,CAAA;AAC3G,OAAO,EAAE,SAAS,EAAE,MAAM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AAC,CAAC,qBAAqB,EAAE,EAAE,CAC5C,IAAI,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,IAAI,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CACvF,CAC+B,CAAA;YAClC,iBAAiB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;QACpD,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAA;IAEvC,OAAO,iBAAiB,CAAA;AAC1B,CAAC","sourcesContent":["import { useEffect, useMemo } from \"react\"\nimport { PortalId, useMqtt } from \"../Mqtt\"\nimport { useTemperaturesStore } from \"./Temperatures.store\"\nimport Logger from \"../../utils/logger\"\nimport { getTemperatureStateTopics, TemperatureInstanceId, TemperatureState } from \"./Temperature.provider\"\nimport { untracked } from \"mobx\"\n\nexport function useTemperatures() {\n const temperaturesStore = useTemperaturesStore()\n const mqtt = useMqtt()\n\n const getTopics = (portalId: PortalId) => ({\n temperatureInstances: `N/${portalId}/temperature/+/DeviceInstance`,\n })\n\n const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId])\n\n const messages = mqtt.messagesByWildcard(topics.temperatureInstances)\n\n useEffect(() => {\n if (!messages || Object.keys(messages).length === 0) {\n // Logger.log(\"Waiting for temperatures...\");\n return\n }\n\n const deviceInstances = Object.values(messages) as TemperatureInstanceId[]\n const oldTemperatures = temperaturesStore.temperatures\n const instanceSet = new Set(deviceInstances)\n if (\n !oldTemperatures ||\n oldTemperatures.length !== deviceInstances.length ||\n !oldTemperatures.every((temperature) => instanceSet.has(temperature.instance))\n ) {\n Logger.log(`New temperatures instances: ${JSON.stringify(deviceInstances)}`)\n // NOTE: snapshot temperature state untracked — per-sensor values are observed live via useTemperature,\n // NOTE: the store list only needs refreshing when the set of sensors changes\n const newTemperatures = untracked(() =>\n deviceInstances.map((temperatureInstanceId) =>\n mqtt.messagesByTopics(getTemperatureStateTopics(mqtt.portalId, temperatureInstanceId))\n )\n ) as unknown as TemperatureState[]\n temperaturesStore.setTemperatures(newTemperatures)\n }\n }, [messages, mqtt, temperaturesStore])\n\n return temperaturesStore\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@victronenergy/mfd-modules",
3
- "version": "11.1.5",
3
+ "version": "11.1.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "js-cookie": "^3.0.8",
27
27
  "localforage": "^1.10.0",
28
28
  "lodash-es": "^4.18.1",
29
- "mobx": "^6.16.0",
29
+ "mobx": "^6.16.1",
30
30
  "mobx-persist-store": "^1.1.8",
31
31
  "mobx-utils": "^6.1.1",
32
32
  "mqtt": "^4.3.8"
@@ -38,7 +38,7 @@
38
38
  "@testing-library/react": "^16.3.2",
39
39
  "@types/js-cookie": "^3.0.6",
40
40
  "@types/lodash-es": "^4.17.12",
41
- "@types/react": "^19.2.16",
41
+ "@types/react": "^19.2.17",
42
42
  "es-check": "^9.6.4",
43
43
  "eslint": "^10.4.1",
44
44
  "eslint-config-prettier": "^10.1.8",
@@ -46,12 +46,12 @@
46
46
  "eslint-plugin-prettier": "^5.5.6",
47
47
  "eslint-plugin-react-hooks": "^7.1.1",
48
48
  "jsdom": "^29.1.1",
49
- "prettier": "^3.8.3",
49
+ "prettier": "^3.8.4",
50
50
  "react": "^19.2.7",
51
51
  "react-dom": "^19.2.7",
52
52
  "semantic-release": "^25.0.3",
53
53
  "typescript": "^6.0.3",
54
- "typescript-eslint": "^8.60.1",
54
+ "typescript-eslint": "^8.61.0",
55
55
  "vitest": "^4.1.8"
56
56
  },
57
57
  "peerDependencies": {