@victronenergy/mfd-modules 9.2.3 → 9.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/src/Modules/Mqtt/Mqtt.store.d.ts.map +1 -1
  2. package/dist/src/Modules/Mqtt/Mqtt.store.js +1 -0
  3. package/dist/src/Modules/Mqtt/Mqtt.store.js.map +1 -1
  4. package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.d.ts +69 -0
  5. package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.d.ts.map +1 -0
  6. package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.js +45 -0
  7. package/dist/src/Modules/SwitchableOutputs/SwitchableOutput.provider.js.map +1 -0
  8. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.d.ts +2 -0
  9. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.d.ts.map +1 -0
  10. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js +81 -0
  11. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.provider.js.map +1 -0
  12. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.d.ts +22 -0
  13. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.d.ts.map +1 -0
  14. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.js +49 -0
  15. package/dist/src/Modules/SwitchableOutputs/SwitchableOutputs.store.js.map +1 -0
  16. package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.d.ts +22 -0
  17. package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.d.ts.map +1 -0
  18. package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.js +46 -0
  19. package/dist/src/Modules/SwitchableOutputs/SwitchingDevice.provider.js.map +1 -0
  20. package/dist/src/Modules/SwitchableOutputs/SwitchingDevices.store.d.ts +11 -0
  21. package/dist/src/Modules/SwitchableOutputs/SwitchingDevices.store.d.ts.map +1 -0
  22. package/dist/src/Modules/SwitchableOutputs/SwitchingDevices.store.js +37 -0
  23. package/dist/src/Modules/SwitchableOutputs/SwitchingDevices.store.js.map +1 -0
  24. package/dist/src/Modules/SwitchableOutputs/index.d.ts +6 -0
  25. package/dist/src/Modules/SwitchableOutputs/index.d.ts.map +1 -0
  26. package/dist/src/Modules/SwitchableOutputs/index.js +6 -0
  27. package/dist/src/Modules/SwitchableOutputs/index.js.map +1 -0
  28. package/dist/src/index.d.ts +1 -0
  29. package/dist/src/index.d.ts.map +1 -1
  30. package/dist/src/index.js +1 -0
  31. package/dist/src/index.js.map +1 -1
  32. package/dist/src/utils/constants.d.ts +26 -0
  33. package/dist/src/utils/constants.d.ts.map +1 -1
  34. package/dist/src/utils/constants.js +26 -0
  35. package/dist/src/utils/constants.js.map +1 -1
  36. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Mqtt.store.d.ts","sourceRoot":"/","sources":["src/Modules/Mqtt/Mqtt.store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,qBAAqB,EAAE,UAAU,EAAC,MAAM,MAAM,CAAA;AACtD,OAAO,EAAC,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAU,MAAM,EAAC,MAAM,SAAS,CAAA;AAQ3E,qBAAa,SAAS;IAClB,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAoB;IAClC,QAAQ,EAAE,YAAY,CAAK;IAC3B,YAAY,EAAE,YAAY,CAAK;IAC/B,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAoB;IACjD,QAAQ,EAAE,QAAQ,CAAA;IAClB,QAAQ,EAAE,MAAM,CAA0C;IAC1D,mBAAmB,EAAE,GAAG,CAAA;IACxB,WAAW,EAAE,GAAG,CAAA;IAChB,2BAA2B,EAAE,MAAM,CAA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A2BD,wBAAgB,OAAO,cAEtB"}
@@ -417,6 +417,7 @@ var MqttStore = /** @class */ (function () {
417
417
  "N/".concat(_this.portalId, "/inverter/#"),
418
418
  "N/".concat(_this.portalId, "/tank/#"),
419
419
  "N/".concat(_this.portalId, "/temperature/#"),
420
+ "N/".concat(_this.portalId, "/switch/#"),
420
421
  "N/".concat(_this.portalId, "/full_publish_completed")
421
422
  ];
422
423
  (_a = _this.client) === null || _a === void 0 ? void 0 : _a.subscribe(topics, function (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"Mqtt.store.js","sourceRoot":"/","sources":["src/Modules/Mqtt/Mqtt.store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAC,MAAM,MAAM,CAAA;AAC9D,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAsC,MAAM,EAAS,MAAM,SAAS,CAAA;AAC3E,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAA;AAC7B,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAA;AAEhC,IAAI,KAAgB,CAAA;AAEpB;IA8EI;QAAA,iBAcC;QA3FD;;;;;WAA0B;QAC1B;;;;;WAA+B;QAC/B;;;;mBAAiB,MAAM,CAAC,UAAU;WAAA;QAClC;;;;mBAAyB,EAAE;WAAA;QAC3B;;;;mBAA6B,EAAE;WAAA;QAC/B;;;;mBAAgC,IAAI,GAAG,EAAU;WAAA;QACjD;;;;;WAAkB;QAClB;;;;mBAAmB,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAA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Y,EAAE,CAAS,EAAE,QAAgB;IAC1D,OAAO,IAAI,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,eAAe;IACpB,IAAM,MAAM,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,SAAS,EAAE,CAAA;IACvC,4CAA4C;IAC5C,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,MAAM,CAAA;IAChD,sCAAsC;IACtC,IAAI,CAAC,KAAK;QAAE,KAAK,GAAG,MAAM,CAAA;IAE1B,OAAO,MAAM,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,OAAO;IACnB,OAAO,OAAO,CAAC,cAAM,OAAA,eAAe,EAAE,EAAjB,CAAiB,EAAE,EAAE,CAAC,CAAA;AAC/C,CAAC","sourcesContent":["import {comparer, makeAutoObservable, runInAction} from \"mobx\"\nimport {computedFn} from \"mobx-utils\"\nimport * as mqtt from \"mqtt\"\nimport {IClientPublishOptions, MqttClient} from \"mqtt\"\nimport {MqttMessage, MqttMessages, PortalId, STATUS, Topics} from \"../Mqtt\"\nimport Logger from \"../../utils/logger\"\nimport {getMessageJson} from \"../../utils/util\"\nimport {useMemo} from \"react\"\nimport {assign} from \"lodash-es\"\n\nlet store: MqttStore\n\nexport class MqttStore {\n client?: MqttClient | null\n error?: object | null | boolean\n status: string = STATUS.CONNECTING\n messages: MqttMessages = {}\n messageQueue: MqttMessages = {}\n topicsSubscribed: Set<string> = new Set<string>()\n portalId: PortalId\n uniqueId: string = Math.random().toString(16).substr(2, 8)\n keepAliveHandlerRef: any\n queueWorker: any\n meanQueueWorkerPassDuration: number = 0\n\n // Use comparer.identity to check the message we get for given topic.\n // Will cause re-render when new message for given topic arrives.\n // We rely on the fact that MQTT will only re-send a message when it\n // changes, and on full keep alive only.\n messageFromTopic = computedFn((topic?: string) => {\n // Logger.log(`DEBUG: messageFromTopic: ${JSON.stringify(topic)}`)\n // trace()\n return topic ? this.messages[topic] : undefined\n }, { name: \"Mqtt.store.messageFromTopic\", equals: comparer.identity })\n\n // Use comparer.identity to check the messages we get for given topics.\n // Will cause re-render when any new message for one of the topics arrives.\n // We rely on the fact that MQTT will only re-send a message when it\n // changes, and on full keep alive only.\n messagesByTopics = computedFn((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 }, { name: \"Mqtt.store.messagesByTopics\", equals: comparer.identity })\n\n // Use comparer.identity to check the messages we get for given topics.\n // Will cause re-render when any new message for one of the topic arrives,\n // or when we receive a new (yet unseen) topic.\n // We rely on the fact that MQTT will only re-send a message when it\n // changes, and on full keep alive\n // Only access Object.keys(this.messages),\n // and this.messages[k], where k matches the wildcard regex,\n // to make sure we invalidate:\n // - when new topics arrive\n // - when message with matching topic changes\n messagesByWildcard = computedFn((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(([_, message]) =>\n message !== undefined && message !== null\n && (!Array.isArray(message) || (message.length !== 0 && !message.every((v) => v === undefined || v === null)))\n ),\n )\n }, { name: \"Mqtt.store.messagesByWildcard\", equals: comparer.identity })\n\n constructor() {\n makeAutoObservable(this, {\n messageQueue: false,\n setupKeepaliveTimer: false,\n clearKeepaliveTimer: false,\n sendFullKeepalive: false,\n sendSuppressedKeepalive: false,\n setupQueueWorker: false,\n removeQueueWorker: false,\n scheduleNextQueueWorkerPass: false,\n subscribeToTopic: false,\n subscribeToAllTopics: false,\n clearSubscribedTopics: false,\n })\n }\n\n get isConnected() {\n return this.status === STATUS.CONNECTED\n }\n\n subscribeToTopic = (topic?: string) => {\n if (!topic) return\n if (topic.includes(\"undefined\")) return\n\n if (!this.topicsSubscribed.has(topic)) {\n Logger.log(`Subscribing to ${topic}`)\n this.client?.subscribe(topic, (err, granted) => {\n if (err) {\n Logger.error(err)\n return\n }\n\n (granted !== undefined && granted[0])\n ? Logger.log(`Subscribed to ${granted[0].topic} with Qos ${granted[0].qos}`)\n : Logger.log(`Subscribed to ${topic} with Qos unknown`);\n })\n\n this.topicsSubscribed.add(topic)\n }\n }\n\n clearSubscribedTopics() {\n this.topicsSubscribed.clear()\n this.portalId = undefined\n }\n\n addMessage = async (topic: string, message: { value: string | null }) => {\n this.messageQueue[topic] = message.value ?? undefined\n }\n\n addMessagesFromQueue = async () => {\n if (Object.values(this.messageQueue).length > 0) {\n // Logger.log(`DEBUG: addMessagesFromQueue: in queue: ${JSON.stringify(Object.values(this.messageQueue).length)}`)\n assign(this.messages, this.messageQueue)\n // Logger.log(`DEBUG: addMessagesFromQueue: to process: ${JSON.stringify(Object.values(this.messages).length)}`)\n this.messageQueue = {}\n }\n }\n\n scheduleNextQueueWorkerPass = (timeout: number) => {\n this.queueWorker = setTimeout(async () => {\n const started = performance.now()\n await this.addMessagesFromQueue()\n const ended = performance.now()\n this.meanQueueWorkerPassDuration = addToMean(this.meanQueueWorkerPassDuration, 10, ended - started)\n // Schedule next update after 1 - 3 seconds\n // depending on how fast we were able to process the incoming messages\n const newTimeout = Math.max(1000, Math.min(this.meanQueueWorkerPassDuration * 50, 3000))\n this.scheduleNextQueueWorkerPass(newTimeout)\n }, timeout)\n }\n\n setupQueueWorker = () => {\n this.removeQueueWorker()\n\n this.meanQueueWorkerPassDuration = 20 // ms\n this.scheduleNextQueueWorkerPass(1000) // ms\n }\n\n removeQueueWorker = () => {\n if (this.queueWorker) {\n clearInterval(this.queueWorker)\n }\n this.queueWorker = undefined\n }\n\n setPortalId = (portalId: string) => {\n this.portalId = portalId\n }\n\n setStatus(status: string) {\n this.status = status\n }\n\n setError(error: object | null | boolean) {\n this.error = error\n }\n\n boot = (\n protocol: string,\n host: string = \"localhost\",\n port: number | null,\n path: string = \"websocket-mqtt\",\n remote: boolean = false,\n portalId?: string,\n ) => {\n Logger.log(\"MQTT booting\")\n\n let client = this.client\n\n if (client) {\n client.end(true)\n this.client = undefined\n this.portalId = undefined\n this.topicsSubscribed = new Set<string>()\n }\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\", async (topic, message) => {\n // Logger.log(`DEBUG: Message received: ${topic} - ${message.toString()}`)\n\n if (topic.endsWith(\"/system/0/Serial\") && !this.portalId) {\n const portalId = getMessageJson(message).value\n\n if (this.portalId !== portalId && portalId !== undefined) {\n this.setPortalId(portalId)\n }\n\n runInAction(() => this.subscribeToAllTopics())\n }\n if (topic.endsWith(\"full_publish_completed\")) {\n const uniqueId = getMessageJson(message)[\"full-publish-completed-echo\"] || \"\"\n Logger.log(`Received full_publish_completed for ${this.portalId} with full-publish-completed-echo: '${uniqueId}'`)\n if (uniqueId === this.uniqueId) {\n await this.addMessagesFromQueue()\n this.setupQueueWorker()\n }\n }\n\n if (message.toString() !== \"\") {\n await this.addMessage(topic, getMessageJson(message))\n }\n })\n\n Logger.log(\"MQTT booted\")\n }\n\n subscribeToAllTopics = () => {\n const topics = [\n `N/${this.portalId}/settings/#`,\n `N/${this.portalId}/system/#`,\n `N/${this.portalId}/vebus/#`,\n `N/${this.portalId}/alternator/#`,\n `N/${this.portalId}/battery/#`,\n `N/${this.portalId}/charger/#`,\n `N/${this.portalId}/dcsource/#`,\n `N/${this.portalId}/generator/#`,\n `N/${this.portalId}/genset/#`,\n `N/${this.portalId}/dcgenset/#`,\n `N/${this.portalId}/inverter/#`,\n `N/${this.portalId}/tank/#`,\n `N/${this.portalId}/temperature/#`,\n `N/${this.portalId}/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\n const options = JSON.stringify({\"keepalive-options\": [\"suppress-republish\"]})\n const topic = `R/${this.portalId}/keepalive`\n\n Logger.log(`Sending keepalive for ${this.portalId} with ${options}`)\n this.client?.publish(topic, options)\n }\n }\n\n sendFullKeepalive = () => {\n if (this.portalId) {\n\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 && 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, options?: IClientPublishOptions) => {\n if (this.status !== STATUS.CONNECTED || !this.client) {\n Logger.log(\"Could not publish value, not connected to MQTT broker\")\n }\n const message = JSON.stringify({value: data})\n\n Logger.log(`Publishing to ${topic}: ${message}`)\n\n this.client?.publish(topic, message, options ?? {})\n }\n}\n\n/**\n * Compute mean by providing existing mean, number of samples, and new sample.\n *\n * @param {number} mean current mean\n * @param {number} n number of sampled values\n * @param {number} newValue the sample\n * @returns {number} the new mean\n *\n * @example\n * addToMean(14, 5, 53); // => 20.5\n */\nfunction addToMean(mean: number, n: number, newValue: number): number {\n return mean + (newValue - mean) / (n + 1);\n}\n\nfunction initializeStore() {\n const _store = store ?? new MqttStore()\n // For SSG and SSR always create a new store\n if (typeof window === \"undefined\") return _store\n // Create the store once in the client\n if (!store) store = _store\n\n return _store\n}\n\nexport function useMqtt() {\n return useMemo(() => initializeStore(), [])\n}"]}
1
+ {"version":3,"file":"Mqtt.store.js","sourceRoot":"/","sources":["src/Modules/Mqtt/Mqtt.store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAC,MAAM,MAAM,CAAA;AAC9D,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,MAAM,C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ction} from \"mobx\"\nimport {computedFn} from \"mobx-utils\"\nimport * as mqtt from \"mqtt\"\nimport {IClientPublishOptions, MqttClient} from \"mqtt\"\nimport {MqttMessage, MqttMessages, PortalId, STATUS, Topics} from \"../Mqtt\"\nimport Logger from \"../../utils/logger\"\nimport {getMessageJson} from \"../../utils/util\"\nimport {useMemo} from \"react\"\nimport {assign} from \"lodash-es\"\n\nlet store: MqttStore\n\nexport class MqttStore {\n client?: MqttClient | null\n error?: object | null | boolean\n status: string = STATUS.CONNECTING\n messages: MqttMessages = {}\n messageQueue: MqttMessages = {}\n topicsSubscribed: Set<string> = new Set<string>()\n portalId: PortalId\n uniqueId: string = Math.random().toString(16).substr(2, 8)\n keepAliveHandlerRef: any\n queueWorker: any\n meanQueueWorkerPassDuration: number = 0\n\n // Use comparer.identity to check the message we get for given topic.\n // Will cause re-render when new message for given topic arrives.\n // We rely on the fact that MQTT will only re-send a message when it\n // changes, and on full keep alive only.\n messageFromTopic = computedFn((topic?: string) => {\n // Logger.log(`DEBUG: messageFromTopic: ${JSON.stringify(topic)}`)\n // trace()\n return topic ? this.messages[topic] : undefined\n }, { name: \"Mqtt.store.messageFromTopic\", equals: comparer.identity })\n\n // Use comparer.identity to check the messages we get for given topics.\n // Will cause re-render when any new message for one of the topics arrives.\n // We rely on the fact that MQTT will only re-send a message when it\n // changes, and on full keep alive only.\n messagesByTopics = computedFn((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 }, { name: \"Mqtt.store.messagesByTopics\", equals: comparer.identity })\n\n // Use comparer.identity to check the messages we get for given topics.\n // Will cause re-render when any new message for one of the topic arrives,\n // or when we receive a new (yet unseen) topic.\n // We rely on the fact that MQTT will only re-send a message when it\n // changes, and on full keep alive\n // Only access Object.keys(this.messages),\n // and this.messages[k], where k matches the wildcard regex,\n // to make sure we invalidate:\n // - when new topics arrive\n // - when message with matching topic changes\n messagesByWildcard = computedFn((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(([_, message]) =>\n message !== undefined && message !== null\n && (!Array.isArray(message) || (message.length !== 0 && !message.every((v) => v === undefined || v === null)))\n ),\n )\n }, { name: \"Mqtt.store.messagesByWildcard\", equals: comparer.identity })\n\n constructor() {\n makeAutoObservable(this, {\n messageQueue: false,\n setupKeepaliveTimer: false,\n clearKeepaliveTimer: false,\n sendFullKeepalive: false,\n sendSuppressedKeepalive: false,\n setupQueueWorker: false,\n removeQueueWorker: false,\n scheduleNextQueueWorkerPass: false,\n subscribeToTopic: false,\n subscribeToAllTopics: false,\n clearSubscribedTopics: false,\n })\n }\n\n get isConnected() {\n return this.status === STATUS.CONNECTED\n }\n\n subscribeToTopic = (topic?: string) => {\n if (!topic) return\n if (topic.includes(\"undefined\")) return\n\n if (!this.topicsSubscribed.has(topic)) {\n Logger.log(`Subscribing to ${topic}`)\n this.client?.subscribe(topic, (err, granted) => {\n if (err) {\n Logger.error(err)\n return\n }\n\n (granted !== undefined && granted[0])\n ? Logger.log(`Subscribed to ${granted[0].topic} with Qos ${granted[0].qos}`)\n : Logger.log(`Subscribed to ${topic} with Qos unknown`);\n })\n\n this.topicsSubscribed.add(topic)\n }\n }\n\n clearSubscribedTopics() {\n this.topicsSubscribed.clear()\n this.portalId = undefined\n }\n\n addMessage = async (topic: string, message: { value: string | null }) => {\n this.messageQueue[topic] = message.value ?? undefined\n }\n\n addMessagesFromQueue = async () => {\n if (Object.values(this.messageQueue).length > 0) {\n // Logger.log(`DEBUG: addMessagesFromQueue: in queue: ${JSON.stringify(Object.values(this.messageQueue).length)}`)\n assign(this.messages, this.messageQueue)\n // Logger.log(`DEBUG: addMessagesFromQueue: to process: ${JSON.stringify(Object.values(this.messages).length)}`)\n this.messageQueue = {}\n }\n }\n\n scheduleNextQueueWorkerPass = (timeout: number) => {\n this.queueWorker = setTimeout(async () => {\n const started = performance.now()\n await this.addMessagesFromQueue()\n const ended = performance.now()\n this.meanQueueWorkerPassDuration = addToMean(this.meanQueueWorkerPassDuration, 10, ended - started)\n // Schedule next update after 1 - 3 seconds\n // depending on how fast we were able to process the incoming messages\n const newTimeout = Math.max(1000, Math.min(this.meanQueueWorkerPassDuration * 50, 3000))\n this.scheduleNextQueueWorkerPass(newTimeout)\n }, timeout)\n }\n\n setupQueueWorker = () => {\n this.removeQueueWorker()\n\n this.meanQueueWorkerPassDuration = 20 // ms\n this.scheduleNextQueueWorkerPass(1000) // ms\n }\n\n removeQueueWorker = () => {\n if (this.queueWorker) {\n clearInterval(this.queueWorker)\n }\n this.queueWorker = undefined\n }\n\n setPortalId = (portalId: string) => {\n this.portalId = portalId\n }\n\n setStatus(status: string) {\n this.status = status\n }\n\n setError(error: object | null | boolean) {\n this.error = error\n }\n\n boot = (\n protocol: string,\n host: string = \"localhost\",\n port: number | null,\n path: string = \"websocket-mqtt\",\n remote: boolean = false,\n portalId?: string,\n ) => {\n Logger.log(\"MQTT booting\")\n\n let client = this.client\n\n if (client) {\n client.end(true)\n this.client = undefined\n this.portalId = undefined\n this.topicsSubscribed = new Set<string>()\n }\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\", async (topic, message) => {\n // Logger.log(`DEBUG: Message received: ${topic} - ${message.toString()}`)\n\n if (topic.endsWith(\"/system/0/Serial\") && !this.portalId) {\n const portalId = getMessageJson(message).value\n\n if (this.portalId !== portalId && portalId !== undefined) {\n this.setPortalId(portalId)\n }\n\n runInAction(() => this.subscribeToAllTopics())\n }\n if (topic.endsWith(\"full_publish_completed\")) {\n const uniqueId = getMessageJson(message)[\"full-publish-completed-echo\"] || \"\"\n Logger.log(`Received full_publish_completed for ${this.portalId} with full-publish-completed-echo: '${uniqueId}'`)\n if (uniqueId === this.uniqueId) {\n await this.addMessagesFromQueue()\n this.setupQueueWorker()\n }\n }\n\n if (message.toString() !== \"\") {\n await this.addMessage(topic, getMessageJson(message))\n }\n })\n\n Logger.log(\"MQTT booted\")\n }\n\n subscribeToAllTopics = () => {\n const topics = [\n `N/${this.portalId}/settings/#`,\n `N/${this.portalId}/system/#`,\n `N/${this.portalId}/vebus/#`,\n `N/${this.portalId}/alternator/#`,\n `N/${this.portalId}/battery/#`,\n `N/${this.portalId}/charger/#`,\n `N/${this.portalId}/dcsource/#`,\n `N/${this.portalId}/generator/#`,\n `N/${this.portalId}/genset/#`,\n `N/${this.portalId}/dcgenset/#`,\n `N/${this.portalId}/inverter/#`,\n `N/${this.portalId}/tank/#`,\n `N/${this.portalId}/temperature/#`,\n `N/${this.portalId}/switch/#`,\n `N/${this.portalId}/full_publish_completed`\n ]\n\n this.client?.subscribe(topics, err => {\n if (err) {\n Logger.error(err)\n return\n }\n\n // When we received all topics we send a full keepalive.\n this.sendFullKeepalive()\n })\n }\n\n sendSuppressedKeepalive = () => {\n if (this.portalId) {\n\n const options = JSON.stringify({\"keepalive-options\": [\"suppress-republish\"]})\n const topic = `R/${this.portalId}/keepalive`\n\n Logger.log(`Sending keepalive for ${this.portalId} with ${options}`)\n this.client?.publish(topic, options)\n }\n }\n\n sendFullKeepalive = () => {\n if (this.portalId) {\n\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 && 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, options?: IClientPublishOptions) => {\n if (this.status !== STATUS.CONNECTED || !this.client) {\n Logger.log(\"Could not publish value, not connected to MQTT broker\")\n }\n const message = JSON.stringify({value: data})\n\n Logger.log(`Publishing to ${topic}: ${message}`)\n\n this.client?.publish(topic, message, options ?? {})\n }\n}\n\n/**\n * Compute mean by providing existing mean, number of samples, and new sample.\n *\n * @param {number} mean current mean\n * @param {number} n number of sampled values\n * @param {number} newValue the sample\n * @returns {number} the new mean\n *\n * @example\n * addToMean(14, 5, 53); // => 20.5\n */\nfunction addToMean(mean: number, n: number, newValue: number): number {\n return mean + (newValue - mean) / (n + 1);\n}\n\nfunction initializeStore() {\n const _store = store ?? new MqttStore()\n // For SSG and SSR always create a new store\n if (typeof window === \"undefined\") return _store\n // Create the store once in the client\n if (!store) store = _store\n\n return _store\n}\n\nexport function useMqtt() {\n return useMemo(() => initializeStore(), [])\n}"]}
@@ -0,0 +1,69 @@
1
+ import { PortalId, Topics } from "../Mqtt";
2
+ import { SwitchingDeviceInstanceId } from "./SwitchingDevice.provider";
3
+ import { SwitchableOutputStatus, SwitchableOutputType } from "../../utils/constants";
4
+ export type SwitchableOutputId = string;
5
+ export interface SwitchableOutputState {
6
+ deviceId: SwitchingDeviceInstanceId;
7
+ outputId: SwitchableOutputId;
8
+ type: SwitchableOutputType;
9
+ status: SwitchableOutputStatus;
10
+ name: string;
11
+ customName: string;
12
+ group: string;
13
+ showUIControl: 0 | 1;
14
+ auto: 0 | 1;
15
+ state: 0 | 1;
16
+ dimming?: number;
17
+ dimmingMin?: number;
18
+ dimmingMax?: number;
19
+ stepSize?: number;
20
+ measurement?: number;
21
+ unit: string | "/S" | "/T" | "/V";
22
+ labels: string;
23
+ }
24
+ export interface SwitchableOutputProvider extends SwitchableOutputState {
25
+ updateAuto: (auto: 0 | 1) => void;
26
+ updateState: (state: 0 | 1) => void;
27
+ updateDimming: (dimming: number) => void;
28
+ }
29
+ export interface SwitchableOutputTopics extends Topics {
30
+ type?: string;
31
+ status?: string;
32
+ name?: string;
33
+ customName?: string;
34
+ group?: string;
35
+ showUIControl?: string;
36
+ auto?: string;
37
+ state?: string;
38
+ dimming?: string;
39
+ dimmingMin?: string;
40
+ dimmingMax?: string;
41
+ stepSize?: string;
42
+ measurement?: string;
43
+ unit?: string;
44
+ labels?: string;
45
+ }
46
+ export declare const getSwitchableOutputStateTopics: (portalId: PortalId, deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId) => {
47
+ type: string;
48
+ status: string;
49
+ name: string;
50
+ customName: string;
51
+ group: string;
52
+ showUIControl: string;
53
+ auto: string;
54
+ state: string;
55
+ dimming: string;
56
+ dimmingMin: string;
57
+ dimmingMax: string;
58
+ stepSize: string;
59
+ measurement: string;
60
+ unit: string;
61
+ labels: string;
62
+ };
63
+ export declare const getSwitchableOutputWriteTopics: (portalId: PortalId, deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId) => {
64
+ auto: string;
65
+ state: string;
66
+ dimming: string;
67
+ };
68
+ export declare function useSwitchableOutput(deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId): SwitchableOutputProvider;
69
+ //# sourceMappingURL=SwitchableOutput.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchableOutput.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutput.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAA2B,MAAM,SAAS,CAAA;AAEnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AACtE,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEpF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAA;AAEvC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,yBAAyB,CAAA;IACnC,QAAQ,EAAE,kBAAkB,CAAA;IAC5B,IAAI,EAAE,oBAAoB,CAAA;IAC1B,MAAM,EAAE,sBAAsB,CAAA;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,CAAC,GAAG,CAAC,CAAA;IACpB,IAAI,EAAE,CAAC,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BAAyB,EAAE,UAAU,kBAAkB;;;;;;;;;;;;;;;;CAgBlI,CAAA;AAEF,eAAO,MAAM,8BAA8B,GAAI,UAAU,QAAQ,EAAE,UAAU,yBAAyB,EAAE,UAAU,kBAAkB;;;;CAIlI,CAAA;AAEF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,yBAAyB,EAAE,QAAQ,EAAE,kBAAkB,GAAG,wBAAwB,CAW/H"}
@@ -0,0 +1,45 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { useMqtt, useTopicsState } from "../Mqtt";
13
+ import { useMemo } from "react";
14
+ export var getSwitchableOutputStateTopics = function (portalId, deviceId, outputId) { return ({
15
+ type: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/Type"),
16
+ status: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Status"),
17
+ name: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Name"),
18
+ customName: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/CustomName"),
19
+ group: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/Group"),
20
+ showUIControl: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Settings/ShowUIControl"),
21
+ auto: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Auto"),
22
+ state: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/State"),
23
+ dimming: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Dimming"),
24
+ dimmingMin: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/DimmingMin"),
25
+ dimmingMax: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/DimmingMax"),
26
+ stepSize: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/StepSize"),
27
+ measurement: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Measurement"),
28
+ unit: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Unit"),
29
+ labels: "N/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Labels"),
30
+ }); };
31
+ export var getSwitchableOutputWriteTopics = function (portalId, deviceId, outputId) { return ({
32
+ auto: "W/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Auto"),
33
+ state: "W/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/State"),
34
+ dimming: "W/".concat(portalId, "/switch/").concat(deviceId, "/SwitchableOutput/").concat(outputId, "/Dimming"),
35
+ }); };
36
+ export function useSwitchableOutput(deviceId, outputId) {
37
+ var mqtt = useMqtt();
38
+ var topics = useMemo(function () { return getSwitchableOutputStateTopics(mqtt.portalId, deviceId, outputId); }, [mqtt.portalId, deviceId, outputId]);
39
+ var writeTopics = useMemo(function () { return getSwitchableOutputWriteTopics(mqtt.portalId, deviceId, outputId); }, [mqtt.portalId, deviceId, outputId]);
40
+ var updateAuto = function (auto) { return mqtt.publish(writeTopics.auto, auto); };
41
+ var updateState = function (state) { return mqtt.publish(writeTopics.state, state); };
42
+ var updateDimming = function (dimming) { return mqtt.publish(writeTopics.dimming, dimming); };
43
+ return __assign(__assign({}, useTopicsState(topics)), { updateAuto: updateAuto, updateState: updateState, updateDimming: updateDimming });
44
+ }
45
+ //# sourceMapping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O,CAAC,WAAY,CAAC,KAAK,EAAE,KAAK,CAAC,EAAvC,CAAuC,CAAA;IAC7E,IAAM,aAAa,GAAG,UAAC,OAAe,IAAK,OAAA,IAAI,CAAC,OAAO,CAAC,WAAY,CAAC,OAAO,EAAE,OAAO,CAAC,EAA3C,CAA2C,CAAA;IAEtF,6BAAY,cAAc,CAAwB,MAAM,CAAC,KAAE,UAAU,YAAA,EAAE,WAAW,aAAA,EAAE,aAAa,eAAA,IAAE;AACrG,CAAC","sourcesContent":["import { PortalId, Topics, useMqtt, useTopicsState } from \"../Mqtt\"\nimport { useMemo } from \"react\"\nimport { SwitchingDeviceInstanceId } from \"./SwitchingDevice.provider\"\nimport { SwitchableOutputStatus, SwitchableOutputType } from \"../../utils/constants\"\n\nexport type SwitchableOutputId = string\n\nexport interface SwitchableOutputState {\n deviceId: SwitchingDeviceInstanceId\n outputId: SwitchableOutputId\n type: SwitchableOutputType\n status: SwitchableOutputStatus\n name: string\n customName: string\n group: string\n showUIControl: 0 | 1\n auto: 0 | 1\n state: 0 | 1\n dimming?: number\n dimmingMin?: number\n dimmingMax?: number\n // NOTE: stepSize can be of any precision, respect the precision in the UI\n stepSize?: number\n measurement?: number\n unit: string | \"/S\" | \"/T\" | \"/V\"\n // NOTE: JSON encoded string array\n labels: string\n}\n\nexport interface SwitchableOutputProvider extends SwitchableOutputState {\n updateAuto: (auto: 0 | 1) => void\n updateState: (state: 0 | 1) => void\n updateDimming: (dimming: number) => void\n}\n\nexport interface SwitchableOutputTopics extends Topics {\n type?: string\n status?: string\n name?: string\n customName?: string\n group?: string\n showUIControl?: string\n auto?: string\n state?: string\n dimming?: string\n dimmingMin?: string\n dimmingMax?: string\n stepSize?: string\n measurement?: string\n unit?: string\n labels?: string\n}\n\nexport const getSwitchableOutputStateTopics = (portalId: PortalId, deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId) => ({\n type: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Settings/Type`,\n status: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Status`,\n name: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Name`,\n customName: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Settings/CustomName`,\n group: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Settings/Group`,\n showUIControl: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Settings/ShowUIControl`,\n auto: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Auto`,\n state: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/State`,\n dimming: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Dimming`,\n dimmingMin: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/DimmingMin`,\n dimmingMax: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/DimmingMax`,\n stepSize: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/StepSize`,\n measurement: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Measurement`,\n unit: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Unit`,\n labels: `N/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Labels`,\n})\n\nexport const getSwitchableOutputWriteTopics = (portalId: PortalId, deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId) => ({\n auto: `W/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Auto`,\n state: `W/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/State`,\n dimming: `W/${portalId}/switch/${deviceId}/SwitchableOutput/${outputId}/Dimming`,\n})\n\nexport function useSwitchableOutput(deviceId: SwitchingDeviceInstanceId, outputId: SwitchableOutputId): SwitchableOutputProvider {\n\n const mqtt = useMqtt()\n const topics = useMemo(() => getSwitchableOutputStateTopics(mqtt.portalId, deviceId, outputId), [mqtt.portalId, deviceId, outputId])\n const writeTopics = useMemo(() => getSwitchableOutputWriteTopics(mqtt.portalId, deviceId, outputId), [mqtt.portalId, deviceId, outputId])\n\n const updateAuto = (auto: 0 | 1) => mqtt.publish(writeTopics!.auto, auto)\n const updateState = (state: 0 | 1) => mqtt.publish(writeTopics!.state, state)\n const updateDimming = (dimming: number) => mqtt.publish(writeTopics!.dimming, dimming)\n\n return { ...useTopicsState<SwitchableOutputState>(topics), updateAuto, updateState, updateDimming }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const useSwitchableOutputs: () => import("./SwitchableOutputs.store").SwitchableOutputsStore;
2
+ //# sourceMappingURL=SwitchableOutputs.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchableOutputs.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.provider.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,oBAAoB,kEA6DhC,CAAA"}
@@ -0,0 +1,81 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { autorun } from "mobx";
13
+ import Logger from "../../utils/logger";
14
+ import { useMqtt } from "../Mqtt";
15
+ import { useMemo, useEffect } from "react";
16
+ import { useSwitchableOutputsStore } from "./SwitchableOutputs.store";
17
+ import { getSwitchingDeviceStateTopics } from "./SwitchingDevice.provider";
18
+ import { getSwitchableOutputStateTopics } from "./SwitchableOutput.provider";
19
+ export var useSwitchableOutputs = function () {
20
+ var switchableOutputsStore = useSwitchableOutputsStore();
21
+ var getTopics = function (portalId) { return ({
22
+ switchableOutputs: "N/".concat(portalId, "/switch/+/SwitchableOutput/+/Settings/+"),
23
+ }); };
24
+ var mqtt = useMqtt();
25
+ var topics = useMemo(function () { return getTopics(mqtt.portalId); }, [mqtt.portalId]);
26
+ var messagesForSwitchableOutputs = mqtt.messagesByWildcard(topics.switchableOutputs);
27
+ // Examine MQTT to find all available switchable outputs and their group assignments
28
+ useEffect(function () {
29
+ if (!messagesForSwitchableOutputs || Object.entries(messagesForSwitchableOutputs).length === 0) {
30
+ Logger.log("Waiting for switchable outputs...");
31
+ }
32
+ else {
33
+ var availableSwitchableOutputs_1 = Object.keys(messagesForSwitchableOutputs)
34
+ .filter(function (key) { return key.endsWith('/Settings/Group'); })
35
+ .sort();
36
+ var customGroupAssigments_1 = availableSwitchableOutputs_1
37
+ .filter(function (topic) { return topic.endsWith('/Settings/Group'); })
38
+ .map(function (topic) { return messagesForSwitchableOutputs[topic]; });
39
+ var dispose_1 = autorun(function () {
40
+ switchableOutputsStore.setCustomGroupAssignments(customGroupAssigments_1);
41
+ var newGroups = {};
42
+ // Walk the array of all switchable outputs, determine to which group it belongs
43
+ // and populate its initial state
44
+ availableSwitchableOutputs_1.forEach(function (output, index) {
45
+ var swo = extractSwitchableOutputInfo(output);
46
+ var switchingDevice = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, swo.deviceId));
47
+ var customGroupAssignment = customGroupAssigments_1[index].trim();
48
+ var groupName = customGroupAssignment === "" ? switchingDevice.customName || switchingDevice.productName : customGroupAssignment;
49
+ var switchableOutput = mqtt.messagesByTopics(getSwitchableOutputStateTopics(mqtt.portalId, swo.deviceId, swo.outputId));
50
+ // Ignore hidden controls
51
+ if (switchableOutput.showUIControl === 0) {
52
+ return;
53
+ }
54
+ newGroups[groupName] || (newGroups[groupName] = []);
55
+ newGroups[groupName].push(__assign(__assign({}, switchableOutput), { deviceId: swo.deviceId, outputId: swo.outputId }));
56
+ });
57
+ Logger.log("New switchable output groups: ".concat(JSON.stringify(Object.keys(newGroups))));
58
+ // Sort switches in a group by name
59
+ Object.values(newGroups).forEach(function (array) {
60
+ array.sort(function (a, b) {
61
+ var aName = a.customName || a.name;
62
+ var bName = b.customName || b.name;
63
+ return aName.localeCompare(bName);
64
+ });
65
+ });
66
+ switchableOutputsStore.setGroups(newGroups);
67
+ });
68
+ return function () { return dispose_1(); };
69
+ }
70
+ }, [messagesForSwitchableOutputs]);
71
+ return switchableOutputsStore;
72
+ };
73
+ function extractSwitchableOutputInfo(topic) {
74
+ var switchStart = topic.indexOf('/switch/') + 8; // length of `/switch/`
75
+ var outputStart = topic.indexOf('/SwitchableOutput/') + 18; // length of `/SwitchableOutput/`
76
+ return {
77
+ deviceId: topic.substring(switchStart, topic.indexOf('/', switchStart)),
78
+ outputId: topic.substring(outputStart, topic.indexOf('/', outputStart))
79
+ };
80
+ }
81
+ //# sourceMappingURL=SwitchableOutputs.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchableOutputs.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.provider.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAY,OAAO,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,6BAA6B,EAA6B,MAAM,4BAA4B,CAAA;AACrG,OAAO,EAAE,8BAA8B,EAA6C,MAAM,6BAA6B,CAAA;AAEvH,MAAM,CAAC,IAAM,oBAAoB,GAAG;IAClC,IAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAA;IAE1D,IAAM,SAAS,GAAG,UAAC,QAAkB,IAAK,OAAA,CAAC;QACzC,iBAAiB,EAAE,YAAK,QAAQ,4CAAyC;KAC1E,CAAC,EAFwC,CAExC,CAAA;IAEF,IAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IACtB,IAAM,MAAM,GAAG,OAAO,CAAC,cAAM,OAAA,SAAS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,CAAC,CAAA;gBACF,sBAAsB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;YAC7C,CAAC,CACF,CAAA;YACD,OAAO,cAAM,OAAA,SAAO,EAAE,EAAT,CAAS,CAAA;QACxB,CAAC;IACH,CAAC,EAAE,CAAC,4BAA4B,CAAC,CAAC,CAAA;IAElC,OAAO,sBAAsB,CAAA;AAC/B,CAAC,CAAA;AAED,SAAS,2BAA2B,CAAC,KAAa;IAChD,IAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA,CAAC,uBAAuB;IACzE,IAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAA,CAAC,iCAAiC;IAE9F,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAyC;QAC/G,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAkC;KACzG,CAAA;AACH,CAAC","sourcesContent":["import { autorun } from \"mobx\"\nimport Logger from \"../../utils/logger\"\nimport { PortalId, useMqtt } from \"../Mqtt\"\nimport { useMemo, useEffect } from \"react\"\nimport { useSwitchableOutputsStore } from \"./SwitchableOutputs.store\"\nimport { getSwitchingDeviceStateTopics, SwitchingDeviceInstanceId } from \"./SwitchingDevice.provider\"\nimport { getSwitchableOutputStateTopics, SwitchableOutputId, SwitchableOutputState } from \"./SwitchableOutput.provider\"\n\nexport const useSwitchableOutputs = () => {\n const switchableOutputsStore = useSwitchableOutputsStore()\n\n const getTopics = (portalId: PortalId) => ({\n switchableOutputs: `N/${portalId}/switch/+/SwitchableOutput/+/Settings/+`,\n })\n\n const mqtt = useMqtt()\n const topics = useMemo(() => getTopics(mqtt.portalId), [mqtt.portalId])\n\n const messagesForSwitchableOutputs = mqtt.messagesByWildcard(topics.switchableOutputs)\n\n // Examine MQTT to find all available switchable outputs and their group assignments\n useEffect(() => {\n if (!messagesForSwitchableOutputs || Object.entries(messagesForSwitchableOutputs).length === 0) {\n Logger.log(\"Waiting for switchable outputs...\")\n } else {\n const availableSwitchableOutputs = Object.keys(messagesForSwitchableOutputs)\n .filter(key => key.endsWith('/Settings/Group'))\n .sort() as string[]\n const customGroupAssigments = availableSwitchableOutputs\n .filter(topic => topic.endsWith('/Settings/Group'))\n .map(topic => messagesForSwitchableOutputs[topic])\n const dispose = autorun(() => {\n switchableOutputsStore.setCustomGroupAssignments(customGroupAssigments)\n\n const newGroups: { [key: string] : SwitchableOutputState[]} = {}\n\n // Walk the array of all switchable outputs, determine to which group it belongs\n // and populate its initial state\n availableSwitchableOutputs.forEach((output, index) => {\n const swo = extractSwitchableOutputInfo(output)\n const switchingDevice = mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, swo.deviceId))\n const customGroupAssignment = customGroupAssigments[index].trim()\n const groupName = customGroupAssignment === \"\" ? switchingDevice.customName || switchingDevice.productName : customGroupAssignment\n const switchableOutput = mqtt.messagesByTopics(getSwitchableOutputStateTopics(mqtt.portalId, swo.deviceId, swo.outputId)) as unknown as SwitchableOutputState\n\n // Ignore hidden controls\n if (switchableOutput.showUIControl === 0) { return }\n\n newGroups[groupName] ||= []\n newGroups[groupName].push({ ...switchableOutput, deviceId: swo.deviceId, outputId: swo.outputId })\n })\n\n Logger.log(`New switchable output groups: ${JSON.stringify(Object.keys(newGroups))}`);\n // Sort switches in a group by name\n Object.values(newGroups).forEach(array => {\n array.sort((a, b) => {\n const aName = a.customName || a.name\n const bName = b.customName || b.name\n return aName.localeCompare(bName);\n })\n })\n switchableOutputsStore.setGroups(newGroups)\n }\n )\n return () => dispose()\n }\n }, [messagesForSwitchableOutputs])\n\n return switchableOutputsStore\n}\n\nfunction extractSwitchableOutputInfo(topic: string) {\n const switchStart = topic.indexOf('/switch/') + 8 // length of `/switch/`\n const outputStart = topic.indexOf('/SwitchableOutput/') + 18 // length of `/SwitchableOutput/`\n \n return {\n deviceId: topic.substring(switchStart, topic.indexOf('/', switchStart)) as unknown as SwitchingDeviceInstanceId,\n outputId: topic.substring(outputStart, topic.indexOf('/', outputStart)) as unknown as SwitchableOutputId\n }\n}"]}
@@ -0,0 +1,22 @@
1
+ import { SwitchableOutputState } from "./SwitchableOutput.provider";
2
+ export interface SwitchableOutputsState {
3
+ groups: {
4
+ [key: string]: SwitchableOutputState[];
5
+ };
6
+ customGroupAssignments: string[];
7
+ }
8
+ export declare class SwitchableOutputsStore {
9
+ groups: {
10
+ [key: string]: SwitchableOutputState[];
11
+ };
12
+ customGroupAssignments: string[];
13
+ constructor();
14
+ setGroups: (groups: {
15
+ [key: string]: SwitchableOutputState[];
16
+ }) => {
17
+ [key: string]: SwitchableOutputState[];
18
+ };
19
+ setCustomGroupAssignments: (assignments: string[]) => string[];
20
+ }
21
+ export declare function useSwitchableOutputsStore(): SwitchableOutputsStore;
22
+ //# sourceMappingURL=SwitchableOutputs.store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchableOutputs.store.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAInE,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAI,qBAAqB,EAAE,CAAA;KAAE,CAAA;IAEnD,sBAAsB,EAAE,MAAM,EAAE,CAAA;CACjC;AAED,qBAAa,sBAAsB;IACjC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAI,qBAAqB,EAAE,CAAA;KAAE,CAAK;IACxD,sBAAsB,EAAE,MAAM,EAAE,CAAK;;IAMrC,SAAS,GAAI,QAAQ;QAAE,CAAC,GAAG,EAAE,MAAM,GAAI,qBAAqB,EAAE,CAAA;KAAE;;MAAyB;IACzF,yBAAyB,GAAI,aAAa,MAAM,EAAE,cAA8C;CACjG;AAYD,wBAAgB,yBAAyB,2BAExC"}
@@ -0,0 +1,49 @@
1
+ import { action, makeAutoObservable } from "mobx";
2
+ import { useMemo } from "react";
3
+ var store;
4
+ var SwitchableOutputsStore = /** @class */ (function () {
5
+ function SwitchableOutputsStore() {
6
+ var _this = this;
7
+ Object.defineProperty(this, "groups", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: {}
12
+ });
13
+ Object.defineProperty(this, "customGroupAssignments", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: []
18
+ });
19
+ Object.defineProperty(this, "setGroups", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: function (groups) { return _this.groups = groups; }
24
+ });
25
+ Object.defineProperty(this, "setCustomGroupAssignments", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: function (assignments) { return _this.customGroupAssignments = assignments; }
30
+ });
31
+ makeAutoObservable(this, { setGroups: action, setCustomGroupAssignments: action });
32
+ }
33
+ return SwitchableOutputsStore;
34
+ }());
35
+ export { SwitchableOutputsStore };
36
+ function initializeStore() {
37
+ var _store = store !== null && store !== void 0 ? store : new SwitchableOutputsStore();
38
+ // For SSG and SSR always create a new store
39
+ if (typeof window === "undefined")
40
+ return _store;
41
+ // Create the store once in the client
42
+ if (!store)
43
+ store = _store;
44
+ return _store;
45
+ }
46
+ export function useSwitchableOutputsStore() {
47
+ return useMemo(function () { return initializeStore(); }, []);
48
+ }
49
+ //# sourceMappingURL=SwitchableOutputs.store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchableOutputs.store.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchableOutputs.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAe,MAAM,MAAM,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAG/B,IAAI,KAA6B,CAAA;AAQjC;IAIE;QAAA,iBAEC;QALD;;;;mBAAsD,EAAE;WAAA;QACxD;;;;mBAAmC,EAAE;WAAA;QAMrC;;;;mBAAY,UAAC,MAAmD,IAAK,OAAA,KAAI,CAAC,MAAM,GAAG,MAAM,EAApB,CAAoB;WAAA;QACzF;;;;mBAA4B,UAAC,WAAqB,IAAK,OAAA,KAAI,CAAC,sBAAsB,GAAG,WAAW,EAAzC,CAAyC;WAAA;QAJ9F,kBAAkB,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,EAAE,CAAC,CAAA;IACpF,CAAC;IAIH,6BAAC;AAAD,CAAC,AAVD,IAUC;;AAED,SAAS,eAAe;IACtB,IAAM,MAAM,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,sBAAsB,EAAE,CAAA;IACpD,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,yBAAyB;IACvC,OAAO,OAAO,CAAC,cAAM,OAAA,eAAe,EAAE,EAAjB,CAAiB,EAAE,EAAE,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import { action, makeAutoObservable, runInAction } from \"mobx\"\nimport { useMemo } from \"react\"\nimport { SwitchableOutputState } from \"./SwitchableOutput.provider\"\n\nlet store: SwitchableOutputsStore\n\nexport interface SwitchableOutputsState {\n groups: { [key: string] : SwitchableOutputState[] }\n // custom group assignments for available switchable outputs sorted by their topic path\n customGroupAssignments: string[]\n}\n\nexport class SwitchableOutputsStore {\n groups: { [key: string] : SwitchableOutputState[] } = {}\n customGroupAssignments: string[] = []\n\n constructor() {\n makeAutoObservable(this, { setGroups: action, setCustomGroupAssignments: action })\n }\n\n setGroups = (groups: { [key: string] : SwitchableOutputState[] }) => this.groups = groups\n setCustomGroupAssignments = (assignments: string[]) => this.customGroupAssignments = assignments\n}\n\nfunction initializeStore() {\n const _store = store ?? new SwitchableOutputsStore()\n // For SSG and SSR always create a new store\n if (typeof window === \"undefined\") return _store\n // Create the store once in the client\n if (!store) store = _store\n\n return _store\n}\n\nexport function useSwitchableOutputsStore() {\n return useMemo(() => initializeStore(), [])\n}"]}
@@ -0,0 +1,22 @@
1
+ import { PortalId, Topics } from "../Mqtt";
2
+ import { SwitchableOutputState } from "./SwitchableOutput.provider";
3
+ export type SwitchingDeviceInstanceId = number;
4
+ export interface SwitchingDeviceState {
5
+ productName: string;
6
+ customName: string;
7
+ instance: number;
8
+ switchableOutputs: SwitchableOutputState[];
9
+ }
10
+ export interface SwitchingDeviceTopics extends Topics {
11
+ productName?: string;
12
+ customName?: string;
13
+ instance?: string;
14
+ }
15
+ export declare const getSwitchingDeviceStateTopics: (portalId: PortalId, instanceId: SwitchingDeviceInstanceId) => {
16
+ productName: string;
17
+ customName: string;
18
+ instance: string;
19
+ };
20
+ export declare function useSwitchingDevice(instanceId: SwitchingDeviceInstanceId): SwitchingDeviceState;
21
+ export declare function useSwitchingDevices(): import("./SwitchingDevices.store").SwitchingDevicesStore;
22
+ //# sourceMappingURL=SwitchingDevice.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchingDevice.provider.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchingDevice.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAA2B,MAAM,SAAS,CAAA;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAInE,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAA;AAE9C,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,iBAAiB,EAAE,qBAAqB,EAAE,CAAA;CAC3C;AAED,MAAM,WAAW,qBAAsB,SAAQ,MAAM;IACnD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,6BAA6B,GAAI,UAAU,QAAQ,EAAE,YAAY,yBAAyB;;;;CAIrG,CAAA;AAEF,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,yBAAyB,GAAG,oBAAoB,CAM9F;AAED,wBAAgB,mBAAmB,6DAiClC"}
@@ -0,0 +1,46 @@
1
+ import { useEffect, useMemo } from "react";
2
+ import { useMqtt, useTopicsState } from "../Mqtt";
3
+ import Logger from "../../utils/logger";
4
+ import { useSwitchingDevicesStore } from "./SwitchingDevices.store";
5
+ import { autorun } from "mobx";
6
+ export var getSwitchingDeviceStateTopics = function (portalId, instanceId) { return ({
7
+ productName: "N/".concat(portalId, "/switch/").concat(instanceId, "/ProductName"),
8
+ customName: "N/".concat(portalId, "/switch/").concat(instanceId, "/CustomName"),
9
+ instance: "N/".concat(portalId, "/tank/").concat(instanceId, "/DeviceInstance"),
10
+ }); };
11
+ export function useSwitchingDevice(instanceId) {
12
+ var portalId = useMqtt().portalId;
13
+ var topics = useMemo(function () { return getSwitchingDeviceStateTopics(portalId, instanceId); }, [portalId, instanceId]);
14
+ return useTopicsState(topics);
15
+ }
16
+ export function useSwitchingDevices() {
17
+ var switchingDevicesStore = useSwitchingDevicesStore();
18
+ var getTopics = function (portalId) { return ({
19
+ devices: "N/".concat(portalId, "/switch/+/DeviceInstance"),
20
+ }); };
21
+ var mqtt = useMqtt();
22
+ var topics = useMemo(function () { return getTopics(mqtt.portalId); }, [mqtt.portalId]);
23
+ var messagesForSwitchingDevices = mqtt.messagesByWildcard(topics.devices);
24
+ // Examine MQTT to find all available switching devices
25
+ useEffect(function () {
26
+ if (!messagesForSwitchingDevices || Object.entries(messagesForSwitchingDevices).length === 0) {
27
+ Logger.log("Waiting for switching devices...");
28
+ }
29
+ else {
30
+ var deviceInstances_1 = Object.values(messagesForSwitchingDevices);
31
+ var dispose_1 = autorun(function () {
32
+ var oldDevices = switchingDevicesStore.devices;
33
+ var newDevices = deviceInstances_1.map(function (deviceId) { return mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, 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 || oldDevices.length != newDevices.length || !newDevices.every(function (id) { return deviceInstances_1.includes(id); })) {
37
+ Logger.log("New switching devices instances: ".concat(JSON.stringify(deviceInstances_1)));
38
+ switchingDevicesStore.setDevices(newDevices);
39
+ }
40
+ });
41
+ return function () { return dispose_1(); };
42
+ }
43
+ }, [messagesForSwitchingDevices]);
44
+ return switchingDevicesStore;
45
+ }
46
+ //# sourceMappingURL=SwitchingDevice.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchingDevice.provider.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchingDevice.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAoB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,MAAM,MAAM,oBAAoB,CAAA;AAEvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAiB9B,MAAM,CAAC,IAAM,6BAA6B,GAAG,UAAC,QAAkB,EAAE,UAAqC,IAAK,OAAA,CAAC;IAC3G,WAAW,EAAE,YAAK,QAAQ,qBAAW,UAAU,iBAAc;IAC7D,UAAU,EAAE,YAAK,QAAQ,qBAAW,UAAU,gBAAa;IAC3D,QAAQ,EAAE,YAAK,QAAQ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BAAe,CAAC,GAAG,CAAC,UAAC,QAAQ,IAAK,OAAA,IAAI,CAAC,gBAAgB,CAAC,6BAA6B,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAA7E,CAA6E,CAA2C,CAAA;gBAC7K,iEAAiE;gBACjE,uDAAuD;gBACvD,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,UAAC,EAAE,IAAK,OAAA,iBAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,EAA5B,CAA4B,CAAC,EAAE,CAAC;oBACrH,MAAM,CAAC,GAAG,CAAC,2CAAoC,IAAI,CAAC,SAAS,CAAC,iBAAe,CAAC,CAAE,CAAC,CAAC;oBAClF,qBAAqB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;gBAC9C,CAAC;YACH,CAAC,CAAC,CAAA;YACF,OAAO,cAAM,OAAA,SAAO,EAAE,EAAT,CAAS,CAAA;QACxB,CAAC;IACH,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAC,CAAA;IAEjC,OAAO,qBAAqB,CAAA;AAC9B,CAAC","sourcesContent":["import { useEffect, useMemo } from \"react\"\nimport { PortalId, Topics, useMqtt, useTopicsState } from \"../Mqtt\"\nimport Logger from \"../../utils/logger\"\nimport { SwitchableOutputState } 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 = (portalId: PortalId, instanceId: SwitchingDeviceInstanceId) => ({\n productName: `N/${portalId}/switch/${instanceId}/ProductName`,\n customName: `N/${portalId}/switch/${instanceId}/CustomName`,\n instance: `N/${portalId}/tank/${instanceId}/DeviceInstance`,\n})\n\nexport function useSwitchingDevice(instanceId: SwitchingDeviceInstanceId): SwitchingDeviceState {\n\n const { portalId } = useMqtt()\n const topics = useMemo(() => getSwitchingDeviceStateTopics(portalId, 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) => mqtt.messagesByTopics(getSwitchingDeviceStateTopics(mqtt.portalId, deviceId))) 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 (!oldDevices || oldDevices.length != newDevices.length || !newDevices.every((id) => deviceInstances.includes(id))) {\n Logger.log(`New switching devices instances: ${JSON.stringify(deviceInstances)}`);\n switchingDevicesStore.setDevices(newDevices)\n }\n })\n return () => dispose()\n }\n }, [messagesForSwitchingDevices])\n\n return switchingDevicesStore\n}"]}
@@ -0,0 +1,11 @@
1
+ import { SwitchingDeviceInstanceId } from "./SwitchingDevice.provider";
2
+ export interface SwitchingDevicesState {
3
+ devices: SwitchingDeviceInstanceId[];
4
+ }
5
+ export declare class SwitchingDevicesStore {
6
+ devices: SwitchingDeviceInstanceId[];
7
+ constructor();
8
+ setDevices: (devices: SwitchingDeviceInstanceId[]) => number[];
9
+ }
10
+ export declare function useSwitchingDevicesStore(): SwitchingDevicesStore;
11
+ //# sourceMappingURL=SwitchingDevices.store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchingDevices.store.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchingDevices.store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AAItE,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,yBAAyB,EAAE,CAAA;CACrC;AAED,qBAAa,qBAAqB;IAChC,OAAO,EAAE,yBAAyB,EAAE,CAAK;;IAMzC,UAAU,GAAI,SAAS,yBAAyB,EAAE,cAA2B;CAC9E;AAYD,wBAAgB,wBAAwB,0BAEvC"}
@@ -0,0 +1,37 @@
1
+ import { action, makeAutoObservable } from "mobx";
2
+ import { useMemo } from "react";
3
+ var store;
4
+ var SwitchingDevicesStore = /** @class */ (function () {
5
+ function SwitchingDevicesStore() {
6
+ var _this = this;
7
+ Object.defineProperty(this, "devices", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: []
12
+ });
13
+ Object.defineProperty(this, "setDevices", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: function (devices) { return _this.devices = devices; }
18
+ });
19
+ makeAutoObservable(this, { setDevices: action });
20
+ }
21
+ return SwitchingDevicesStore;
22
+ }());
23
+ export { SwitchingDevicesStore };
24
+ function initializeStore() {
25
+ var _store = store !== null && store !== void 0 ? store : new SwitchingDevicesStore();
26
+ // For SSG and SSR always create a new store
27
+ if (typeof window === "undefined")
28
+ return _store;
29
+ // Create the store once in the client
30
+ if (!store)
31
+ store = _store;
32
+ return _store;
33
+ }
34
+ export function useSwitchingDevicesStore() {
35
+ return useMemo(function () { return initializeStore(); }, []);
36
+ }
37
+ //# sourceMappingURL=SwitchingDevices.store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchingDevices.store.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/SwitchingDevices.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAG/B,IAAI,KAA4B,CAAA;AAMhC;IAGE;QAAA,iBAEC;QAJD;;;;mBAAuC,EAAE;WAAA;QAMzC;;;;mBAAa,UAAC,OAAoC,IAAK,OAAA,KAAI,CAAC,OAAO,GAAG,OAAO,EAAtB,CAAsB;WAAA;QAH3E,kBAAkB,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAA;IAClD,CAAC;IAGH,4BAAC;AAAD,CAAC,AARD,IAQC;;AAED,SAAS,eAAe;IACtB,IAAM,MAAM,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,qBAAqB,EAAE,CAAA;IACnD,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,wBAAwB;IACtC,OAAO,OAAO,CAAC,cAAM,OAAA,eAAe,EAAE,EAAjB,CAAiB,EAAE,EAAE,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import { action, makeAutoObservable } from \"mobx\"\nimport { useMemo } from \"react\"\nimport { SwitchingDeviceInstanceId } from \"./SwitchingDevice.provider\"\n\nlet store: SwitchingDevicesStore\n\nexport interface SwitchingDevicesState {\n devices: SwitchingDeviceInstanceId[]\n}\n\nexport class SwitchingDevicesStore {\n devices: SwitchingDeviceInstanceId[] = []\n\n constructor() {\n makeAutoObservable(this, { setDevices: action })\n }\n\n setDevices = (devices: SwitchingDeviceInstanceId[]) => this.devices = devices\n}\n\nfunction initializeStore() {\n const _store = store ?? new SwitchingDevicesStore()\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 useSwitchingDevicesStore() {\n return useMemo(() => initializeStore(), [])\n}"]}
@@ -0,0 +1,6 @@
1
+ export * from "./SwitchingDevice.provider";
2
+ export * from "./SwitchingDevices.store";
3
+ export * from "./SwitchableOutput.provider";
4
+ export * from "./SwitchableOutputs.provider";
5
+ export * from "./SwitchableOutputs.store";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AACxC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from "./SwitchingDevice.provider";
2
+ export * from "./SwitchingDevices.store";
3
+ export * from "./SwitchableOutput.provider";
4
+ export * from "./SwitchableOutputs.provider";
5
+ export * from "./SwitchableOutputs.store";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["src/Modules/SwitchableOutputs/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AACxC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA","sourcesContent":["export * from \"./SwitchingDevice.provider\"\nexport * from \"./SwitchingDevices.store\"\nexport * from \"./SwitchableOutput.provider\"\nexport * from \"./SwitchableOutputs.provider\"\nexport * from \"./SwitchableOutputs.store\"\n"]}
@@ -21,5 +21,6 @@ export * from "./Modules/Vebus";
21
21
  export * from "./Modules/Vrm";
22
22
  export * from "./Modules/WindGenerators";
23
23
  export * from "./Modules/Temperatures";
24
+ export * from "./Modules/SwitchableOutputs";
24
25
  export * from "./utils/storage";
25
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iBAAiB,CAAA"}
package/dist/src/index.js CHANGED
@@ -21,5 +21,6 @@ export * from "./Modules/Vebus";
21
21
  export * from "./Modules/Vrm";
22
22
  export * from "./Modules/WindGenerators";
23
23
  export * from "./Modules/Temperatures";
24
+ export * from "./Modules/SwitchableOutputs";
24
25
  export * from "./utils/storage";
25
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA","sourcesContent":["export * from \"./Modules/AcLoads\"\nexport * from \"./Modules/AcMode\"\nexport * from \"./Modules/ActiveSource\"\nexport * from \"./Modules/Alternators\"\nexport * from \"./Modules/App\"\nexport * from \"./Modules/Battery\"\nexport * from \"./Modules/Chargers\"\nexport * from \"./Modules/DcLoads\"\nexport * from \"./Modules/Generators\"\nexport * from \"./Modules/Header\"\nexport * from \"./Modules/InverterCharger\"\nexport * from \"./Modules/Inverters\"\nexport * from \"./Modules/Language\"\nexport * from \"./Modules/Mqtt\"\nexport * from \"./Modules/PvCharger\"\nexport * from \"./Modules/ShorePowerInput\"\nexport * from \"./Modules/SystemState\"\nexport * from \"./Modules/Tanks\"\nexport * from \"./Modules/Theme\"\nexport * from \"./Modules/Vebus\"\nexport * from \"./Modules/Vrm\"\nexport * from \"./Modules/WindGenerators\"\nexport * from \"./Modules/Temperatures\"\nexport * from \"./utils/storage\""]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iBAAiB,CAAA","sourcesContent":["export * from \"./Modules/AcLoads\"\nexport * from \"./Modules/AcMode\"\nexport * from \"./Modules/ActiveSource\"\nexport * from \"./Modules/Alternators\"\nexport * from \"./Modules/App\"\nexport * from \"./Modules/Battery\"\nexport * from \"./Modules/Chargers\"\nexport * from \"./Modules/DcLoads\"\nexport * from \"./Modules/Generators\"\nexport * from \"./Modules/Header\"\nexport * from \"./Modules/InverterCharger\"\nexport * from \"./Modules/Inverters\"\nexport * from \"./Modules/Language\"\nexport * from \"./Modules/Mqtt\"\nexport * from \"./Modules/PvCharger\"\nexport * from \"./Modules/ShorePowerInput\"\nexport * from \"./Modules/SystemState\"\nexport * from \"./Modules/Tanks\"\nexport * from \"./Modules/Theme\"\nexport * from \"./Modules/Vebus\"\nexport * from \"./Modules/Vrm\"\nexport * from \"./Modules/WindGenerators\"\nexport * from \"./Modules/Temperatures\"\nexport * from \"./Modules/SwitchableOutputs\"\nexport * from \"./utils/storage\""]}
@@ -84,6 +84,32 @@ export declare const TANK_FLUID_TYPE: {
84
84
  HYDRAULIC_OIL: number;
85
85
  RAW_WATER: number;
86
86
  };
87
+ export declare const SWITCHABLE_OUTPUT_TYPE: {
88
+ readonly MOMENTARY_SWITCH: 0;
89
+ readonly TOGGLE_SWITCH: 1;
90
+ readonly DIMMABLE: 2;
91
+ readonly TEMPERATURE_SETPOINT: 3;
92
+ readonly STEPPED_SWITCH: 4;
93
+ readonly SLAVE_MODE: 5;
94
+ readonly DROPDOWN: 6;
95
+ readonly SLIDER: 7;
96
+ readonly UNRANGED_SETPOINT: 8;
97
+ readonly THREE_STATE_SWITCH: 9;
98
+ readonly BILGE_PUMP_CONTROL: 10;
99
+ };
100
+ export type SwitchableOutputType = typeof SWITCHABLE_OUTPUT_TYPE[keyof typeof SWITCHABLE_OUTPUT_TYPE];
101
+ export declare const SWITCHABLE_OUTPUT_STATUS: {
102
+ readonly STATUS_OFF: 0;
103
+ readonly STATUS_ON: 9;
104
+ readonly STATUS_POWERED: 1;
105
+ readonly STATUS_TRIPPED: 2;
106
+ readonly STATUS_OVER_TEMPERATURE: 4;
107
+ readonly STATUS_OUTPUT_FAULT: 8;
108
+ readonly STATUS_SHORT_FAULT: 16;
109
+ readonly STATUS_DISABLED: 32;
110
+ readonly STATUS_BYPASSED: 64;
111
+ };
112
+ export type SwitchableOutputStatus = typeof SWITCHABLE_OUTPUT_STATUS[keyof typeof SWITCHABLE_OUTPUT_STATUS];
87
113
  export declare const VIEWS: {
88
114
  CONNECTING: string;
89
115
  METRICS: string;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"/","sources":["src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;CAIzB,CAAA;AAED,eAAO,MAAM,sBAAsB;;CAElC,CAAA;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;CAe9B,CAAA;AAED,eAAO,MAAM,SAAS;;;;;;CAMrB,CAAA;AAED,eAAO,MAAM,cAAc;;;;;CAK1B,CAAA;AAED,eAAO,MAAM,YAAY;;;;CAIxB,CAAA;AAED,eAAO,MAAM,WAAW;;;;;CAKvB,CAAA;AAED,eAAO,MAAM,YAAY;;;CAGxB,CAAA;AAED,eAAO,MAAM,aAAa;;;;;CAKzB,CAAA;AAED,eAAO,MAAM,+BAA+B,QAAQ,CAAA;AAEpD,eAAO,MAAM,8BAA8B;;;CAG1C,CAAA;AAED,eAAO,MAAM,cAAc;;CAE1B,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;CAKhC,CAAA;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;CAa3B,CAAA;AAED,eAAO,MAAM,KAAK;;;;;;;CAOjB,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"/","sources":["src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;CAIzB,CAAA;AAED,eAAO,MAAM,sBAAsB;;CAElC,CAAA;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;CAe9B,CAAA;AAED,eAAO,MAAM,SAAS;;;;;;CAMrB,CAAA;AAED,eAAO,MAAM,cAAc;;;;;CAK1B,CAAA;AAED,eAAO,MAAM,YAAY;;;;CAIxB,CAAA;AAED,eAAO,MAAM,WAAW;;;;;CAKvB,CAAA;AAED,eAAO,MAAM,YAAY;;;CAGxB,CAAA;AAED,eAAO,MAAM,aAAa;;;;;CAKzB,CAAA;AAED,eAAO,MAAM,+BAA+B,QAAQ,CAAA;AAEpD,eAAO,MAAM,8BAA8B;;;CAG1C,CAAA;AAED,eAAO,MAAM,cAAc;;CAE1B,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;CAKhC,CAAA;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;CAa3B,CAAA;AAGD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;CAYzB,CAAA;AAEV,MAAM,MAAM,oBAAoB,GAAG,OAAO,sBAAsB,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAA;AAGrG,eAAO,MAAM,wBAAwB;;;;;;;;;;CAU3B,CAAA;AAEV,MAAM,MAAM,sBAAsB,GAAG,OAAO,wBAAwB,CAAC,MAAM,OAAO,wBAAwB,CAAC,CAAA;AAE3G,eAAO,MAAM,KAAK;;;;;;;CAOjB,CAAA"}
@@ -84,6 +84,32 @@ export var TANK_FLUID_TYPE = {
84
84
  HYDRAULIC_OIL: 9,
85
85
  RAW_WATER: 10
86
86
  };
87
+ // Taken from: https://github.com/victronenergy/venus/wiki/dbus#switch
88
+ export var SWITCHABLE_OUTPUT_TYPE = {
89
+ MOMENTARY_SWITCH: 0,
90
+ TOGGLE_SWITCH: 1,
91
+ DIMMABLE: 2,
92
+ TEMPERATURE_SETPOINT: 3,
93
+ STEPPED_SWITCH: 4,
94
+ SLAVE_MODE: 5,
95
+ DROPDOWN: 6,
96
+ SLIDER: 7,
97
+ UNRANGED_SETPOINT: 8,
98
+ THREE_STATE_SWITCH: 9,
99
+ BILGE_PUMP_CONTROL: 10,
100
+ };
101
+ // Taken from: https://github.com/victronenergy/venus/wiki/dbus#switch
102
+ export var SWITCHABLE_OUTPUT_STATUS = {
103
+ STATUS_OFF: 0x00,
104
+ STATUS_ON: 0x09,
105
+ STATUS_POWERED: 0x01,
106
+ STATUS_TRIPPED: 0x02,
107
+ STATUS_OVER_TEMPERATURE: 0x04,
108
+ STATUS_OUTPUT_FAULT: 0x08,
109
+ STATUS_SHORT_FAULT: 0x10,
110
+ STATUS_DISABLED: 0x20,
111
+ STATUS_BYPASSED: 0x40,
112
+ };
87
113
  export var VIEWS = {
88
114
  CONNECTING: "CONNECTING",
89
115
  METRICS: "METRICS",
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"/","sources":["src/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,CAAC;IACX,WAAW,EAAE,CAAC;CACf,CAAA;AAED,MAAM,CAAC,IAAM,sBAAsB,GAAG;IACpC,cAAc,EAAE,CAAC,CAAC;CACnB,CAAA;AAED,MAAM,CAAC,IAAM,kBAAkB,GAAG;IAChC,GAAG,EAAE,CAAC;IACN,SAAS,EAAE,CAAC;IACZ,eAAe,EAAE,CAAC;IAClB,aAAa,EAAE,CAAC;IAChB,oBAAoB,EAAE,CAAC;IACvB,cAAc,EAAE,CAAC;IACjB,YAAY,EAAE,CAAC;IACf,qBAAqB,EAAE,CAAC;IACxB,QAAQ,EAAE,CAAC;IACX,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,EAAE;IACb,iBAAiB,EAAE,EAAE;IACrB,WAAW,EAAE,GAAG;IAChB,OAAO,EAAE,GAAG;CACb,CAAA;AAED,MAAM,CAAC,IAAM,SAAS,GAAG;IACvB,aAAa,EAAE,CAAC;IAChB,IAAI,EAAE,CAAC;IACP,MAAM,E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AAE,CAAC;IACZ,GAAG,EAAE,CAAC;IACN,WAAW,EAAE,CAAC;IACd,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,aAAa,EAAE,CAAC;IAChB,SAAS,EAAE,EAAE;CACd,CAAA;AAED,MAAM,CAAC,IAAM,KAAK,GAAG;IACnB,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,SAAS;IAClB,qCAAqC,EAAE,uCAAuC;IAC9E,cAAc,EAAE,gBAAgB;IAChC,gBAAgB,EAAE,kBAAkB;IACpC,KAAK,EAAE,OAAO;CACf,CAAA","sourcesContent":["export const BATTERY_STATE = {\n IDLE: 0,\n CHARGING: 1,\n DISCHARGING: 2,\n}\n\nexport const DC_SOURCE_MONITOR_MODE = {\n WIND_GENERATOR: -8,\n}\n\nexport const VEBUS_SYSTEM_STATE = {\n OFF: 0,\n LOW_POWER: 1,\n FAULT_CONDITION: 2,\n BULK_CHARGING: 3,\n ABSORPTION_CHARGINNG: 4,\n FLOAT_CHARGING: 5,\n STORAGE_MODE: 6,\n EQUALISATION_CHARGING: 7,\n PASSTHRU: 8,\n INVERTING: 9,\n ASSISTING: 10,\n POWER_SUPPLY_MODE: 11,\n DISCHARGING: 256,\n SUSTAIN: 257,\n}\n\nexport const AC_SOURCE = {\n NOT_AVAILABLE: 0,\n GRID: 1,\n GENSET: 2,\n SHORE: 3,\n INVERTING_ISLAND_MODE: 240,\n}\n\nexport const AC_SOURCE_TYPE = {\n NOT_IN_USE: 0,\n GRID: 1,\n GENERATOR: 2,\n SHORE: 3,\n}\n\nexport const ACTIVE_INPUT = {\n INPUT_0: 0,\n INPUT_1: 1,\n NONE: 240, // Inverting\n}\n\nexport const SYSTEM_MODE = {\n CHARGER_ONLY: 1,\n INVERTER_ONLY: 2,\n ON: 3,\n OFF: 4,\n}\n\nexport const CHARGER_MODE = {\n OFF: 4,\n ON: 1,\n}\n\nexport const INVERTER_MODE = {\n ON: 2,\n VEBUS_ON: 3, // Vebus inverters use mode 3 in stead of 2 for ON.\n OFF: 4,\n ECO: 5,\n}\n\nexport const FISCHER_PANDA_GENSET_PRODUCT_ID = 45120 /// 0xB040 VE_PROD_ID_FISCHER_PANDA_GENSET\n\nexport const FISCHER_PANDA_GENSET_AUTOSTART = {\n DISABLED: 0,\n ENABLED: 1,\n}\n\nexport const RELAY_FUNCTION = {\n GENERATOR_START_STOP: 1,\n}\n\nexport const GENERATOR_START_STOP = {\n STOP: 0,\n START: 1,\n AUTO_ON: 1,\n AUTO_OFF: 0,\n}\n\nexport const TANK_FLUID_TYPE = {\n FUEL: 0,\n FRESH_WATER: 1,\n WASTE_WATER: 2,\n LIVE_WELL: 3,\n OIL: 4,\n BLACK_WATER: 5,\n GASOLINE: 5,\n DIESEL: 6,\n LPG: 7,\n LNG: 8,\n HYDRAULIC_OIL: 9,\n RAW_WATER: 10\n}\n\nexport const VIEWS = {\n CONNECTING: \"CONNECTING\",\n METRICS: \"METRICS\",\n INVERTER_CHARGER_INPUT_LIMIT_SELECTOR: \"INVERTER_CHARGER_INPUT_LIMIT_SELECTOR\",\n REMOTE_CONSOLE: \"REMOTE_CONSOLE\",\n MQTT_UNAVAILABLE: \"MQTT_UNAVAILABLE\",\n ERROR: \"ERROR\",\n}\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"/","sources":["src/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,CAAC;IACX,WAAW,EAAE,CAAC;CACf,CAAA;AAED,MAAM,CAAC,IAAM,sBAAsB,GAAG;IACpC,cAAc,EAAE,CAAC,CAAC;CACnB,CAAA;AAED,MAAM,CAAC,IAAM,kBAAkB,GAAG;IAChC,GAAG,EAAE,CAAC;IACN,SAAS,EAAE,CAAC;IACZ,eAAe,EAAE,CAAC;IAClB,aAAa,EAAE,CAAC;IAChB,oBAAoB,E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B,OAAO,EAAE,SAAS;IAClB,qCAAqC,EAAE,uCAAuC;IAC9E,cAAc,EAAE,gBAAgB;IAChC,gBAAgB,EAAE,kBAAkB;IACpC,KAAK,EAAE,OAAO;CACf,CAAA","sourcesContent":["export const BATTERY_STATE = {\n IDLE: 0,\n CHARGING: 1,\n DISCHARGING: 2,\n}\n\nexport const DC_SOURCE_MONITOR_MODE = {\n WIND_GENERATOR: -8,\n}\n\nexport const VEBUS_SYSTEM_STATE = {\n OFF: 0,\n LOW_POWER: 1,\n FAULT_CONDITION: 2,\n BULK_CHARGING: 3,\n ABSORPTION_CHARGINNG: 4,\n FLOAT_CHARGING: 5,\n STORAGE_MODE: 6,\n EQUALISATION_CHARGING: 7,\n PASSTHRU: 8,\n INVERTING: 9,\n ASSISTING: 10,\n POWER_SUPPLY_MODE: 11,\n DISCHARGING: 256,\n SUSTAIN: 257,\n}\n\nexport const AC_SOURCE = {\n NOT_AVAILABLE: 0,\n GRID: 1,\n GENSET: 2,\n SHORE: 3,\n INVERTING_ISLAND_MODE: 240,\n}\n\nexport const AC_SOURCE_TYPE = {\n NOT_IN_USE: 0,\n GRID: 1,\n GENERATOR: 2,\n SHORE: 3,\n}\n\nexport const ACTIVE_INPUT = {\n INPUT_0: 0,\n INPUT_1: 1,\n NONE: 240, // Inverting\n}\n\nexport const SYSTEM_MODE = {\n CHARGER_ONLY: 1,\n INVERTER_ONLY: 2,\n ON: 3,\n OFF: 4,\n}\n\nexport const CHARGER_MODE = {\n OFF: 4,\n ON: 1,\n}\n\nexport const INVERTER_MODE = {\n ON: 2,\n VEBUS_ON: 3, // Vebus inverters use mode 3 in stead of 2 for ON.\n OFF: 4,\n ECO: 5,\n}\n\nexport const FISCHER_PANDA_GENSET_PRODUCT_ID = 45120 /// 0xB040 VE_PROD_ID_FISCHER_PANDA_GENSET\n\nexport const FISCHER_PANDA_GENSET_AUTOSTART = {\n DISABLED: 0,\n ENABLED: 1,\n}\n\nexport const RELAY_FUNCTION = {\n GENERATOR_START_STOP: 1,\n}\n\nexport const GENERATOR_START_STOP = {\n STOP: 0,\n START: 1,\n AUTO_ON: 1,\n AUTO_OFF: 0,\n}\n\nexport const TANK_FLUID_TYPE = {\n FUEL: 0,\n FRESH_WATER: 1,\n WASTE_WATER: 2,\n LIVE_WELL: 3,\n OIL: 4,\n BLACK_WATER: 5,\n GASOLINE: 5,\n DIESEL: 6,\n LPG: 7,\n LNG: 8,\n HYDRAULIC_OIL: 9,\n RAW_WATER: 10\n}\n\n// Taken from: https://github.com/victronenergy/venus/wiki/dbus#switch\nexport const SWITCHABLE_OUTPUT_TYPE = {\n MOMENTARY_SWITCH: 0,\n TOGGLE_SWITCH: 1,\n DIMMABLE: 2,\n TEMPERATURE_SETPOINT: 3,\n STEPPED_SWITCH: 4,\n SLAVE_MODE: 5,\n DROPDOWN: 6,\n SLIDER: 7,\n UNRANGED_SETPOINT: 8,\n THREE_STATE_SWITCH: 9,\n BILGE_PUMP_CONTROL: 10,\n} as const\n\nexport type SwitchableOutputType = typeof SWITCHABLE_OUTPUT_TYPE[keyof typeof SWITCHABLE_OUTPUT_TYPE]\n\n// Taken from: https://github.com/victronenergy/venus/wiki/dbus#switch\nexport const SWITCHABLE_OUTPUT_STATUS = {\n STATUS_OFF: 0x00,\n STATUS_ON: 0x09,\n STATUS_POWERED: 0x01,\n STATUS_TRIPPED: 0x02,\n STATUS_OVER_TEMPERATURE: 0x04,\n STATUS_OUTPUT_FAULT: 0x08,\n STATUS_SHORT_FAULT: 0x10,\n STATUS_DISABLED: 0x20,\n STATUS_BYPASSED: 0x40,\n} as const\n\nexport type SwitchableOutputStatus = typeof SWITCHABLE_OUTPUT_STATUS[keyof typeof SWITCHABLE_OUTPUT_STATUS]\n\nexport const VIEWS = {\n CONNECTING: \"CONNECTING\",\n METRICS: \"METRICS\",\n INVERTER_CHARGER_INPUT_LIMIT_SELECTOR: \"INVERTER_CHARGER_INPUT_LIMIT_SELECTOR\",\n REMOTE_CONSOLE: \"REMOTE_CONSOLE\",\n MQTT_UNAVAILABLE: \"MQTT_UNAVAILABLE\",\n ERROR: \"ERROR\",\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@victronenergy/mfd-modules",
3
- "version": "9.2.3",
3
+ "version": "9.4.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",