"1g4" * "shellyplusplugs-xyz" => "plusplugs" */ public static function ExtractType(string $src): string { if (!str_starts_with($src, 'shelly')) { return 'unknown'; } // nach 'shelly' den Rest nehmen $rest = substr($src, 6); // z.B. "1g4-12345" oder "mini3-abc" // alles vor dem ersten "-" ist der Typ $parts = explode('-', $rest); return $parts[0] ?? 'unknown'; } /** * Geht rekursiv durch params und sammelt bekannte Werte: * - input (bool) * - output (bool) * - temperature (float, inkl. tC) */ public static function MapParams(array $params): array { $mapped = [ 'input' => null, 'output' => null, 'temperature' => null ]; self::ExtractRecursive($params, $mapped); // null-Werte rauswerfen return array_filter($mapped, static function ($v) { return $v !== null; }); } private static function ExtractRecursive(array $data, array &$mapped): void { foreach ($data as $key => $value) { $lowerKey = strtolower((string)$key); if (is_array($value)) { // Temperatur in verschachtelter Struktur, z.B. ["temperature" => ["tC" => 41.2]] if ($lowerKey === 'temperature') { if (isset($value['tC']) && is_numeric($value['tC'])) { $mapped['temperature'] = (float)$value['tC']; } elseif (isset($value['t']) && is_numeric($value['t'])) { $mapped['temperature'] = (float)$value['t']; } } self::ExtractRecursive($value, $mapped); continue; } switch ($lowerKey) { case 'input': $mapped['input'] = (bool)$value; break; case 'output': $mapped['output'] = (bool)$value; break; case 'temperature': case 'tc': case 't': if (is_numeric($value)) { $mapped['temperature'] = (float)$value; } break; } } } } ?>