iobroker.luxtronik2-controller 0.23.1 → 0.24.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 +22 -17
- package/admin/jsonConfig.json +146 -0
- package/build/copManager.js +107 -55
- package/build/copManager.js.map +2 -2
- package/build/main.js +80 -29
- package/build/main.js.map +2 -2
- package/io-package.json +29 -28
- package/package.json +1 -1
package/build/copManager.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/copManager.ts"],
|
|
4
|
-
"sourcesContent": ["import { writeLog } from './logger';\nimport { getDpPath } from './stateMapping';\nimport type { LuxtronikAdapter } from './types';\n\nlet isInitialized = false;\n/** Cache f\u00FCr bereits angelegte Datenbank-Objekte zur Vermeidung unn\u00F6tiger DB-Zugriffe */\nconst ensuredObjects = new Set<string>();\n\n/**\n * Stellt einmalig pro Adapter-Laufzeit sicher, dass ein internes COP-Objekt existiert.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param id Die Objekt-ID.\n * @param obj Die Objekt-Definition.\n */\nasync function ensureCopObject(adapter: LuxtronikAdapter, id: string, obj: ioBroker.SettableObject): Promise<void> {\n\tif (ensuredObjects.has(id)) {\n\t\treturn;\n\t}\n\tawait adapter.setObjectNotExistsAsync(id, obj);\n\tensuredObjects.add(id);\n}\n\n/**\n * Verarbeitet die COP-Daten und berechnet Live-Werte anhand von absoluten Z\u00E4hlern und Snapshots.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param bzVal Der aktuelle Betriebszustand der W\u00E4rmepumpe als String.\n * @returns Ein Promise, das nach Abschluss der Berechnung aufgel\u00F6st wird.\n */\nexport async function processCopData(adapter: LuxtronikAdapter, bzVal: string): Promise<void> {\n\tconst config = adapter.config as any;\n\tif (!config.cop_calculation_active) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\twriteLog(`COP Manager gestartet. Modus: ${bzVal}`, 'debug');\n\n\t\t// 1. STROMVERBRAUCH ABRUFEN (IMMER GESAMTZ\u00C4HLER!)\n\t\tlet currentPower = 0;\n\t\tif (config.cop_source_power === 'external' && config.cop_oid_power_total) {\n\t\t\tconst state = await adapter.getForeignStateAsync(config.cop_oid_power_total);\n\t\t\tif (state && typeof state.val === 'number') {\n\t\t\t\tcurrentPower = state.val;\n\t\t\t}\n\t\t} else {\n\t\t\tconst state = await adapter.getStateAsync(getDpPath('energy_total'));\n\t\t\tif (state && typeof state.val === 'number') {\n\t\t\t\tcurrentPower = state.val;\n\t\t\t}\n\t\t}\n\n\t\t// 2. W\u00C4RMEMENGE ABRUFEN (IMMER GESAMTZ\u00C4HLER!)\n\t\tlet currentThermal = 0;\n\t\tif (config.cop_source_thermal === 'external' && config.cop_oid_thermal_total) {\n\t\t\tconst state = await adapter.getForeignStateAsync(config.cop_oid_thermal_total);\n\t\t\tif (state && typeof state.val === 'number') {\n\t\t\t\tcurrentThermal = state.val;\n\t\t\t}\n\t\t} else {\n\t\t\tconst state = await adapter.getStateAsync(getDpPath('thermalenergy_total'));\n\t\t\tif (state && typeof state.val === 'number') {\n\t\t\t\tcurrentThermal = state.val;\n\t\t\t}\n\t\t}\n\n\t\t// --- ABSOLUT SICHERE INITIALISIERUNG AUS DER DATENBANK ---\n\t\tconst rawPowerId = 'hidden.cop_buckets.last_raw_power';\n\t\tconst rawThermalId = 'hidden.cop_buckets.last_raw_thermal';\n\n\t\tif (!isInitialized) {\n\t\t\tawait ensureCopObject(adapter, rawPowerId, {\n\t\t\t\ttype: 'state',\n\t\t\t\tcommon: { name: 'Last Raw Power', type: 'number', role: 'value', read: true, write: false },\n\t\t\t\tnative: {},\n\t\t\t});\n\t\t\tawait ensureCopObject(adapter, rawThermalId, {\n\t\t\t\ttype: 'state',\n\t\t\t\tcommon: { name: 'Last Raw Thermal', type: 'number', role: 'value', read: true, write: false },\n\t\t\t\tnative: {},\n\t\t\t});\n\n\t\t\tconst lastPowerStateInit = await adapter.getStateAsync(rawPowerId);\n\t\t\tconst lastThermalStateInit = await adapter.getStateAsync(rawThermalId);\n\n\t\t\tif (!lastPowerStateInit || lastPowerStateInit.val === null) {\n\t\t\t\tawait adapter.setState(rawPowerId, { val: currentPower, ack: true });\n\t\t\t}\n\t\t\tif (!lastThermalStateInit || lastThermalStateInit.val === null) {\n\t\t\t\tawait adapter.setState(rawThermalId, { val: currentThermal, ack: true });\n\t\t\t}\n\n\t\t\tisInitialized = true;\n\t\t\tawait handleTimeRollover(adapter);\n\t\t\treturn;\n\t\t}\n\n\t\t// 3. LETZTE Z\u00C4HLERST\u00C4NDE AUS DER DATENBANK LADEN\n\t\tconst lastPowerState = await adapter.getStateAsync(rawPowerId);\n\t\tconst lastThermalState = await adapter.getStateAsync(rawThermalId);\n\n\t\tconst lastPower = lastPowerState && typeof lastPowerState.val === 'number' ? lastPowerState.val : currentPower;\n\t\tconst lastThermal =\n\t\t\tlastThermalState && typeof lastThermalState.val === 'number' ? lastThermalState.val : currentThermal;\n\n\t\t// 4. DELTA BERECHNEN (Gegen negative Werte absichern)\n\t\tconst deltaPower = Math.max(0, currentPower - lastPower);\n\t\tconst deltaThermal = Math.max(0, currentThermal - lastThermal);\n\n\t\t// Falls ein externer Z\u00E4hler genullt wurde (Reset), Referenzwert nachziehen\n\t\tif (currentPower < lastPower) {\n\t\t\tawait adapter.setState(rawPowerId, { val: currentPower, ack: true });\n\t\t}\n\t\tif (currentThermal < lastThermal) {\n\t\t\tawait adapter.setState(rawThermalId, { val: currentThermal, ack: true });\n\t\t}\n\n\t\t// 5. NEUE Z\u00C4HLERST\u00C4NDE SOFORT F\u00DCR DEN N\u00C4CHSTEN DURCHLAUF IN DB SPEICHERN\n\t\tif (deltaPower > 0) {\n\t\t\tawait adapter.setState(rawPowerId, { val: currentPower, ack: true });\n\t\t}\n\t\tif (deltaThermal > 0) {\n\t\t\tawait adapter.setState(rawThermalId, { val: currentThermal, ack: true });\n\t\t}\n\n\t\t// 6. ZEITWECHSEL PR\u00DCFEN\n\t\tawait handleTimeRollover(adapter);\n\n\t\t// 7. WERTE IN DIE ENDLOS-Z\u00C4HLER VERTEILEN (inkl. Abtauen = '4' f\u00FCr Heizung)\n\t\tif (deltaPower > 0 || deltaThermal > 0) {\n\t\t\tawait addDeltaToBucket(adapter, 'Total', deltaPower, deltaThermal);\n\n\t\t\tif (bzVal === '0' || bzVal === '4') {\n\t\t\t\tawait addDeltaToBucket(adapter, 'Heating', deltaPower, deltaThermal);\n\t\t\t} else if (bzVal === '1') {\n\t\t\t\tawait addDeltaToBucket(adapter, 'HotWater', deltaPower, deltaThermal);\n\t\t\t}\n\t\t}\n\n\t\t// 8. LIVE COP BERECHNEN UND SCHREIBEN\n\t\tawait calculateAndWriteCop(adapter, 'Total');\n\t\tawait calculateAndWriteCop(adapter, 'Heating');\n\t\tawait calculateAndWriteCop(adapter, 'HotWater');\n\t} catch (err: any) {\n\t\twriteLog(`Fehler bei der COP-Berechnung: ${err.message}`, 'error');\n\t}\n}\n\n/**\n * Pr\u00FCft auf Tages-, Monats- oder Jahreswechsel (lokale Systemzeit) und erstellt Snapshots der Endlosz\u00E4hler.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n */\nasync function handleTimeRollover(adapter: LuxtronikAdapter): Promise<void> {\n\twriteLog(`Pr\u00FCfe Tageswechsel und lege Ordner an...`, 'debug');\n\tconst dateStateId = 'hidden.cop_buckets.last_date';\n\tawait ensureCopObject(adapter, 'hidden', {\n\t\ttype: 'folder',\n\t\tcommon: { name: 'Hidden System Data' },\n\t\tnative: {},\n\t});\n\tawait ensureCopObject(adapter, 'hidden.cop_buckets', {\n\t\ttype: 'folder',\n\t\tcommon: { name: 'COP Data Buckets' },\n\t\tnative: {},\n\t});\n\tawait ensureCopObject(adapter, dateStateId, {\n\t\ttype: 'state',\n\t\tcommon: { name: 'Last calculation date', type: 'string', role: 'date', read: true, write: false },\n\t\tnative: {},\n\t});\n\n\tconst state = await adapter.getStateAsync(dateStateId);\n\tconst lastDate = state && typeof state.val === 'string' ? state.val : '';\n\n\tconst now = new Date();\n\tconst y = now.getFullYear();\n\tconst m = String(now.getMonth() + 1).padStart(2, '0');\n\tconst d = String(now.getDate()).padStart(2, '0');\n\tconst currentDate = `${y}-${m}-${d}`; // Lokales Datum: YYYY-MM-DD\n\tconst currentMonth = `${y}-${m}`; // Lokaler Monat: YYYY-MM\n\tconst currentYear = `${y}`; // Lokales Jahr: YYYY\n\n\tif (lastDate !== currentDate) {\n\t\tconst lastMonth = lastDate ? lastDate.substring(0, 7) : '';\n\t\tconst lastYear = lastDate ? lastDate.substring(0, 4) : '';\n\t\tconst categories = ['Total', 'Heating', 'HotWater'];\n\n\t\tfor (const cat of categories) {\n\t\t\tconst powerAbs = await getAbsoluteValue(adapter, cat, 'power');\n\t\t\tconst thermalAbs = await getAbsoluteValue(adapter, cat, 'thermal');\n\n\t\t\t// IMMER: Tageswechsel Snapshot\n\t\t\tawait setSnapshot(adapter, cat, 'today', powerAbs, thermalAbs);\n\n\t\t\t// Historie f\u00FCr 7-Tage-COP aktualisieren\n\t\t\tawait update7DaysHistory(adapter, cat, powerAbs, thermalAbs);\n\n\t\t\t// Monatswechsel Snapshot\n\t\t\tif (lastMonth !== currentMonth) {\n\t\t\t\tawait setSnapshot(adapter, cat, 'month', powerAbs, thermalAbs);\n\t\t\t}\n\n\t\t\t// Jahreswechsel Snapshot\n\t\t\tif (lastYear !== currentYear) {\n\t\t\t\tawait setSnapshot(adapter, cat, 'year', powerAbs, thermalAbs);\n\t\t\t}\n\t\t}\n\n\t\tawait adapter.setState(dateStateId, { val: currentDate, ack: true });\n\t\twriteLog(`Tageswechsel erkannt. COP-Snapshots f\u00FCr ${currentDate} wurden gesichert.`, 'info');\n\t}\n}\n\n/**\n * Liest den Endlosz\u00E4hler f\u00FCr eine spezifische Kategorie aus.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die Kategorie (Total, Heating, HotWater).\n * @param type Art der Energie (power oder thermal).\n * @returns Der absolute Wert in kWh.\n */\nasync function getAbsoluteValue(\n\tadapter: LuxtronikAdapter,\n\tcategory: string,\n\ttype: 'power' | 'thermal',\n): Promise<number> {\n\tconst id = `hidden.cop_buckets.${category}_${type}_absolute`;\n\tawait ensureCopObject(adapter, id, {\n\t\ttype: 'state',\n\t\tcommon: { name: `${category} ${type} Absolute`, type: 'number', role: 'value', read: true, write: false },\n\t\tnative: {},\n\t});\n\tconst state = await adapter.getStateAsync(id);\n\treturn state && typeof state.val === 'number' ? state.val : 0;\n}\n\n/**\n * Schreibt einen Snapshot-Wert.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die Kategorie.\n * @param timeframe Der Zeitraum (today, month, year).\n * @param power Der zu sichernde Stromwert.\n * @param thermal Der zu sichernde W\u00E4rmewert.\n */\nasync function setSnapshot(\n\tadapter: LuxtronikAdapter,\n\tcategory: string,\n\ttimeframe: string,\n\tpower: number,\n\tthermal: number,\n): Promise<void> {\n\tconst powerId = `hidden.cop_buckets.${category}_power_start_${timeframe}`;\n\tconst thermalId = `hidden.cop_buckets.${category}_thermal_start_${timeframe}`;\n\n\tawait ensureCopObject(adapter, powerId, {\n\t\ttype: 'state',\n\t\tcommon: {\n\t\t\tname: `${category} Power Start ${timeframe}`,\n\t\t\ttype: 'number',\n\t\t\trole: 'value',\n\t\t\tread: true,\n\t\t\twrite: false,\n\t\t},\n\t\tnative: {},\n\t});\n\tawait ensureCopObject(adapter, thermalId, {\n\t\ttype: 'state',\n\t\tcommon: {\n\t\t\tname: `${category} Thermal Start ${timeframe}`,\n\t\t\ttype: 'number',\n\t\t\trole: 'value',\n\t\t\tread: true,\n\t\t\twrite: false,\n\t\t},\n\t\tnative: {},\n\t});\n\n\tawait adapter.setState(powerId, { val: power, ack: true });\n\tawait adapter.setState(thermalId, { val: thermal, ack: true });\n}\n\n/**\n * Verwaltet einen rollierenden 7-Tage-Speicher als JSON.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die Kategorie.\n * @param currentPower Der absolute Stromz\u00E4hler.\n * @param currentThermal Der absolute W\u00E4rmez\u00E4hler.\n */\nasync function update7DaysHistory(\n\tadapter: LuxtronikAdapter,\n\tcategory: string,\n\tcurrentPower: number,\n\tcurrentThermal: number,\n): Promise<void> {\n\tconst historyId = `hidden.cop_buckets.${category}_history_7d`;\n\tawait ensureCopObject(adapter, historyId, {\n\t\ttype: 'state',\n\t\tcommon: { name: `${category} 7 Days History`, type: 'string', role: 'json', read: true, write: false },\n\t\tnative: {},\n\t});\n\n\tconst state = await adapter.getStateAsync(historyId);\n\tlet history: { power: number; thermal: number }[] = [];\n\n\tif (state && typeof state.val === 'string' && state.val !== '') {\n\t\ttry {\n\t\t\thistory = JSON.parse(state.val);\n\t\t} catch {\n\t\t\t/* ignore */\n\t\t}\n\t}\n\n\thistory.push({ power: currentPower, thermal: currentThermal });\n\tif (history.length > 7) {\n\t\thistory.shift(); // \u00C4ltesten Eintrag entfernen (Ringpuffer)\n\t}\n\n\tawait adapter.setState(historyId, { val: JSON.stringify(history), ack: true });\n}\n\n/**\n * Addiert die neuen kWh-Deltas auf die internen Endlosz\u00E4hler.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die zu aktualisierende Kategorie.\n * @param deltaPower Die verbrauchte elektrische Energie.\n * @param deltaThermal Die erzeugte thermische Energie.\n */\nasync function addDeltaToBucket(\n\tadapter: LuxtronikAdapter,\n\tcategory: string,\n\tdeltaPower: number,\n\tdeltaThermal: number,\n): Promise<void> {\n\tconst powerId = `hidden.cop_buckets.${category}_power_absolute`;\n\tconst thermalId = `hidden.cop_buckets.${category}_thermal_absolute`;\n\n\tconst currentPower = await getAbsoluteValue(adapter, category, 'power');\n\tconst currentThermal = await getAbsoluteValue(adapter, category, 'thermal');\n\n\tawait adapter.setState(powerId, { val: currentPower + deltaPower, ack: true });\n\tawait adapter.setState(thermalId, { val: currentThermal + deltaThermal, ack: true });\n}\n\n/**\n * Liest die Endlosz\u00E4hler und Snapshots aus, berechnet die Differenz und schreibt den COP.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die auszulesende Kategorie (Total, Heating, HotWater).\n */\nasync function calculateAndWriteCop(adapter: LuxtronikAdapter, category: string): Promise<void> {\n\tconst currentPower = await getAbsoluteValue(adapter, category, 'power');\n\tconst currentThermal = await getAbsoluteValue(adapter, category, 'thermal');\n\n\tconst dpMap: Record<string, Record<string, string>> = {\n\t\tTotal: { today: 'cop_total_today', '7d': 'cop_total_7d', month: 'cop_total_month', year: 'cop_total_year' },\n\t\tHeating: {\n\t\t\ttoday: 'cop_heating_today',\n\t\t\t'7d': 'cop_heating_7d',\n\t\t\tmonth: 'cop_heating_month',\n\t\t\tyear: 'cop_heating_year',\n\t\t},\n\t\tHotWater: { today: 'cop_water_today', '7d': 'cop_water_7d', month: 'cop_water_month', year: 'cop_water_year' },\n\t};\n\n\t// 1. Berechnung f\u00FCr Heute, Monat, Jahr\n\tconst timeframes = ['today', 'month', 'year'];\n\tfor (const tf of timeframes) {\n\t\tconst powerStartId = `hidden.cop_buckets.${category}_power_start_${tf}`;\n\t\tconst thermalStartId = `hidden.cop_buckets.${category}_thermal_start_${tf}`;\n\n\t\tconst pState = await adapter.getStateAsync(powerStartId);\n\t\tconst tState = await adapter.getStateAsync(thermalStartId);\n\n\t\tconst pStart = pState && typeof pState.val === 'number' ? pState.val : currentPower;\n\t\tconst tStart = tState && typeof tState.val === 'number' ? tState.val : currentThermal;\n\n\t\tconst pUsed = currentPower - pStart;\n\t\tconst tGen = currentThermal - tStart;\n\n\t\tif (pUsed > 0) {\n\t\t\tconst cop = Math.round((tGen / pUsed) * 100) / 100;\n\t\t\tconst targetId = getDpPath(dpMap[category][tf]);\n\t\t\tif (targetId) {\n\t\t\t\tawait adapter.setState(targetId, { val: cop, ack: true });\n\t\t\t}\n\t\t}\n\t}\n\n\t// 2. Berechnung f\u00FCr rollierende 7 Tage\n\tconst historyId = `hidden.cop_buckets.${category}_history_7d`;\n\tconst hState = await adapter.getStateAsync(historyId);\n\tif (hState && typeof hState.val === 'string' && hState.val !== '') {\n\t\ttry {\n\t\t\tconst history = JSON.parse(hState.val);\n\t\t\tif (history.length > 0) {\n\t\t\t\tconst oldest = history[0];\n\t\t\t\tconst pUsed = currentPower - oldest.power;\n\t\t\t\tconst tGen = currentThermal - oldest.thermal;\n\t\t\t\tif (pUsed > 0) {\n\t\t\t\t\tconst cop = Math.round((tGen / pUsed) * 100) / 100;\n\t\t\t\t\tconst targetId = getDpPath(dpMap[category]['7d']);\n\t\t\t\t\tif (targetId) {\n\t\t\t\t\t\tawait adapter.setState(targetId, { val: cop, ack: true });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t/* ignore */\n\t\t}\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AACzB,0BAA0B;AAG1B,IAAI,gBAAgB;AAEpB,MAAM,iBAAiB,oBAAI,IAAY;AASvC,eAAe,gBAAgB,SAA2B,IAAY,KAA6C;AAClH,MAAI,eAAe,IAAI,EAAE,GAAG;AAC3B;AAAA,EACD;AACA,QAAM,QAAQ,wBAAwB,IAAI,GAAG;AAC7C,iBAAe,IAAI,EAAE;AACtB;AASA,eAAsB,eAAe,SAA2B,OAA8B;AAC7F,QAAM,SAAS,QAAQ;AACvB,MAAI,CAAC,OAAO,wBAAwB;AACnC;AAAA,EACD;AAEA,MAAI;AACH,gCAAS,iCAAiC,KAAK,IAAI,OAAO;
|
|
4
|
+
"sourcesContent": ["import { writeLog } from './logger';\nimport { getDpPath } from './stateMapping';\nimport type { LuxtronikAdapter } from './types';\n\nlet isInitialized = false;\n/** Cache f\u00FCr bereits angelegte Datenbank-Objekte zur Vermeidung unn\u00F6tiger DB-Zugriffe */\nconst ensuredObjects = new Set<string>();\n\n/**\n * Stellt einmalig pro Adapter-Laufzeit sicher, dass ein internes COP-Objekt existiert.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param id Die Objekt-ID.\n * @param obj Die Objekt-Definition.\n */\nasync function ensureCopObject(adapter: LuxtronikAdapter, id: string, obj: ioBroker.SettableObject): Promise<void> {\n\tif (ensuredObjects.has(id)) {\n\t\treturn;\n\t}\n\tawait adapter.setObjectNotExistsAsync(id, obj);\n\tensuredObjects.add(id);\n}\n\n/**\n * Verarbeitet die COP-Daten und berechnet Live-Werte anhand von absoluten Z\u00E4hlern und Snapshots.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param bzVal Der aktuelle Betriebszustand der W\u00E4rmepumpe als String.\n * @returns Ein Promise, das nach Abschluss der Berechnung aufgel\u00F6st wird.\n */\nexport async function processCopData(adapter: LuxtronikAdapter, bzVal: string): Promise<void> {\n\tconst config = adapter.config as any;\n\tif (!config.cop_calculation_active) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\twriteLog(`COP Manager gestartet. Modus: ${bzVal}`, 'debug');\n\n\t\tconst isExternalPower = config.cop_source_power === 'external' && Boolean(config.cop_oid_power_total);\n\t\tconst isExternalThermal = config.cop_source_thermal === 'external' && Boolean(config.cop_oid_thermal_total);\n\n\t\t// 1. ALLE STROMZ\u00C4HLER ABRUFEN (Gesamt + Einzelz\u00E4hler)\n\t\tlet currentPowerTotal = 0;\n\t\tlet currentPowerHeating = 0;\n\t\tlet currentPowerWater = 0;\n\n\t\tif (isExternalPower) {\n\t\t\tconst state = await adapter.getForeignStateAsync(config.cop_oid_power_total);\n\t\t\tif (state && typeof state.val === 'number') {\n\t\t\t\tcurrentPowerTotal = state.val;\n\t\t\t}\n\t\t} else {\n\t\t\tconst [sTotal, sHeat, sWater] = await Promise.all([\n\t\t\t\tadapter.getStateAsync(getDpPath('energy_total')),\n\t\t\t\tadapter.getStateAsync(getDpPath('energy_heating')),\n\t\t\t\tadapter.getStateAsync(getDpPath('energy_warmwater')),\n\t\t\t]);\n\t\t\tif (sTotal && typeof sTotal.val === 'number') {\n\t\t\t\tcurrentPowerTotal = sTotal.val;\n\t\t\t}\n\t\t\tif (sHeat && typeof sHeat.val === 'number') {\n\t\t\t\tcurrentPowerHeating = sHeat.val;\n\t\t\t}\n\t\t\tif (sWater && typeof sWater.val === 'number') {\n\t\t\t\tcurrentPowerWater = sWater.val;\n\t\t\t}\n\t\t}\n\n\t\t// 2. ALLE W\u00C4RMEMENGENZ\u00C4HLER ABRUFEN (Gesamt + Einzelz\u00E4hler)\n\t\tlet currentThermalTotal = 0;\n\t\tlet currentThermalHeating = 0;\n\t\tlet currentThermalWater = 0;\n\n\t\tif (isExternalThermal) {\n\t\t\tconst state = await adapter.getForeignStateAsync(config.cop_oid_thermal_total);\n\t\t\tif (state && typeof state.val === 'number') {\n\t\t\t\tcurrentThermalTotal = state.val;\n\t\t\t}\n\t\t} else {\n\t\t\tconst [sTotal, sHeat, sWater] = await Promise.all([\n\t\t\t\tadapter.getStateAsync(getDpPath('thermalenergy_total')),\n\t\t\t\tadapter.getStateAsync(getDpPath('thermalenergy_heating')),\n\t\t\t\tadapter.getStateAsync(getDpPath('thermalenergy_warmwater')),\n\t\t\t]);\n\t\t\tif (sTotal && typeof sTotal.val === 'number') {\n\t\t\t\tcurrentThermalTotal = sTotal.val;\n\t\t\t}\n\t\t\tif (sHeat && typeof sHeat.val === 'number') {\n\t\t\t\tcurrentThermalHeating = sHeat.val;\n\t\t\t}\n\t\t\tif (sWater && typeof sWater.val === 'number') {\n\t\t\t\tcurrentThermalWater = sWater.val;\n\t\t\t}\n\t\t}\n\n\t\t// --- SEPARATE REFERENZ-SPEICHER (Verhindert Spr\u00FCnge beim Taktwechsel!) ---\n\t\tconst rawPowerTotalId = 'hidden.cop_buckets.last_raw_power';\n\t\tconst rawPowerHeatId = 'hidden.cop_buckets.last_raw_power_heating';\n\t\tconst rawPowerWaterId = 'hidden.cop_buckets.last_raw_power_water';\n\n\t\tconst rawThermalTotalId = 'hidden.cop_buckets.last_raw_thermal';\n\t\tconst rawThermalHeatId = 'hidden.cop_buckets.last_raw_thermal_heating';\n\t\tconst rawThermalWaterId = 'hidden.cop_buckets.last_raw_thermal_water';\n\n\t\tconst rawTrackers = [\n\t\t\t{ id: rawPowerTotalId, name: 'Last Raw Power Total', current: currentPowerTotal },\n\t\t\t{ id: rawPowerHeatId, name: 'Last Raw Power Heating', current: currentPowerHeating },\n\t\t\t{ id: rawPowerWaterId, name: 'Last Raw Power Water', current: currentPowerWater },\n\t\t\t{ id: rawThermalTotalId, name: 'Last Raw Thermal Total', current: currentThermalTotal },\n\t\t\t{ id: rawThermalHeatId, name: 'Last Raw Thermal Heating', current: currentThermalHeating },\n\t\t\t{ id: rawThermalWaterId, name: 'Last Raw Thermal Water', current: currentThermalWater },\n\t\t];\n\n\t\tif (!isInitialized) {\n\t\t\tfor (const tracker of rawTrackers) {\n\t\t\t\tawait ensureCopObject(adapter, tracker.id, {\n\t\t\t\t\ttype: 'state',\n\t\t\t\t\tcommon: { name: tracker.name, type: 'number', role: 'value', read: true, write: false },\n\t\t\t\t\tnative: {},\n\t\t\t\t});\n\t\t\t\tconst stateInit = await adapter.getStateAsync(tracker.id);\n\t\t\t\tif (!stateInit || stateInit.val === null) {\n\t\t\t\t\tawait adapter.setState(tracker.id, { val: tracker.current, ack: true });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tisInitialized = true;\n\t\t\tawait handleTimeRollover(adapter);\n\t\t\treturn;\n\t\t}\n\n\t\t// 3. LETZTE Z\u00C4HLERST\u00C4NDE LADEN & DELTAS ISOLIERT BERECHNEN\n\t\tconst readAndCalcDelta = async (id: string, currentVal: number): Promise<number> => {\n\t\t\tconst lastState = await adapter.getStateAsync(id);\n\t\t\tconst lastVal = lastState && typeof lastState.val === 'number' ? lastState.val : currentVal;\n\t\t\tconst delta = Math.max(0, currentVal - lastVal);\n\n\t\t\t// Referenzwert sofort nachziehen (sowohl bei Zuwachs als auch bei Z\u00E4hler-Reset)\n\t\t\tif (currentVal !== lastVal) {\n\t\t\t\tawait adapter.setState(id, { val: currentVal, ack: true });\n\t\t\t}\n\t\t\treturn delta;\n\t\t};\n\n\t\tconst deltaPowerTotal = await readAndCalcDelta(rawPowerTotalId, currentPowerTotal);\n\t\tconst deltaPowerHeating = await readAndCalcDelta(rawPowerHeatId, currentPowerHeating);\n\t\tconst deltaPowerWater = await readAndCalcDelta(rawPowerWaterId, currentPowerWater);\n\n\t\tconst deltaThermalTotal = await readAndCalcDelta(rawThermalTotalId, currentThermalTotal);\n\t\tconst deltaThermalHeating = await readAndCalcDelta(rawThermalHeatId, currentThermalHeating);\n\t\tconst deltaThermalWater = await readAndCalcDelta(rawThermalWaterId, currentThermalWater);\n\n\t\t// 4. ZEITWECHSEL PR\u00DCFEN\n\t\tawait handleTimeRollover(adapter);\n\n\t\t// 5. INTELLIGENTE ZUORDNUNG MIT AUTOMATISCHEM FALLBACK AUF TOTAL\n\t\tlet modeDeltaPower = 0;\n\t\tlet modeDeltaThermal = 0;\n\n\t\tif (bzVal === '0' || bzVal === '4') {\n\t\t\t// HEIZEN (inkl. Abtauen): Einzelz\u00E4hler nutzen; falls 0 -> Fallback auf Gesamtz\u00E4hler-Delta\n\t\t\tmodeDeltaPower = isExternalPower\n\t\t\t\t? deltaPowerTotal\n\t\t\t\t: deltaPowerHeating > 0\n\t\t\t\t\t? deltaPowerHeating\n\t\t\t\t\t: deltaPowerTotal;\n\t\t\tmodeDeltaThermal = isExternalThermal\n\t\t\t\t? deltaThermalTotal\n\t\t\t\t: deltaThermalHeating > 0\n\t\t\t\t\t? deltaThermalHeating\n\t\t\t\t\t: deltaThermalTotal;\n\n\t\t\tif (modeDeltaPower > 0 || modeDeltaThermal > 0) {\n\t\t\t\tawait addDeltaToBucket(adapter, 'Heating', modeDeltaPower, modeDeltaThermal);\n\t\t\t}\n\t\t} else if (bzVal === '1') {\n\t\t\t// WARMWASSER: Einzelz\u00E4hler nutzen; falls 0 (z.B. Novelan Bug) -> Fallback auf Gesamtz\u00E4hler-Delta\n\t\t\tmodeDeltaPower = isExternalPower\n\t\t\t\t? deltaPowerTotal\n\t\t\t\t: deltaPowerWater > 0\n\t\t\t\t\t? deltaPowerWater\n\t\t\t\t\t: deltaPowerTotal;\n\t\t\tmodeDeltaThermal = isExternalThermal\n\t\t\t\t? deltaThermalTotal\n\t\t\t\t: deltaThermalWater > 0\n\t\t\t\t\t? deltaThermalWater\n\t\t\t\t\t: deltaThermalTotal;\n\n\t\t\tif (!isExternalPower && deltaPowerWater === 0 && deltaPowerTotal > 0) {\n\t\t\t\twriteLog(\n\t\t\t\t\t`[COP] WW-Stromz\u00E4hler meldet 0 Delta. Nutze Delta von energy_total (${deltaPowerTotal} kWh) als Fallback.`,\n\t\t\t\t\t'debug',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!isExternalThermal && deltaThermalWater === 0 && deltaThermalTotal > 0) {\n\t\t\t\twriteLog(\n\t\t\t\t\t`[COP] WW-W\u00E4rmez\u00E4hler meldet 0 Delta. Nutze Delta von thermalenergy_total (${deltaThermalTotal} kWh) als Fallback.`,\n\t\t\t\t\t'debug',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (modeDeltaPower > 0 || modeDeltaThermal > 0) {\n\t\t\t\tawait addDeltaToBucket(adapter, 'HotWater', modeDeltaPower, modeDeltaThermal);\n\t\t\t}\n\t\t}\n\n\t\t// TOTAL-BUCKET: Nimmt das reale Gesamtdelta (oder das Modus-Delta als Fallback)\n\t\tconst totalBucketPower = deltaPowerTotal > 0 ? deltaPowerTotal : modeDeltaPower;\n\t\tconst totalBucketThermal = deltaThermalTotal > 0 ? deltaThermalTotal : modeDeltaThermal;\n\n\t\tif (totalBucketPower > 0 || totalBucketThermal > 0) {\n\t\t\tawait addDeltaToBucket(adapter, 'Total', totalBucketPower, totalBucketThermal);\n\t\t}\n\n\t\t// 6. LIVE COP BERECHNEN UND SCHREIBEN\n\t\tawait calculateAndWriteCop(adapter, 'Total');\n\t\tawait calculateAndWriteCop(adapter, 'Heating');\n\t\tawait calculateAndWriteCop(adapter, 'HotWater');\n\t} catch (err: any) {\n\t\twriteLog(`Fehler bei der COP-Berechnung: ${err.message}`, 'error');\n\t}\n}\n\n/**\n * Pr\u00FCft auf Tages-, Monats- oder Jahreswechsel (lokale Systemzeit) und erstellt Snapshots der Endlosz\u00E4hler.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n */\nasync function handleTimeRollover(adapter: LuxtronikAdapter): Promise<void> {\n\twriteLog(`Pr\u00FCfe Tageswechsel und lege Ordner an...`, 'debug');\n\tconst dateStateId = 'hidden.cop_buckets.last_date';\n\tawait ensureCopObject(adapter, 'hidden', {\n\t\ttype: 'folder',\n\t\tcommon: { name: 'Hidden System Data' },\n\t\tnative: {},\n\t});\n\tawait ensureCopObject(adapter, 'hidden.cop_buckets', {\n\t\ttype: 'folder',\n\t\tcommon: { name: 'COP Data Buckets' },\n\t\tnative: {},\n\t});\n\tawait ensureCopObject(adapter, dateStateId, {\n\t\ttype: 'state',\n\t\tcommon: { name: 'Last calculation date', type: 'string', role: 'date', read: true, write: false },\n\t\tnative: {},\n\t});\n\n\tconst state = await adapter.getStateAsync(dateStateId);\n\tconst lastDate = state && typeof state.val === 'string' ? state.val : '';\n\n\tconst now = new Date();\n\tconst y = now.getFullYear();\n\tconst m = String(now.getMonth() + 1).padStart(2, '0');\n\tconst d = String(now.getDate()).padStart(2, '0');\n\tconst currentDate = `${y}-${m}-${d}`; // Lokales Datum: YYYY-MM-DD\n\tconst currentMonth = `${y}-${m}`; // Lokaler Monat: YYYY-MM\n\tconst currentYear = `${y}`; // Lokales Jahr: YYYY\n\n\tif (lastDate !== currentDate) {\n\t\tconst lastMonth = lastDate ? lastDate.substring(0, 7) : '';\n\t\tconst lastYear = lastDate ? lastDate.substring(0, 4) : '';\n\t\tconst categories = ['Total', 'Heating', 'HotWater'];\n\n\t\tfor (const cat of categories) {\n\t\t\tconst powerAbs = await getAbsoluteValue(adapter, cat, 'power');\n\t\t\tconst thermalAbs = await getAbsoluteValue(adapter, cat, 'thermal');\n\n\t\t\t// IMMER: Tageswechsel Snapshot\n\t\t\tawait setSnapshot(adapter, cat, 'today', powerAbs, thermalAbs);\n\n\t\t\t// Historie f\u00FCr 7-Tage-COP aktualisieren\n\t\t\tawait update7DaysHistory(adapter, cat, powerAbs, thermalAbs);\n\n\t\t\t// Monatswechsel Snapshot\n\t\t\tif (lastMonth !== currentMonth) {\n\t\t\t\tawait setSnapshot(adapter, cat, 'month', powerAbs, thermalAbs);\n\t\t\t}\n\n\t\t\t// Jahreswechsel Snapshot\n\t\t\tif (lastYear !== currentYear) {\n\t\t\t\tawait setSnapshot(adapter, cat, 'year', powerAbs, thermalAbs);\n\t\t\t}\n\t\t}\n\n\t\tawait adapter.setState(dateStateId, { val: currentDate, ack: true });\n\t\twriteLog(`Tageswechsel erkannt. COP-Snapshots f\u00FCr ${currentDate} wurden gesichert.`, 'info');\n\t}\n}\n\n/**\n * Liest den Endlosz\u00E4hler f\u00FCr eine spezifische Kategorie aus.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die Kategorie (Total, Heating, HotWater).\n * @param type Art der Energie (power oder thermal).\n * @returns Der absolute Wert in kWh.\n */\nasync function getAbsoluteValue(\n\tadapter: LuxtronikAdapter,\n\tcategory: string,\n\ttype: 'power' | 'thermal',\n): Promise<number> {\n\tconst id = `hidden.cop_buckets.${category}_${type}_absolute`;\n\tawait ensureCopObject(adapter, id, {\n\t\ttype: 'state',\n\t\tcommon: { name: `${category} ${type} Absolute`, type: 'number', role: 'value', read: true, write: false },\n\t\tnative: {},\n\t});\n\tconst state = await adapter.getStateAsync(id);\n\treturn state && typeof state.val === 'number' ? state.val : 0;\n}\n\n/**\n * Schreibt einen Snapshot-Wert.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die Kategorie.\n * @param timeframe Der Zeitraum (today, month, year).\n * @param power Der zu sichernde Stromwert.\n * @param thermal Der zu sichernde W\u00E4rmewert.\n */\nasync function setSnapshot(\n\tadapter: LuxtronikAdapter,\n\tcategory: string,\n\ttimeframe: string,\n\tpower: number,\n\tthermal: number,\n): Promise<void> {\n\tconst powerId = `hidden.cop_buckets.${category}_power_start_${timeframe}`;\n\tconst thermalId = `hidden.cop_buckets.${category}_thermal_start_${timeframe}`;\n\n\tawait ensureCopObject(adapter, powerId, {\n\t\ttype: 'state',\n\t\tcommon: {\n\t\t\tname: `${category} Power Start ${timeframe}`,\n\t\t\ttype: 'number',\n\t\t\trole: 'value',\n\t\t\tread: true,\n\t\t\twrite: false,\n\t\t},\n\t\tnative: {},\n\t});\n\tawait ensureCopObject(adapter, thermalId, {\n\t\ttype: 'state',\n\t\tcommon: {\n\t\t\tname: `${category} Thermal Start ${timeframe}`,\n\t\t\ttype: 'number',\n\t\t\trole: 'value',\n\t\t\tread: true,\n\t\t\twrite: false,\n\t\t},\n\t\tnative: {},\n\t});\n\n\tawait adapter.setState(powerId, { val: power, ack: true });\n\tawait adapter.setState(thermalId, { val: thermal, ack: true });\n}\n\n/**\n * Verwaltet einen rollierenden 7-Tage-Speicher als JSON.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die Kategorie.\n * @param currentPower Der absolute Stromz\u00E4hler.\n * @param currentThermal Der absolute W\u00E4rmez\u00E4hler.\n */\nasync function update7DaysHistory(\n\tadapter: LuxtronikAdapter,\n\tcategory: string,\n\tcurrentPower: number,\n\tcurrentThermal: number,\n): Promise<void> {\n\tconst historyId = `hidden.cop_buckets.${category}_history_7d`;\n\tawait ensureCopObject(adapter, historyId, {\n\t\ttype: 'state',\n\t\tcommon: { name: `${category} 7 Days History`, type: 'string', role: 'json', read: true, write: false },\n\t\tnative: {},\n\t});\n\n\tconst state = await adapter.getStateAsync(historyId);\n\tlet history: { power: number; thermal: number }[] = [];\n\n\tif (state && typeof state.val === 'string' && state.val !== '') {\n\t\ttry {\n\t\t\thistory = JSON.parse(state.val);\n\t\t} catch {\n\t\t\t/* ignore */\n\t\t}\n\t}\n\n\thistory.push({ power: currentPower, thermal: currentThermal });\n\tif (history.length > 7) {\n\t\thistory.shift(); // \u00C4ltesten Eintrag entfernen (Ringpuffer)\n\t}\n\n\tawait adapter.setState(historyId, { val: JSON.stringify(history), ack: true });\n}\n\n/**\n * Addiert die neuen kWh-Deltas auf die internen Endlosz\u00E4hler.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die zu aktualisierende Kategorie.\n * @param deltaPower Die verbrauchte elektrische Energie.\n * @param deltaThermal Die erzeugte thermische Energie.\n */\nasync function addDeltaToBucket(\n\tadapter: LuxtronikAdapter,\n\tcategory: string,\n\tdeltaPower: number,\n\tdeltaThermal: number,\n): Promise<void> {\n\tconst powerId = `hidden.cop_buckets.${category}_power_absolute`;\n\tconst thermalId = `hidden.cop_buckets.${category}_thermal_absolute`;\n\n\tconst currentPower = await getAbsoluteValue(adapter, category, 'power');\n\tconst currentThermal = await getAbsoluteValue(adapter, category, 'thermal');\n\n\tawait adapter.setState(powerId, { val: currentPower + deltaPower, ack: true });\n\tawait adapter.setState(thermalId, { val: currentThermal + deltaThermal, ack: true });\n}\n\n/**\n * Liest die Endlosz\u00E4hler und Snapshots aus, berechnet die Differenz und schreibt den COP.\n *\n * @param adapter Die Instanz des ioBroker-Adapters.\n * @param category Die auszulesende Kategorie (Total, Heating, HotWater).\n */\nasync function calculateAndWriteCop(adapter: LuxtronikAdapter, category: string): Promise<void> {\n\tconst currentPower = await getAbsoluteValue(adapter, category, 'power');\n\tconst currentThermal = await getAbsoluteValue(adapter, category, 'thermal');\n\n\tconst dpMap: Record<string, Record<string, string>> = {\n\t\tTotal: { today: 'cop_total_today', '7d': 'cop_total_7d', month: 'cop_total_month', year: 'cop_total_year' },\n\t\tHeating: {\n\t\t\ttoday: 'cop_heating_today',\n\t\t\t'7d': 'cop_heating_7d',\n\t\t\tmonth: 'cop_heating_month',\n\t\t\tyear: 'cop_heating_year',\n\t\t},\n\t\tHotWater: { today: 'cop_water_today', '7d': 'cop_water_7d', month: 'cop_water_month', year: 'cop_water_year' },\n\t};\n\n\t// 1. Berechnung f\u00FCr Heute, Monat, Jahr\n\tconst timeframes = ['today', 'month', 'year'];\n\tfor (const tf of timeframes) {\n\t\tconst powerStartId = `hidden.cop_buckets.${category}_power_start_${tf}`;\n\t\tconst thermalStartId = `hidden.cop_buckets.${category}_thermal_start_${tf}`;\n\n\t\tconst pState = await adapter.getStateAsync(powerStartId);\n\t\tconst tState = await adapter.getStateAsync(thermalStartId);\n\n\t\tconst pStart = pState && typeof pState.val === 'number' ? pState.val : currentPower;\n\t\tconst tStart = tState && typeof tState.val === 'number' ? tState.val : currentThermal;\n\n\t\tconst pUsed = currentPower - pStart;\n\t\tconst tGen = currentThermal - tStart;\n\n\t\tif (pUsed > 0) {\n\t\t\tconst cop = Math.round((tGen / pUsed) * 100) / 100;\n\t\t\tconst targetId = getDpPath(dpMap[category][tf]);\n\t\t\tif (targetId) {\n\t\t\t\tawait adapter.setState(targetId, { val: cop, ack: true });\n\t\t\t}\n\t\t}\n\t}\n\n\t// 2. Berechnung f\u00FCr rollierende 7 Tage\n\tconst historyId = `hidden.cop_buckets.${category}_history_7d`;\n\tconst hState = await adapter.getStateAsync(historyId);\n\tif (hState && typeof hState.val === 'string' && hState.val !== '') {\n\t\ttry {\n\t\t\tconst history = JSON.parse(hState.val);\n\t\t\tif (history.length > 0) {\n\t\t\t\tconst oldest = history[0];\n\t\t\t\tconst pUsed = currentPower - oldest.power;\n\t\t\t\tconst tGen = currentThermal - oldest.thermal;\n\t\t\t\tif (pUsed > 0) {\n\t\t\t\t\tconst cop = Math.round((tGen / pUsed) * 100) / 100;\n\t\t\t\t\tconst targetId = getDpPath(dpMap[category]['7d']);\n\t\t\t\t\tif (targetId) {\n\t\t\t\t\t\tawait adapter.setState(targetId, { val: cop, ack: true });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t/* ignore */\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;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,QAAM,SAAS,MAAM,QAAQ,cAAc,SAAS;AACpD,MAAI,UAAU,OAAO,OAAO,QAAQ,YAAY,OAAO,QAAQ,IAAI;AAClE,QAAI;AACH,YAAM,UAAU,KAAK,MAAM,OAAO,GAAG;AACrC,UAAI,QAAQ,SAAS,GAAG;AACvB,cAAM,SAAS,QAAQ,CAAC;AACxB,cAAM,QAAQ,eAAe,OAAO;AACpC,cAAM,OAAO,iBAAiB,OAAO;AACrC,YAAI,QAAQ,GAAG;AACd,gBAAM,MAAM,KAAK,MAAO,OAAO,QAAS,GAAG,IAAI;AAC/C,gBAAM,eAAW,+BAAU,MAAM,QAAQ,EAAE,IAAI,CAAC;AAChD,cAAI,UAAU;AACb,kBAAM,QAAQ,SAAS,UAAU,EAAE,KAAK,KAAK,KAAK,KAAK,CAAC;AAAA,UACzD;AAAA,QACD;AAAA,MACD;AAAA,IACD,QAAQ;AAAA,IAER;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/main.js
CHANGED
|
@@ -153,11 +153,29 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
153
153
|
configUpdated = true;
|
|
154
154
|
(0, import_logger.writeLog)(`[Migration] Updated zip_control_mode to '${migratedMode}' based on legacy settings.`, "info");
|
|
155
155
|
}
|
|
156
|
+
if (config.operation_mode === void 0) {
|
|
157
|
+
if (config.modbus_active === true) {
|
|
158
|
+
config.operation_mode = "modbus";
|
|
159
|
+
} else if (config.idle_defaults_aktiv === true || config.regelung_aktiv === true || config.hup_optimierung_aktiv === true || config.pv_active === true || config.zip_optimierung_aktiv === true) {
|
|
160
|
+
config.operation_mode = "native";
|
|
161
|
+
} else {
|
|
162
|
+
config.operation_mode = "readonly";
|
|
163
|
+
}
|
|
164
|
+
configUpdated = true;
|
|
165
|
+
(0, import_logger.writeLog)(`[Migration] Set operation_mode to '${config.operation_mode}' based on legacy settings.`, "info");
|
|
166
|
+
}
|
|
167
|
+
const shouldModbusBeActive = config.operation_mode === "modbus";
|
|
168
|
+
if (config.modbus_active !== shouldModbusBeActive) {
|
|
169
|
+
config.modbus_active = shouldModbusBeActive;
|
|
170
|
+
configUpdated = true;
|
|
171
|
+
}
|
|
156
172
|
if (configUpdated) {
|
|
157
173
|
try {
|
|
158
174
|
const obj = await this.getForeignObjectAsync(`system.adapter.${this.namespace}`);
|
|
159
175
|
if (obj && obj.native) {
|
|
160
176
|
obj.native.zip_control_mode = config.zip_control_mode;
|
|
177
|
+
obj.native.operation_mode = config.operation_mode;
|
|
178
|
+
obj.native.modbus_active = config.modbus_active;
|
|
161
179
|
await this.setForeignObject(`system.adapter.${this.namespace}`, obj);
|
|
162
180
|
}
|
|
163
181
|
} catch (err) {
|
|
@@ -194,21 +212,36 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
194
212
|
await (0, import_objectManager.ensureCustomObjectsExist)(this);
|
|
195
213
|
(0, import_backupManager.initAutoBackup)(this);
|
|
196
214
|
await this.subscribeStatesAsync("Information.12_SystemInfo.check_firmware");
|
|
197
|
-
|
|
215
|
+
const isReadOnly = config.operation_mode === "readonly";
|
|
216
|
+
if (isReadOnly) {
|
|
217
|
+
(0, import_logger.writeLog)(
|
|
218
|
+
"\u{1F512} Operating Mode: READ-ONLY. All hardware write operations and optimizations are disabled.",
|
|
219
|
+
"info"
|
|
220
|
+
);
|
|
221
|
+
await this.setState((0, import_stateMapping.getDpPath)("Regelung_Aktiv"), { val: false, ack: true });
|
|
222
|
+
} else if (config.operation_mode === "modbus") {
|
|
223
|
+
(0, import_logger.writeLog)("\u26A1 Operating Mode: READ/WRITE WITH MODBUS TCP (Hybrid).", "info");
|
|
224
|
+
await this.setState((0, import_stateMapping.getDpPath)("Regelung_Aktiv"), { val: config.regelung_aktiv === true, ack: true });
|
|
225
|
+
} else {
|
|
226
|
+
(0, import_logger.writeLog)("\u270D\uFE0F Operating Mode: READ/WRITE WITHOUT MODBUS (Native TCP Port 8889).", "info");
|
|
227
|
+
await this.setState((0, import_stateMapping.getDpPath)("Regelung_Aktiv"), { val: config.regelung_aktiv === true, ack: true });
|
|
228
|
+
}
|
|
198
229
|
const debugState = await this.getStateAsync((0, import_stateMapping.getDpPath)("Schreibe_Debug_Log"));
|
|
199
230
|
this.isDebugLogActive = (debugState == null ? void 0 : debugState.val) === true;
|
|
200
231
|
(0, import_logger.setCustomDebug)(this.isDebugLogActive);
|
|
201
|
-
await (0, import_zipManager.disableHardwareZipTimer)(this);
|
|
202
232
|
const cycleTodayState = await this.getStateAsync((0, import_stateMapping.getDpPath)("write_cycles_today"));
|
|
203
233
|
this.writeCyclesToday = cycleTodayState && typeof cycleTodayState.val === "number" ? cycleTodayState.val : 0;
|
|
204
234
|
const cycleTotalState = await this.getStateAsync((0, import_stateMapping.getDpPath)("write_cycles_total"));
|
|
205
235
|
this.writeCyclesTotal = cycleTotalState && typeof cycleTotalState.val === "number" ? cycleTotalState.val : 0;
|
|
206
236
|
this.scheduleMidnightReset();
|
|
207
|
-
|
|
208
|
-
|
|
237
|
+
if (!isReadOnly) {
|
|
238
|
+
await (0, import_zipManager.disableHardwareZipTimer)(this);
|
|
239
|
+
(0, import_zipManager.subscribeMotionSensors)(this);
|
|
240
|
+
await (0, import_pvManager.initPvManagement)(this);
|
|
241
|
+
}
|
|
209
242
|
this.subscribeStates("*");
|
|
210
243
|
this.modbusManager = new import_modbusManager.ModbusManager(this);
|
|
211
|
-
if (config.modbus_active) {
|
|
244
|
+
if (!isReadOnly && config.modbus_active) {
|
|
212
245
|
(0, import_logger.writeLog)("Checking Modbus TCP availability for hybrid operations...", "info");
|
|
213
246
|
await this.modbusManager.checkAvailability();
|
|
214
247
|
}
|
|
@@ -289,6 +322,10 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
289
322
|
* @returns A promise that resolves when the synchronization task finishes.
|
|
290
323
|
*/
|
|
291
324
|
async syncConfigValue(mappingKey, val) {
|
|
325
|
+
const config = this.config;
|
|
326
|
+
if (config.operation_mode === "readonly") {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
292
329
|
if (val === void 0 || val === null) {
|
|
293
330
|
return;
|
|
294
331
|
}
|
|
@@ -298,7 +335,6 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
298
335
|
}
|
|
299
336
|
const id = (0, import_stateMapping.getDpPath)(mappingKey);
|
|
300
337
|
const state = await this.getStateAsync(id);
|
|
301
|
-
const config = this.config;
|
|
302
338
|
let appliedFactor = definition.factor;
|
|
303
339
|
if (mappingKey === "heating_system_circ_pump_voltage_nominal" || mappingKey === "heating_system_circ_pump_voltage_minimal") {
|
|
304
340
|
appliedFactor = config.hup_voltage_factor !== void 0 ? Number(config.hup_voltage_factor) : 100;
|
|
@@ -427,6 +463,9 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
427
463
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
428
464
|
try {
|
|
429
465
|
const config = this.config;
|
|
466
|
+
if (config.operation_mode === "readonly") {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
430
469
|
const bzState = await this.getStateAsync((0, import_stateMapping.getDpPath)("WP_BZ_akt"));
|
|
431
470
|
const bzVal = bzState && bzState.val !== null ? String(bzState.val).trim() : rawValues[80] !== void 0 ? String(rawValues[80]) : "";
|
|
432
471
|
const regelungAktivState = await this.getStateAsync((0, import_stateMapping.getDpPath)("Regelung_Aktiv"));
|
|
@@ -862,18 +901,25 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
862
901
|
if (!state) {
|
|
863
902
|
return;
|
|
864
903
|
}
|
|
904
|
+
const config = this.config;
|
|
905
|
+
const isReadOnly = config.operation_mode === "readonly";
|
|
865
906
|
if (!id.startsWith(`${this.namespace}.`)) {
|
|
907
|
+
if (isReadOnly) {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
866
910
|
(0, import_pvManager.handlePvFeedInChange)(this, id, state);
|
|
867
911
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
912
|
+
if (!isReadOnly) {
|
|
913
|
+
const isMotionSensor = await (0, import_zipManager.checkAndHandleMotionSensor)(this, id, state);
|
|
914
|
+
if (isMotionSensor) {
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
871
917
|
}
|
|
872
918
|
if (!id.startsWith(`${this.namespace}.`)) {
|
|
873
919
|
return;
|
|
874
920
|
}
|
|
875
921
|
if (state.ack) {
|
|
876
|
-
if (id.endsWith("WP_BZ_akt")) {
|
|
922
|
+
if (!isReadOnly && id.endsWith("WP_BZ_akt")) {
|
|
877
923
|
await (0, import_pvManager.handlePvCycleCheck)(this, Number(state.val));
|
|
878
924
|
}
|
|
879
925
|
return;
|
|
@@ -884,11 +930,34 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
884
930
|
void (0, import_updateManager.checkFirmwareUpdate)(this);
|
|
885
931
|
return;
|
|
886
932
|
}
|
|
933
|
+
const mappingKey = id.split(".").pop();
|
|
934
|
+
const relativeId = id.replace(`${this.namespace}.`, "");
|
|
935
|
+
if (mappingKey === "Schreibe_Debug_Log") {
|
|
936
|
+
await this.setState(relativeId, { val: state.val, ack: true });
|
|
937
|
+
this.isDebugLogActive = state.val === true;
|
|
938
|
+
(0, import_logger.setCustomDebug)(this.isDebugLogActive);
|
|
939
|
+
(0, import_logger.writeLog)(
|
|
940
|
+
`Extended debugging telemetry logging mode has been ${this.isDebugLogActive ? "enabled" : "disabled"}.`,
|
|
941
|
+
"info"
|
|
942
|
+
);
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
if (mappingKey === "Dump_Raw_To_Log" && state.val === true) {
|
|
946
|
+
await this.setState(relativeId, { val: false, ack: true });
|
|
947
|
+
await (0, import_rawFunctions.dumpAllRawToLog)(this);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
if (isReadOnly) {
|
|
951
|
+
(0, import_logger.writeLog)(
|
|
952
|
+
`[Read-Only] Write attempt to '${id}' blocked! Change Operating Mode in adapter settings to enable hardware writes.`,
|
|
953
|
+
"warn"
|
|
954
|
+
);
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
887
957
|
if (id.startsWith(`${this.namespace}.Custom.`)) {
|
|
888
958
|
try {
|
|
889
959
|
const obj = await this.getObjectAsync(id);
|
|
890
960
|
if (obj && obj.native && obj.native.source === "parameter") {
|
|
891
|
-
const relativeId = id.replace(`${this.namespace}.`, "");
|
|
892
961
|
await this.setState(relativeId, { val: state.val, ack: true });
|
|
893
962
|
let valueToWrite = state.val;
|
|
894
963
|
if (obj.native.customType === "boolean") {
|
|
@@ -916,7 +985,6 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
916
985
|
}
|
|
917
986
|
return;
|
|
918
987
|
}
|
|
919
|
-
const mappingKey = id.split(".").pop();
|
|
920
988
|
if (!mappingKey) {
|
|
921
989
|
return;
|
|
922
990
|
}
|
|
@@ -925,17 +993,6 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
925
993
|
return;
|
|
926
994
|
}
|
|
927
995
|
try {
|
|
928
|
-
const relativeId = id.replace(`${this.namespace}.`, "");
|
|
929
|
-
if (mappingKey === "Schreibe_Debug_Log") {
|
|
930
|
-
await this.setState(relativeId, { val: state.val, ack: true });
|
|
931
|
-
this.isDebugLogActive = state.val === true;
|
|
932
|
-
(0, import_logger.setCustomDebug)(this.isDebugLogActive);
|
|
933
|
-
(0, import_logger.writeLog)(
|
|
934
|
-
`Extended debugging telemetry logging mode has been ${this.isDebugLogActive ? "enabled" : "disabled"}.`,
|
|
935
|
-
"info"
|
|
936
|
-
);
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
996
|
if (mappingKey === "Regelung_Aktiv" || mappingKey === "zip_aktiv") {
|
|
940
997
|
await this.setState(relativeId, { val: state.val, ack: true });
|
|
941
998
|
return;
|
|
@@ -946,11 +1003,6 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
946
1003
|
await this.setIdleDefaults();
|
|
947
1004
|
return;
|
|
948
1005
|
}
|
|
949
|
-
if (mappingKey === "Dump_Raw_To_Log" && state.val === true) {
|
|
950
|
-
await this.setState(relativeId, { val: false, ack: true });
|
|
951
|
-
await (0, import_rawFunctions.dumpAllRawToLog)(this);
|
|
952
|
-
return;
|
|
953
|
-
}
|
|
954
1006
|
if (mappingKey === "Zwangswarmwasser") {
|
|
955
1007
|
if (state.val === true) {
|
|
956
1008
|
await (0, import_actionHandlers.handleZwangswarmwasser)(this, id);
|
|
@@ -974,7 +1026,6 @@ class Luxtronik2Controller extends utils.Adapter {
|
|
|
974
1026
|
}
|
|
975
1027
|
return;
|
|
976
1028
|
}
|
|
977
|
-
const config = this.config;
|
|
978
1029
|
const isModbusEnabled = Boolean(
|
|
979
1030
|
this.modbusManager && this.modbusManager.isAvailable && config.modbus_active && definition.modbus && config[definition.modbus.configKey] === true
|
|
980
1031
|
);
|