iobroker.luxtronik2-controller 0.3.8 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -12
- package/build/actionHandlers.js +61 -29
- package/build/actionHandlers.js.map +2 -2
- package/build/logger.js +3 -5
- package/build/logger.js.map +2 -2
- package/build/main.js +4 -4
- package/build/main.js.map +2 -2
- package/build/notificationManager.js +78 -83
- package/build/notificationManager.js.map +2 -2
- package/build/objectManager.js +120 -100
- package/build/objectManager.js.map +2 -2
- package/build/rawFunctions.js +174 -199
- package/build/rawFunctions.js.map +2 -2
- package/build/virtualStates.js +66 -100
- package/build/virtualStates.js.map +2 -2
- package/build/zipManager.js +59 -31
- package/build/zipManager.js.map +2 -2
- package/io-package.json +27 -27
- package/package.json +1 -1
|
@@ -25,21 +25,47 @@ __export(notificationManager_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(notificationManager_exports);
|
|
26
26
|
var import_logger = require("./logger");
|
|
27
27
|
var import_stateMapping = require("./stateMapping");
|
|
28
|
-
function
|
|
28
|
+
function safeParse(value) {
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(value);
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function sendNotification(adapter, message) {
|
|
36
|
+
var _a;
|
|
29
37
|
const config = adapter.config;
|
|
30
|
-
|
|
38
|
+
const successMessages = [];
|
|
39
|
+
if (config.notification_bell === true) {
|
|
40
|
+
if (typeof adapter.registerNotification === "function") {
|
|
41
|
+
await adapter.registerNotification("luxtronik2-controller", "lwpError", message);
|
|
42
|
+
(0, import_logger.writeLog)("Benachrichtigung an ioBroker-Glocke gesendet.", "info");
|
|
43
|
+
successMessages.push("Glocke");
|
|
44
|
+
} else {
|
|
45
|
+
(0, import_logger.writeLog)(`\u{1F6A8} ioBroker-Glocke nicht verf\xFCgbar. Nachricht: ${message}`, "warn");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const telegramInstance = config.telegram_instance;
|
|
49
|
+
const isTelegramActive = config.telegram_enabled === true && typeof telegramInstance === "string" && // TypeScript Typen-Prüfung!
|
|
50
|
+
telegramInstance !== "none";
|
|
51
|
+
if (isTelegramActive) {
|
|
31
52
|
const sendObj = { text: message };
|
|
32
|
-
|
|
33
|
-
|
|
53
|
+
const receiver = (_a = config.telegram_receiver) == null ? void 0 : _a.trim();
|
|
54
|
+
if (receiver) {
|
|
34
55
|
if (/^-?\d+$/.test(receiver)) {
|
|
35
|
-
sendObj.chatId =
|
|
56
|
+
sendObj.chatId = Number(receiver);
|
|
36
57
|
} else {
|
|
37
58
|
sendObj.user = receiver;
|
|
38
59
|
}
|
|
39
60
|
}
|
|
40
|
-
|
|
41
|
-
(0, import_logger.writeLog)(`Telegram-Nachricht gesendet an ${
|
|
61
|
+
adapter.sendTo(telegramInstance, "send", sendObj);
|
|
62
|
+
(0, import_logger.writeLog)(`Telegram-Nachricht gesendet an ${telegramInstance}`, "info");
|
|
63
|
+
successMessages.push("Telegram");
|
|
42
64
|
}
|
|
65
|
+
return successMessages;
|
|
66
|
+
}
|
|
67
|
+
function sendTelegramNotification(adapter, message) {
|
|
68
|
+
void sendNotification(adapter, message);
|
|
43
69
|
}
|
|
44
70
|
async function handleTestMessage(adapter, obj) {
|
|
45
71
|
try {
|
|
@@ -49,7 +75,7 @@ async function handleTestMessage(adapter, obj) {
|
|
|
49
75
|
const isIoBrokerNotifyActive = config.notification_bell === true;
|
|
50
76
|
if (!isTelegramActive && !isIoBrokerNotifyActive) {
|
|
51
77
|
if (obj.callback) {
|
|
52
|
-
|
|
78
|
+
adapter.sendTo(
|
|
53
79
|
obj.from,
|
|
54
80
|
obj.command,
|
|
55
81
|
{
|
|
@@ -60,54 +86,36 @@ async function handleTestMessage(adapter, obj) {
|
|
|
60
86
|
}
|
|
61
87
|
return;
|
|
62
88
|
}
|
|
63
|
-
const
|
|
89
|
+
const errorPath = (0, import_stateMapping.getDpPath)("Fehlerspeicher");
|
|
90
|
+
const lastErrorState = errorPath ? await adapter.getStateAsync(errorPath) : null;
|
|
64
91
|
let msg = "";
|
|
65
92
|
if (lastErrorState && typeof lastErrorState.val === "string") {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
93
|
+
const errorList = safeParse(lastErrorState.val);
|
|
94
|
+
if (errorList && errorList.length > 0) {
|
|
95
|
+
const newestError = errorList[0];
|
|
96
|
+
msg = `\u{1F6A8} *Test-Alarm: Fehlerspeicher*
|
|
97
|
+
|
|
98
|
+
Aktuellster Fehler:
|
|
72
99
|
Code: ${newestError.code}
|
|
73
100
|
Fehler: ${newestError.beschreibung}
|
|
74
101
|
Datum: ${newestError.datum}
|
|
75
102
|
|
|
76
103
|
`;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
Fehler: ${errorList[i].beschreibung}
|
|
84
|
-
|
|
85
|
-
`;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
104
|
+
if (errorList.length > 1) {
|
|
105
|
+
const history = errorList.slice(1).map((e) => `Datum: ${e.datum}
|
|
106
|
+
Code: ${e.code}
|
|
107
|
+
Fehler: ${e.beschreibung}`).join("\n\n");
|
|
108
|
+
msg += `Historie:
|
|
109
|
+
${history}`;
|
|
88
110
|
}
|
|
89
|
-
} catch (parseErr) {
|
|
90
|
-
(0, import_logger.writeLog)(`JSON Parse-Fehler beim Test-Button: ${parseErr.message}`, "debug");
|
|
91
111
|
}
|
|
92
112
|
}
|
|
93
113
|
if (msg === "") {
|
|
94
114
|
msg = "\u2705 *Erfolgreicher Test*\n\nDies ist eine generierte Test-Nachricht. Die Kommunikation zu Telegram und ioBroker funktioniert einwandfrei! (Es liegen aktuell keine echten Heizungsfehler vor).";
|
|
95
115
|
}
|
|
96
|
-
const successMessages =
|
|
97
|
-
if (isIoBrokerNotifyActive) {
|
|
98
|
-
if (typeof adapter.registerNotification === "function") {
|
|
99
|
-
await adapter.registerNotification("luxtronik2-controller", "lwpError", msg);
|
|
100
|
-
(0, import_logger.writeLog)("Test-Benachrichtigung an ioBroker-Glocke gesendet.", "info");
|
|
101
|
-
successMessages.push("Glocke");
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (isTelegramActive) {
|
|
105
|
-
sendTelegramNotification(adapter, msg);
|
|
106
|
-
(0, import_logger.writeLog)(`Test-Fehlermeldung via Telegram versendet an ${config.telegram_instance}.`, "info");
|
|
107
|
-
successMessages.push("Telegram");
|
|
108
|
-
}
|
|
116
|
+
const successMessages = await sendNotification(adapter, msg);
|
|
109
117
|
if (obj.callback) {
|
|
110
|
-
|
|
118
|
+
adapter.sendTo(
|
|
111
119
|
obj.from,
|
|
112
120
|
obj.command,
|
|
113
121
|
{ result: `Erfolgreich ausgel\xF6st: ${successMessages.join(" & ")}` },
|
|
@@ -115,56 +123,43 @@ Fehler: ${errorList[i].beschreibung}
|
|
|
115
123
|
);
|
|
116
124
|
}
|
|
117
125
|
} catch (err) {
|
|
118
|
-
|
|
126
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
127
|
+
(0, import_logger.writeLog)(`Fehler beim Test-Button: ${errorMessage}`, "error");
|
|
119
128
|
if (obj.callback) {
|
|
120
|
-
|
|
129
|
+
adapter.sendTo(obj.from, obj.command, { error: `Skriptfehler: ${errorMessage}` }, obj.callback);
|
|
121
130
|
}
|
|
122
131
|
}
|
|
123
132
|
}
|
|
124
133
|
async function checkAndSendErrorNotifications(adapter, oldFehlerVal, newFehlerVal) {
|
|
125
|
-
if (newFehlerVal
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
if (!newFehlerVal || newFehlerVal === oldFehlerVal) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const newList = safeParse(newFehlerVal);
|
|
138
|
+
if (!newList || newList.length === 0) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const newestError = newList[0];
|
|
142
|
+
const currentErrorTimestamp = newestError.timestamp;
|
|
143
|
+
const currentErrorCode = newestError.code;
|
|
144
|
+
if (currentErrorTimestamp === void 0 || currentErrorCode === 0) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const oldList = oldFehlerVal ? safeParse(oldFehlerVal) : [];
|
|
148
|
+
const oldNewestError = oldList && oldList.length > 0 ? oldList[0] : null;
|
|
149
|
+
if (oldNewestError && currentErrorTimestamp === oldNewestError.timestamp) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (adapter.lastKnownErrorTimestamp !== null && adapter.lastKnownErrorTimestamp !== void 0 && currentErrorTimestamp <= adapter.lastKnownErrorTimestamp) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
adapter.lastKnownErrorTimestamp = currentErrorTimestamp;
|
|
156
|
+
const msg = `\u{1F6A8} *St\xF6rung W\xE4rmepumpe!*
|
|
134
157
|
Ein Fehler an der W\xE4rmepumpe wurde registriert:
|
|
135
158
|
|
|
136
|
-
*Code:* ${
|
|
159
|
+
*Code:* ${currentErrorCode}
|
|
137
160
|
*Fehler:* ${newestError.beschreibung}
|
|
138
161
|
*Datum:* ${newestError.datum}`;
|
|
139
|
-
|
|
140
|
-
const currentErrorCode = newestError.code;
|
|
141
|
-
if (adapter.lastKnownErrorTimestamp === null) {
|
|
142
|
-
if (currentErrorTimestamp !== void 0) {
|
|
143
|
-
adapter.lastKnownErrorTimestamp = currentErrorTimestamp;
|
|
144
|
-
}
|
|
145
|
-
} else if (currentErrorTimestamp !== void 0 && currentErrorTimestamp > adapter.lastKnownErrorTimestamp) {
|
|
146
|
-
adapter.lastKnownErrorTimestamp = currentErrorTimestamp;
|
|
147
|
-
if (currentErrorCode !== 0) {
|
|
148
|
-
sendTelegramNotification(adapter, msg);
|
|
149
|
-
const config = adapter.config;
|
|
150
|
-
if (config.notification_bell) {
|
|
151
|
-
if (typeof adapter.registerNotification === "function") {
|
|
152
|
-
await adapter.registerNotification("luxtronik2-controller", "lwpError", msg);
|
|
153
|
-
} else {
|
|
154
|
-
(0, import_logger.writeLog)(
|
|
155
|
-
`\u{1F6A8} W\xE4rmepumpen-Fehler: Code ${newestError.code} - ${newestError.beschreibung}`,
|
|
156
|
-
"warn"
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
} catch {
|
|
165
|
-
(0, import_logger.writeLog)("Konnte Fehlerhistorie f\xFCr Benachrichtigungen nicht parsen.", "debug");
|
|
166
|
-
}
|
|
167
|
-
}
|
|
162
|
+
await sendNotification(adapter, msg);
|
|
168
163
|
}
|
|
169
164
|
// Annotate the CommonJS export names for ESM import in node:
|
|
170
165
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/notificationManager.ts"],
|
|
4
|
-
"sourcesContent": ["import { writeLog } from './logger';\nimport { getDpPath } from './stateMapping';\n\n// =========================================================\n//
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import type { AdapterInstance } from '@iobroker/adapter-core';\nimport { writeLog } from './logger';\nimport { getDpPath } from './stateMapping';\n\n// =========================================================\n// INTERFACES & TYPEN\n// =========================================================\n\n/**\n * Struktur eines Fehlerspeichereintrags der Luxtronik W\u00E4rmepumpe.\n */\nexport interface ErrorHistoryEntry {\n\t/** Der Fehlercode der W\u00E4rmepumpe (z.B. 704) */\n\tcode: number;\n\t/** Die Klartextbeschreibung des Fehlers */\n\tbeschreibung: string;\n\t/** Das formatierte Datum (de-DE) */\n\tdatum: string;\n\t/** Der rohe UNIX-Timestamp des Fehlers */\n\ttimestamp?: number;\n}\n\n/**\n * Erweiterte Schnittstelle f\u00FCr den ioBroker-Adapter zur Typsicherheit interner Attribute.\n */\nexport interface ExtendedAdapter extends AdapterInstance {\n\t/** Die Adapter-Konfiguration aus der io-package.json kombiniert mit dynamischen Werten */\n\tconfig: ioBroker.AdapterConfig & Record<string, any>;\n\t/** Speichert den Timestamp des zuletzt gemeldeten Fehlers, um doppelte Alarme zu vermeiden */\n\tlastKnownErrorTimestamp?: number | null;\n}\n\n// =========================================================\n// HILFSFUNKTIONEN\n// =========================================================\n\n/**\n * Parst einen JSON-String typsicher und f\u00E4ngt Fehler lautlos ab.\n *\n * @param value Der zu parsende JSON-String.\n * @returns Das geparste Objekt im angegebenen Typ T oder null, falls das Parsen fehlschl\u00E4gt.\n */\nfunction safeParse<T>(value: string): T | null {\n\ttry {\n\t\treturn JSON.parse(value) as T;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Zentrale Funktion zum Versenden von Benachrichtigungen \u00FCber alle konfigurierten Kan\u00E4le (Telegram & ioBroker-Glocke).\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param message Die zu versendende Nachricht als Markdown-formatierter String.\n * @returns Ein Array mit den Namen der erfolgreich genutzten Kommunikationskan\u00E4le.\n */\nasync function sendNotification(adapter: ExtendedAdapter, message: string): Promise<string[]> {\n\tconst config = adapter.config;\n\tconst successMessages: string[] = [];\n\n\t// 1. ioBroker-Glocke (Notification Manager)\n\tif (config.notification_bell === true) {\n\t\tif (typeof adapter.registerNotification === 'function') {\n\t\t\tawait adapter.registerNotification('luxtronik2-controller', 'lwpError', message);\n\t\t\twriteLog('Benachrichtigung an ioBroker-Glocke gesendet.', 'info');\n\t\t\tsuccessMessages.push('Glocke');\n\t\t} else {\n\t\t\twriteLog(`\uD83D\uDEA8 ioBroker-Glocke nicht verf\u00FCgbar. Nachricht: ${message}`, 'warn');\n\t\t}\n\t}\n\n\t// 2. Telegram\n\tconst telegramInstance = config.telegram_instance; // Wert sicher zwischenspeichern\n\tconst isTelegramActive =\n\t\tconfig.telegram_enabled === true &&\n\t\ttypeof telegramInstance === 'string' && // TypeScript Typen-Pr\u00FCfung!\n\t\ttelegramInstance !== 'none';\n\n\tif (isTelegramActive) {\n\t\tconst sendObj: Record<string, any> = { text: message };\n\t\tconst receiver = config.telegram_receiver?.trim();\n\n\t\tif (receiver) {\n\t\t\tif (/^-?\\d+$/.test(receiver)) {\n\t\t\t\tsendObj.chatId = Number(receiver);\n\t\t\t} else {\n\t\t\t\tsendObj.user = receiver;\n\t\t\t}\n\t\t}\n\n\t\t// Jetzt wei\u00DF TS absolut sicher, dass telegramInstance ein String ist!\n\t\tadapter.sendTo(telegramInstance, 'send', sendObj);\n\t\twriteLog(`Telegram-Nachricht gesendet an ${telegramInstance}`, 'info');\n\t\tsuccessMessages.push('Telegram');\n\t}\n\n\treturn successMessages;\n}\n\n/**\n * R\u00FCckw\u00E4rtskompatibler Wrapper, falls die main.ts direkt Telegram-Nachrichten verschickt.\n * Leitet die Anfrage an die neue, universelle Benachrichtigungsfunktion weiter.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param message Die zu versendende Nachricht.\n */\nexport function sendTelegramNotification(adapter: ExtendedAdapter, message: string): void {\n\t// void signalisiert dem Linter, dass wir das Promise absichtlich nicht abwarten\n\tvoid sendNotification(adapter, message);\n}\n\n// =========================================================\n// TEST-BUTTON AUS DER OBERFL\u00C4CHE BEHANDELN\n// =========================================================\n\n/**\n * Behandelt eingehende Test-Nachrichten aus der ioBroker-Admin Oberfl\u00E4che (Test-Button).\n * Sammelt die Fehlerhistorie und versendet einen Test-Alarm.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param obj Das empfangene ioBroker-Nachrichtenobjekt inkl. Callback.\n */\nexport async function handleTestMessage(adapter: ExtendedAdapter, obj: ioBroker.Message): Promise<void> {\n\ttry {\n\t\twriteLog('Test-Button empfangen!', 'info');\n\t\tconst config = adapter.config;\n\n\t\tconst isTelegramActive =\n\t\t\tconfig.telegram_enabled === true && config.telegram_instance && config.telegram_instance !== 'none';\n\t\tconst isIoBrokerNotifyActive = config.notification_bell === true;\n\n\t\t// Abbruch, wenn kein Kanal konfiguriert ist\n\t\tif (!isTelegramActive && !isIoBrokerNotifyActive) {\n\t\t\tif (obj.callback) {\n\t\t\t\tadapter.sendTo(\n\t\t\t\t\tobj.from,\n\t\t\t\t\tobj.command,\n\t\t\t\t\t{\n\t\t\t\t\t\terror: 'Fehler: Weder Telegram noch Glocke sind aktiv gespeichert! Bitte erst SPEICHERN klicken.',\n\t\t\t\t\t},\n\t\t\t\t\tobj.callback,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst errorPath = getDpPath('Fehlerspeicher');\n\t\tconst lastErrorState = errorPath ? await adapter.getStateAsync(errorPath) : null;\n\t\tlet msg = '';\n\n\t\t// Historie auslesen und formatieren\n\t\tif (lastErrorState && typeof lastErrorState.val === 'string') {\n\t\t\tconst errorList = safeParse<ErrorHistoryEntry[]>(lastErrorState.val);\n\n\t\t\tif (errorList && errorList.length > 0) {\n\t\t\t\tconst newestError = errorList[0];\n\t\t\t\tmsg = `\uD83D\uDEA8 *Test-Alarm: Fehlerspeicher*\\n\\nAktuellster Fehler:\\nCode: ${newestError.code}\\nFehler: ${newestError.beschreibung}\\nDatum: ${newestError.datum}\\n\\n`;\n\n\t\t\t\tif (errorList.length > 1) {\n\t\t\t\t\tconst history = errorList\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map(e => `Datum: ${e.datum}\\nCode: ${e.code}\\nFehler: ${e.beschreibung}`)\n\t\t\t\t\t\t.join('\\n\\n');\n\t\t\t\t\tmsg += `Historie:\\n${history}`;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Fallback, falls der Fehlerspeicher komplett leer ist\n\t\tif (msg === '') {\n\t\t\tmsg =\n\t\t\t\t'\u2705 *Erfolgreicher Test*\\n\\nDies ist eine generierte Test-Nachricht. Die Kommunikation zu Telegram und ioBroker funktioniert einwandfrei! (Es liegen aktuell keine echten Heizungsfehler vor).';\n\t\t}\n\n\t\t// Zentrale Benachrichtigung ausl\u00F6sen\n\t\tconst successMessages = await sendNotification(adapter, msg);\n\n\t\t// Ergebnis an die UI zur\u00FCckmelden\n\t\tif (obj.callback) {\n\t\t\tadapter.sendTo(\n\t\t\t\tobj.from,\n\t\t\t\tobj.command,\n\t\t\t\t{ result: `Erfolgreich ausgel\u00F6st: ${successMessages.join(' & ')}` },\n\t\t\t\tobj.callback,\n\t\t\t);\n\t\t}\n\t} catch (err: unknown) {\n\t\tconst errorMessage = err instanceof Error ? err.message : String(err);\n\t\twriteLog(`Fehler beim Test-Button: ${errorMessage}`, 'error');\n\t\tif (obj.callback) {\n\t\t\tadapter.sendTo(obj.from, obj.command, { error: `Skriptfehler: ${errorMessage}` }, obj.callback);\n\t\t}\n\t}\n}\n\n// =========================================================\n// INTELLIGENTER FEHLER-FILTER UND ALARM\n// =========================================================\n\n/**\n * \u00DCberpr\u00FCft \u00C4nderungen im Fehlerspeicher, filtert bekannte Fehler heraus und\n * l\u00F6st bei neu aufgetretenen, echten W\u00E4rmepumpen-Fehlern einen Alarm aus.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param oldFehlerVal Der vorherige Zustand des Fehlerspeichers als JSON-String.\n * @param newFehlerVal Der neue Zustand des Fehlerspeichers als JSON-String.\n */\nexport async function checkAndSendErrorNotifications(\n\tadapter: ExtendedAdapter,\n\toldFehlerVal: string | undefined,\n\tnewFehlerVal: string | undefined,\n): Promise<void> {\n\t// Guard Clause: Wenn sich nichts ge\u00E4ndert hat oder der Wert leer ist, direkt abbrechen\n\tif (!newFehlerVal || newFehlerVal === oldFehlerVal) {\n\t\treturn;\n\t}\n\n\tconst newList = safeParse<ErrorHistoryEntry[]>(newFehlerVal);\n\tif (!newList || newList.length === 0) {\n\t\treturn;\n\t}\n\n\tconst newestError = newList[0];\n\tconst currentErrorTimestamp = newestError.timestamp;\n\tconst currentErrorCode = newestError.code;\n\n\t// Guard Clause: Ung\u00FCltiger Timestamp oder Dummy-Fehlercode (0)\n\tif (currentErrorTimestamp === undefined || currentErrorCode === 0) {\n\t\treturn;\n\t}\n\n\tconst oldList = oldFehlerVal ? safeParse<ErrorHistoryEntry[]>(oldFehlerVal) : [];\n\tconst oldNewestError = oldList && oldList.length > 0 ? oldList[0] : null;\n\n\t// Guard Clause: Fehler ist identisch mit dem vorherigen (gleicher Timestamp)\n\tif (oldNewestError && currentErrorTimestamp === oldNewestError.timestamp) {\n\t\treturn;\n\t}\n\n\t// Guard Clause: Fehler ist \u00E4lter oder gleich dem zuletzt gemeldeten (Schutz vor Endlosschleifen)\n\tif (\n\t\tadapter.lastKnownErrorTimestamp !== null &&\n\t\tadapter.lastKnownErrorTimestamp !== undefined &&\n\t\tcurrentErrorTimestamp <= adapter.lastKnownErrorTimestamp\n\t) {\n\t\treturn;\n\t}\n\n\t// Timestamp speichern, um mehrfache Benachrichtigungen f\u00FCr denselben Fehler zu verhindern\n\tadapter.lastKnownErrorTimestamp = currentErrorTimestamp;\n\n\tconst msg = `\uD83D\uDEA8 *St\u00F6rung W\u00E4rmepumpe!*\\nEin Fehler an der W\u00E4rmepumpe wurde registriert:\\n\\n*Code:* ${currentErrorCode}\\n*Fehler:* ${newestError.beschreibung}\\n*Datum:* ${newestError.datum}`;\n\n\tawait sendNotification(adapter, msg);\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/objectManager.js
CHANGED
|
@@ -29,85 +29,78 @@ __export(objectManager_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(objectManager_exports);
|
|
30
30
|
var import_logger = require("./logger");
|
|
31
31
|
var import_stateMapping = require("./stateMapping");
|
|
32
|
+
const PREFIX_MAPPING = [
|
|
33
|
+
["HZ_MoSo_", "sync_heatingOperationTimerTableWeek"],
|
|
34
|
+
["HZ_MoFr_", "sync_heatingOperationTimerTable52MonFri"],
|
|
35
|
+
["HZ_SaSo_", "sync_heatingOperationTimerTable52MonFri"],
|
|
36
|
+
["HZ_Montag_", "sync_heatingOperationTimerTableDayMonday"],
|
|
37
|
+
["HZ_Dienstag_", "sync_heatingOperationTimerTableDayTuesday"],
|
|
38
|
+
["HZ_Mittwoch_", "sync_heatingOperationTimerTableDayWednesday"],
|
|
39
|
+
["HZ_Donnerstag_", "sync_heatingOperationTimerTableDayThursday"],
|
|
40
|
+
["HZ_Freitag_", "sync_heatingOperationTimerTableDayFriday"],
|
|
41
|
+
["HZ_Samstag_", "sync_heatingOperationTimerTableDaySaturday"],
|
|
42
|
+
["HZ_Sonntag_", "sync_heatingOperationTimerTableDaySunday"],
|
|
43
|
+
["WW_MoSo_", "sync_hotWaterTableWeek"],
|
|
44
|
+
["WW_MoFr_", "sync_hotWaterTable52MonFri"],
|
|
45
|
+
["WW_SaSo_", "sync_hotWaterTable52MonFri"],
|
|
46
|
+
["WW_Montag_", "sync_hotWaterTableDayMonday"],
|
|
47
|
+
["WW_Dienstag_", "sync_hotWaterTableDayTuesday"],
|
|
48
|
+
["WW_Mittwoch_", "sync_hotWaterTableDayWednesday"],
|
|
49
|
+
["WW_Donnerstag_", "sync_hotWaterTableDayThursday"],
|
|
50
|
+
["WW_Freitag_", "sync_hotWaterTableDayFriday"],
|
|
51
|
+
["WW_Samstag_", "sync_hotWaterTableDaySaturday"],
|
|
52
|
+
["WW_Sonntag_", "sync_hotWaterTableDaySunday"],
|
|
53
|
+
["Zirkulation_MoSo_", "sync_hotWaterCircPumpTimerTableWeek"],
|
|
54
|
+
["Zirkulation_MoFr_", "sync_hotWaterCircPumpTimerTable52MonFri"],
|
|
55
|
+
["Zirkulation_SaSo_", "sync_hotWaterCircPumpTimerTable52MonFri"],
|
|
56
|
+
["Zirkulation_Montag_", "sync_hotWaterCircPumpTimerTableDayMonday"],
|
|
57
|
+
["Zirkulation_Dienstag_", "sync_hotWaterCircPumpTimerTableDayTuesday"],
|
|
58
|
+
["Zirkulation_Mittwoch_", "sync_hotWaterCircPumpTimerTableDayWednesday"],
|
|
59
|
+
["Zirkulation_Donnerstag_", "sync_hotWaterCircPumpTimerTableDayThursday"],
|
|
60
|
+
["Zirkulation_Freitag_", "sync_hotWaterCircPumpTimerTableDayFriday"],
|
|
61
|
+
["Zirkulation_Samstag_", "sync_hotWaterCircPumpTimerTableDaySaturday"],
|
|
62
|
+
["Zirkulation_Sonntag_", "sync_hotWaterCircPumpTimerTableDaySunday"]
|
|
63
|
+
];
|
|
32
64
|
function isStateEnabled(key, definition, config) {
|
|
33
65
|
if (definition.required) {
|
|
34
66
|
return true;
|
|
35
67
|
}
|
|
36
68
|
const configKey = `sync_${key}`;
|
|
37
|
-
let isEnabled = true;
|
|
38
69
|
if (config[configKey] === false || String(config[configKey]) === "false") {
|
|
39
|
-
|
|
70
|
+
return false;
|
|
40
71
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} else if (key.startsWith("HZ_Montag_")) {
|
|
46
|
-
isEnabled = config.sync_heatingOperationTimerTableDayMonday !== false;
|
|
47
|
-
} else if (key.startsWith("HZ_Dienstag_")) {
|
|
48
|
-
isEnabled = config.sync_heatingOperationTimerTableDayTuesday !== false;
|
|
49
|
-
} else if (key.startsWith("HZ_Mittwoch_")) {
|
|
50
|
-
isEnabled = config.sync_heatingOperationTimerTableDayWednesday !== false;
|
|
51
|
-
} else if (key.startsWith("HZ_Donnerstag_")) {
|
|
52
|
-
isEnabled = config.sync_heatingOperationTimerTableDayThursday !== false;
|
|
53
|
-
} else if (key.startsWith("HZ_Freitag_")) {
|
|
54
|
-
isEnabled = config.sync_heatingOperationTimerTableDayFriday !== false;
|
|
55
|
-
} else if (key.startsWith("HZ_Samstag_")) {
|
|
56
|
-
isEnabled = config.sync_heatingOperationTimerTableDaySaturday !== false;
|
|
57
|
-
} else if (key.startsWith("HZ_Sonntag_")) {
|
|
58
|
-
isEnabled = config.sync_heatingOperationTimerTableDaySunday !== false;
|
|
59
|
-
} else if (key.startsWith("WW_MoSo_")) {
|
|
60
|
-
isEnabled = config.sync_hotWaterTableWeek !== false;
|
|
61
|
-
} else if (key.startsWith("WW_MoFr_") || key.startsWith("WW_SaSo_")) {
|
|
62
|
-
isEnabled = config.sync_hotWaterTable52MonFri !== false;
|
|
63
|
-
} else if (key.startsWith("WW_Montag_")) {
|
|
64
|
-
isEnabled = config.sync_hotWaterTableDayMonday !== false;
|
|
65
|
-
} else if (key.startsWith("WW_Dienstag_")) {
|
|
66
|
-
isEnabled = config.sync_hotWaterTableDayTuesday !== false;
|
|
67
|
-
} else if (key.startsWith("WW_Mittwoch_")) {
|
|
68
|
-
isEnabled = config.sync_hotWaterTableDayWednesday !== false;
|
|
69
|
-
} else if (key.startsWith("WW_Donnerstag_")) {
|
|
70
|
-
isEnabled = config.sync_hotWaterTableDayThursday !== false;
|
|
71
|
-
} else if (key.startsWith("WW_Freitag_")) {
|
|
72
|
-
isEnabled = config.sync_hotWaterTableDayFriday !== false;
|
|
73
|
-
} else if (key.startsWith("WW_Samstag_")) {
|
|
74
|
-
isEnabled = config.sync_hotWaterTableDaySaturday !== false;
|
|
75
|
-
} else if (key.startsWith("WW_Sonntag_")) {
|
|
76
|
-
isEnabled = config.sync_hotWaterTableDaySunday !== false;
|
|
77
|
-
} else if (key.startsWith("Zirkulation_MoSo_")) {
|
|
78
|
-
isEnabled = config.sync_hotWaterCircPumpTimerTableWeek !== false;
|
|
79
|
-
} else if (key.startsWith("Zirkulation_MoFr_") || key.startsWith("Zirkulation_SaSo_")) {
|
|
80
|
-
isEnabled = config.sync_hotWaterCircPumpTimerTable52MonFri !== false;
|
|
81
|
-
} else if (key.startsWith("Zirkulation_Montag_")) {
|
|
82
|
-
isEnabled = config.sync_hotWaterCircPumpTimerTableDayMonday !== false;
|
|
83
|
-
} else if (key.startsWith("Zirkulation_Dienstag_")) {
|
|
84
|
-
isEnabled = config.sync_hotWaterCircPumpTimerTableDayTuesday !== false;
|
|
85
|
-
} else if (key.startsWith("Zirkulation_Mittwoch_")) {
|
|
86
|
-
isEnabled = config.sync_hotWaterCircPumpTimerTableDayWednesday !== false;
|
|
87
|
-
} else if (key.startsWith("Zirkulation_Donnerstag_")) {
|
|
88
|
-
isEnabled = config.sync_hotWaterCircPumpTimerTableDayThursday !== false;
|
|
89
|
-
} else if (key.startsWith("Zirkulation_Freitag_")) {
|
|
90
|
-
isEnabled = config.sync_hotWaterCircPumpTimerTableDayFriday !== false;
|
|
91
|
-
} else if (key.startsWith("Zirkulation_Samstag_")) {
|
|
92
|
-
isEnabled = config.sync_hotWaterCircPumpTimerTableDaySaturday !== false;
|
|
93
|
-
} else if (key.startsWith("Zirkulation_Sonntag_")) {
|
|
94
|
-
isEnabled = config.sync_hotWaterCircPumpTimerTableDaySunday !== false;
|
|
72
|
+
for (const [prefix, mapKey] of PREFIX_MAPPING) {
|
|
73
|
+
if (key.startsWith(prefix)) {
|
|
74
|
+
return config[mapKey] !== false;
|
|
75
|
+
}
|
|
95
76
|
}
|
|
96
|
-
return
|
|
77
|
+
return true;
|
|
97
78
|
}
|
|
79
|
+
const CHAR_MAP = {
|
|
80
|
+
\u00E4: "ae",
|
|
81
|
+
\u00F6: "oe",
|
|
82
|
+
\u00FC: "ue",
|
|
83
|
+
\u00C4: "Ae",
|
|
84
|
+
\u00D6: "Oe",
|
|
85
|
+
\u00DC: "Ue",
|
|
86
|
+
\u00DF: "ss"
|
|
87
|
+
};
|
|
98
88
|
function sanitizeName(name) {
|
|
99
|
-
return name.replace(
|
|
89
|
+
return name.replace(/[äöüÄÖÜß]/g, (match) => CHAR_MAP[match]).replace(/[^a-zA-Z0-9_]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
100
90
|
}
|
|
101
91
|
async function cleanupStates(adapter) {
|
|
102
92
|
const config = adapter.config;
|
|
103
93
|
const activeStateIds = /* @__PURE__ */ new Set();
|
|
104
|
-
for (const [key,
|
|
94
|
+
for (const [key, def] of Object.entries(import_stateMapping.STATE_MAPPING)) {
|
|
95
|
+
const definition = def;
|
|
105
96
|
if (isStateEnabled(key, definition, config)) {
|
|
106
97
|
activeStateIds.add(`${definition.folder}.${key}`);
|
|
107
98
|
}
|
|
108
99
|
}
|
|
109
100
|
try {
|
|
110
101
|
const objects = await adapter.getAdapterObjectsAsync();
|
|
102
|
+
let deletedCount = 0;
|
|
103
|
+
const deletions = [];
|
|
111
104
|
for (const fullId in objects) {
|
|
112
105
|
const obj = objects[fullId];
|
|
113
106
|
if (obj && obj.type === "state") {
|
|
@@ -116,20 +109,25 @@ async function cleanupStates(adapter) {
|
|
|
116
109
|
continue;
|
|
117
110
|
}
|
|
118
111
|
if (!activeStateIds.has(localId)) {
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
});
|
|
112
|
+
deletions.push(adapter.delStateAsync(localId).catch(() => {
|
|
113
|
+
}));
|
|
114
|
+
deletions.push(adapter.delObjectAsync(localId).catch(() => {
|
|
115
|
+
}));
|
|
123
116
|
adapter.createdStates.delete(localId);
|
|
124
|
-
(0, import_logger.writeLog)(
|
|
125
|
-
|
|
126
|
-
"info"
|
|
127
|
-
);
|
|
117
|
+
(0, import_logger.writeLog)(`Datenpunkt '${localId}' rigoros entfernt.`, "debug");
|
|
118
|
+
deletedCount++;
|
|
128
119
|
}
|
|
129
120
|
}
|
|
130
121
|
}
|
|
122
|
+
if (deletions.length > 0) {
|
|
123
|
+
await Promise.all(deletions);
|
|
124
|
+
}
|
|
125
|
+
if (deletedCount > 0) {
|
|
126
|
+
(0, import_logger.writeLog)(`${deletedCount} alte Datenpunkte aufger\xE4umt.`, "info");
|
|
127
|
+
}
|
|
131
128
|
} catch (err) {
|
|
132
|
-
|
|
129
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
130
|
+
(0, import_logger.writeLog)(`Fehler beim Aufr\xE4umen von alten Datenpunkten: ${msg}`, "error");
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
133
|
async function cleanupEmptyFolders(adapter) {
|
|
@@ -142,55 +140,83 @@ async function cleanupEmptyFolders(adapter) {
|
|
|
142
140
|
return type === "channel" || type === "folder" || type === "device";
|
|
143
141
|
});
|
|
144
142
|
folderIds.sort((a, b) => b.length - a.length);
|
|
143
|
+
const existingParents = /* @__PURE__ */ new Set();
|
|
144
|
+
for (const id of allIds) {
|
|
145
|
+
let parent = id;
|
|
146
|
+
while (parent.includes(".")) {
|
|
147
|
+
parent = parent.substring(0, parent.lastIndexOf("."));
|
|
148
|
+
existingParents.add(parent);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
let deletedCount = 0;
|
|
152
|
+
const deletions = [];
|
|
145
153
|
for (const fullId of folderIds) {
|
|
146
154
|
if (fullId === adapter.namespace) {
|
|
147
155
|
continue;
|
|
148
156
|
}
|
|
149
|
-
|
|
150
|
-
const hasChildren = allIds.some((id) => id !== fullId && id.startsWith(prefix) && objects[id] !== void 0);
|
|
151
|
-
if (!hasChildren) {
|
|
157
|
+
if (!existingParents.has(fullId)) {
|
|
152
158
|
const localId = fullId.replace(`${adapter.namespace}.`, "");
|
|
153
|
-
|
|
154
|
-
});
|
|
155
|
-
(0, import_logger.writeLog)(`Leerer Ordner '${localId}'
|
|
156
|
-
|
|
159
|
+
deletions.push(adapter.delObjectAsync(localId).catch(() => {
|
|
160
|
+
}));
|
|
161
|
+
(0, import_logger.writeLog)(`Leerer Ordner '${localId}' aufger\xE4umt.`, "debug");
|
|
162
|
+
deletedCount++;
|
|
157
163
|
}
|
|
158
164
|
}
|
|
165
|
+
if (deletions.length > 0) {
|
|
166
|
+
await Promise.all(deletions);
|
|
167
|
+
}
|
|
168
|
+
if (deletedCount > 0) {
|
|
169
|
+
(0, import_logger.writeLog)(`${deletedCount} leere Ordner aus dem Objektbaum entfernt.`, "info");
|
|
170
|
+
}
|
|
159
171
|
} catch (err) {
|
|
160
|
-
|
|
172
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
173
|
+
(0, import_logger.writeLog)(`Fehler beim Aufr\xE4umen leerer Ordner: ${msg}`, "error");
|
|
161
174
|
}
|
|
162
175
|
}
|
|
163
176
|
async function cleanupCustomStates(adapter) {
|
|
164
177
|
const config = adapter.config;
|
|
165
178
|
const customStates = config.custom_states || [];
|
|
166
|
-
const activeIds =
|
|
179
|
+
const activeIds = new Set(
|
|
180
|
+
customStates.filter((c) => c.active && c.luxId !== void 0 && c.name).map((c) => `Benutzer.${sanitizeName(c.name)}`)
|
|
181
|
+
);
|
|
167
182
|
try {
|
|
168
183
|
const objects = await adapter.getAdapterObjectsAsync();
|
|
184
|
+
let deletedCount = 0;
|
|
185
|
+
const deletions = [];
|
|
169
186
|
for (const id in objects) {
|
|
170
187
|
if (id.startsWith(`${adapter.namespace}.Benutzer.`)) {
|
|
171
188
|
const shortId = id.replace(`${adapter.namespace}.`, "");
|
|
172
189
|
if (shortId === "Benutzer") {
|
|
173
190
|
continue;
|
|
174
191
|
}
|
|
175
|
-
if (!activeIds.
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
});
|
|
192
|
+
if (!activeIds.has(shortId)) {
|
|
193
|
+
deletions.push(adapter.delStateAsync(shortId).catch(() => {
|
|
194
|
+
}));
|
|
195
|
+
deletions.push(adapter.delObjectAsync(shortId).catch(() => {
|
|
196
|
+
}));
|
|
180
197
|
adapter.createdStates.delete(shortId);
|
|
181
|
-
(0, import_logger.writeLog)(`Benutzerdefinierter Datenpunkt '${shortId}' entfernt.`, "
|
|
198
|
+
(0, import_logger.writeLog)(`Benutzerdefinierter Datenpunkt '${shortId}' entfernt.`, "debug");
|
|
199
|
+
deletedCount++;
|
|
182
200
|
}
|
|
183
201
|
}
|
|
184
202
|
}
|
|
203
|
+
if (deletions.length > 0) {
|
|
204
|
+
await Promise.all(deletions);
|
|
205
|
+
}
|
|
206
|
+
if (deletedCount > 0) {
|
|
207
|
+
(0, import_logger.writeLog)(`${deletedCount} benutzerdefinierte Werte aufger\xE4umt.`, "info");
|
|
208
|
+
}
|
|
185
209
|
} catch (err) {
|
|
186
|
-
|
|
210
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
211
|
+
(0, import_logger.writeLog)(`Fehler beim Aufr\xE4umen benutzerdefinierter Werte: ${msg}`, "error");
|
|
187
212
|
}
|
|
188
213
|
}
|
|
189
214
|
async function ensureAllObjectsExist(adapter) {
|
|
190
215
|
const config = adapter.config;
|
|
191
216
|
try {
|
|
192
217
|
const existingObjects = await adapter.getAdapterObjectsAsync();
|
|
193
|
-
for (const [key,
|
|
218
|
+
for (const [key, def] of Object.entries(import_stateMapping.STATE_MAPPING)) {
|
|
219
|
+
const definition = def;
|
|
194
220
|
if (!isStateEnabled(key, definition, config)) {
|
|
195
221
|
continue;
|
|
196
222
|
}
|
|
@@ -230,21 +256,12 @@ async function ensureAllObjectsExist(adapter) {
|
|
|
230
256
|
} else {
|
|
231
257
|
let needsUpdate = false;
|
|
232
258
|
const existingCommon = existingObj.common;
|
|
233
|
-
if (existingCommon.type !== targetType) {
|
|
234
|
-
needsUpdate = true;
|
|
235
|
-
}
|
|
236
|
-
if (existingCommon.role !== definition.role) {
|
|
237
|
-
needsUpdate = true;
|
|
238
|
-
}
|
|
239
|
-
if ((existingCommon.unit || "") !== (definition.unit || "")) {
|
|
259
|
+
if (existingCommon.type !== targetType || existingCommon.role !== definition.role || (existingCommon.unit || "") !== (definition.unit || "") || existingCommon.name !== definition.name || existingCommon.read !== true || existingCommon.write !== (definition.write || false) || existingCommon.min !== definition.min || existingCommon.max !== definition.max || JSON.stringify(existingCommon.states) !== JSON.stringify(definition.states)) {
|
|
240
260
|
needsUpdate = true;
|
|
241
261
|
}
|
|
242
262
|
if (needsUpdate) {
|
|
243
|
-
await adapter.extendObjectAsync(stateId, { common: commonDef });
|
|
244
|
-
(0, import_logger.writeLog)(
|
|
245
|
-
`Typ-Korrektur: '${stateId}' wurde repariert (Typ/Einheit aktualisiert auf '${targetType}').`,
|
|
246
|
-
"info"
|
|
247
|
-
);
|
|
263
|
+
await adapter.extendObjectAsync(stateId, { type: "state", common: commonDef });
|
|
264
|
+
(0, import_logger.writeLog)(`Eigenschaften von '${stateId}' synchronisiert (Reparatur).`, "debug");
|
|
248
265
|
}
|
|
249
266
|
}
|
|
250
267
|
if (definition.write) {
|
|
@@ -265,7 +282,8 @@ async function ensureAllObjectsExist(adapter) {
|
|
|
265
282
|
}
|
|
266
283
|
}
|
|
267
284
|
} catch (err) {
|
|
268
|
-
|
|
285
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
286
|
+
(0, import_logger.writeLog)(`Fehler bei der Objekt\xFCberpr\xFCfung: ${msg}`, "error");
|
|
269
287
|
}
|
|
270
288
|
}
|
|
271
289
|
async function ensureCustomObjectsExist(adapter) {
|
|
@@ -284,7 +302,7 @@ async function ensureCustomObjectsExist(adapter) {
|
|
|
284
302
|
}
|
|
285
303
|
const stateId = `Benutzer.${sanitizeName(custom.name)}`;
|
|
286
304
|
let role = "state";
|
|
287
|
-
|
|
305
|
+
const targetType = custom.type === "datetime" ? "string" : custom.type;
|
|
288
306
|
if (custom.type === "number") {
|
|
289
307
|
role = "value";
|
|
290
308
|
} else if (custom.type === "string") {
|
|
@@ -293,7 +311,6 @@ async function ensureCustomObjectsExist(adapter) {
|
|
|
293
311
|
role = "indicator";
|
|
294
312
|
} else if (custom.type === "datetime") {
|
|
295
313
|
role = "value.datetime";
|
|
296
|
-
targetType = "string";
|
|
297
314
|
}
|
|
298
315
|
const isWritable = custom.source === "parameter";
|
|
299
316
|
const objDef = {
|
|
@@ -318,6 +335,9 @@ async function ensureCustomObjectsExist(adapter) {
|
|
|
318
335
|
adapter.createdStates.add(stateId);
|
|
319
336
|
}
|
|
320
337
|
await adapter.extendObjectAsync(stateId, { common: objDef.common, native: objDef.native });
|
|
338
|
+
if (isWritable) {
|
|
339
|
+
adapter.subscribeStates(stateId);
|
|
340
|
+
}
|
|
321
341
|
}
|
|
322
342
|
}
|
|
323
343
|
// Annotate the CommonJS export names for ESM import in node:
|