Skip to content

Commit 6cada68

Browse files
authored
Merge pull request #3061 from openWB/add_simpleAPI_lastliveJson
Add get_lastlivejson to get values from openWB/system/lastliveJson
2 parents aaa3002 + b67bb1c commit 6cada68

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

simpleAPI/simpleapi.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ private function getReadParameters($params)
276276
'get_pv_monthly_exported',
277277
'get_pv_yearly_exported',
278278
'get_pv_fault_str',
279-
'get_pv_fault_state'
279+
'get_pv_fault_state',
280+
// System - Werte
281+
'get_lastlivevaluesjson'
280282
];
281283

282284
foreach ($readableKeys as $key) {
@@ -485,9 +487,17 @@ private function formatRawOutput($data)
485487
$firstKey = array_keys($data)[0];
486488
$firstValue = $data[$firstKey];
487489

490+
// Für JSON-Strings: direkt den String-Wert zurückgeben
491+
if (is_string($firstValue)) {
492+
return $firstValue;
493+
}
494+
488495
if (is_array($firstValue) && count($firstValue) === 1) {
489496
return array_values($firstValue)[0];
490497
}
498+
499+
// Für andere Array-Strukturen: ersten Wert zurückgeben
500+
return $firstValue;
491501
}
492502

493503
return $data;

simpleAPI/src/ParameterHandler.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ public function readParameter($param, $id)
200200
case 'get_pv_fault_state':
201201
return $this->getPvFaultState($id);
202202

203+
case 'get_lastlivevaluesjson':
204+
return $this->getLastLiveValuesJson();
205+
203206
default:
204207
return null;
205208
}
@@ -1531,4 +1534,24 @@ private function setBatMode($value)
15311534
return ['success' => false, 'message' => 'Error setting bat mode: ' . $e->getMessage()];
15321535
}
15331536
}
1537+
1538+
/**
1539+
* Lese openWB/system/lastlivevaluesJson Topic 1:1 aus
1540+
*/
1541+
private function getLastLiveValuesJson()
1542+
{
1543+
$topic = "openWB/graph/lastlivevaluesJson";
1544+
$jsonValue = $this->mqttClient->getValue($topic);
1545+
1546+
if ($jsonValue === null) {
1547+
return [
1548+
'get_lastlivevaluesjson' => null
1549+
];
1550+
}
1551+
1552+
// JSON-String 1:1 zurückgeben
1553+
return [
1554+
'get_lastlivevaluesjson' => $jsonValue
1555+
];
1556+
}
15341557
}

0 commit comments

Comments
 (0)