no message
This commit is contained in:
@@ -33,34 +33,51 @@ class ShellyParser
|
||||
public static function MapParams(array $params): array
|
||||
{
|
||||
$mapped = [
|
||||
'input' => null,
|
||||
'output' => null,
|
||||
'outputs' => [], // switch:x → output
|
||||
'inputs' => [], // input:x → state oder switch:x.input
|
||||
'temperature' => null
|
||||
];
|
||||
|
||||
// GEN3 / GEN4 Geräte → switch:0, switch:1, ...
|
||||
foreach ($params as $key => $value) {
|
||||
|
||||
// -----------------------------
|
||||
// OUTPUTS (switch:0 → output)
|
||||
// -----------------------------
|
||||
if (str_starts_with($key, 'switch:') && is_array($value)) {
|
||||
|
||||
// Output
|
||||
$index = (int)substr($key, 7);
|
||||
|
||||
if (isset($value['output'])) {
|
||||
$mapped['output'] = (bool)$value['output'];
|
||||
$mapped['outputs'][$index] = (bool)$value['output'];
|
||||
}
|
||||
|
||||
// Input (für Pro / Gen4 Geräte)
|
||||
// Gen4 / Pro Geräte haben input im switch
|
||||
if (isset($value['input'])) {
|
||||
$mapped['input'] = (bool)$value['input'];
|
||||
$mapped['inputs'][$index] = (bool)$value['input'];
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// INPUTS (input:0 → state)
|
||||
// -----------------------------
|
||||
if (str_starts_with($key, 'input:') && is_array($value)) {
|
||||
|
||||
$index = (int)substr($key, 6);
|
||||
|
||||
if (isset($value['state'])) {
|
||||
$mapped['inputs'][$index] = (bool)$value['state'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Temperatur suchen (beliebig tief)
|
||||
// Temperatur-Suche (verschachtelt)
|
||||
self::ExtractRecursive($params, $mapped);
|
||||
|
||||
return array_filter($mapped, fn($v) => $v !== null);
|
||||
return $mapped;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static function ExtractRecursive(array $data, array &$mapped): void
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
Reference in New Issue
Block a user