Files
Symcon_Belevo_Energiemanage…/Int_VGT/libs/ShellyParser.php

46 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
class ShellyParser
{
/** Modell aus src extrahieren */
public static function ExtractType(string $src): string
{
// Beispiel: "shelly1g4-12345"
if (!str_starts_with($src, "shelly")) {
return "unknown";
}
$str = substr($src, 6); // "1g4-12345"
$parts = explode("-", $str); // ["1g4", "12345"]
return $parts[0] ?? "unknown";
}
/** generisches Mapping für Shelly Daten */
public static function MapParams(array $params): array
{
$mapped = [];
foreach ($params as $key => $val) {
if ($key === "input") {
$mapped["input"] = (bool)$val;
}
if ($key === "output") {
$mapped["output"] = (bool)$val;
}
if ($key === "temperature" || $key === "temp") {
$mapped["temperature"] = (float)$val;
}
// weitere Shelly-Geräte können später hier ergänzt werden
}
return $mapped;
}
}