no message

This commit is contained in:
2025-11-24 11:12:44 +01:00
parent 5aef0385f5
commit cd7d8261eb

View File

@@ -99,17 +99,20 @@ class Shelly_Parser_MQTT extends IPSModule
* ---------------------------------------------------------*/ * ---------------------------------------------------------*/
public function RequestAction($Ident, $Value) public function RequestAction($Ident, $Value)
{ {
$this->Log('RequestAction', "$Ident$Value"); $this->Log('RequestAction', "$Ident" . var_export($Value, true));
// Nur Outputs sind schaltbar
if (!str_contains($Ident, '_output_')) { if (!str_contains($Ident, '_output_')) {
throw new Exception("Unknown Ident: $Ident"); throw new Exception("Unknown Ident: $Ident");
} }
// Lokale Variable aktualisieren
$varID = $this->FindVariableByIdent($Ident); $varID = $this->FindVariableByIdent($Ident);
if ($varID > 0) { if ($varID > 0) {
SetValue($varID, $Value); SetValue($varID, $Value);
} }
// deviceID und Index extrahieren
[$deviceID, $suffix] = explode('_output_', $Ident); [$deviceID, $suffix] = explode('_output_', $Ident);
$index = intval($suffix); $index = intval($suffix);
@@ -138,19 +141,25 @@ class Shelly_Parser_MQTT extends IPSModule
$this->EnsureSubscribe(); $this->EnsureSubscribe();
$data = json_decode($JSONString, true); $data = json_decode($JSONString, true);
if (!is_array($data)) return; if (!is_array($data)) {
return;
}
$topic = $data['Topic'] ?? ''; $topic = $data['Topic'] ?? '';
$payload = $data['Payload'] ?? ''; $payload = $data['Payload'] ?? '';
if ($topic === '') return; if ($topic === '') {
return;
}
$this->Log('ReceiveTopic', "$topic$payload"); $this->Log('ReceiveTopic', "$topic$payload");
$parts = explode('/', $topic); $parts = explode('/', $topic);
$deviceID = $parts[0] ?? ''; $deviceID = $parts[0] ?? '';
if ($deviceID === '') return; if ($deviceID === '') {
return;
}
// Online // Online
if (($parts[1] ?? '') === 'online') { if (($parts[1] ?? '') === 'online') {
@@ -182,13 +191,17 @@ class Shelly_Parser_MQTT extends IPSModule
private function HandleRPC(string $deviceID, string $payload) private function HandleRPC(string $deviceID, string $payload)
{ {
$json = json_decode($payload, true); $json = json_decode($payload, true);
if (!is_array($json)) return; if (!is_array($json)) {
return;
}
$src = $json['src'] ?? ''; $src = $json['src'] ?? '';
if (!str_starts_with($src, 'shelly')) return; if (!str_starts_with($src, 'shelly')) {
return;
}
// Typ // Typ
$type = ShellyParser::ExtractType($src); $type = ShellyParser::ExtractType($src);
$typeID = $this->EnsureStringVariable($deviceID, $deviceID . '_type', 'Typ'); $typeID = $this->EnsureStringVariable($deviceID, $deviceID . '_type', 'Typ');
SetValue($typeID, $type); SetValue($typeID, $type);
@@ -220,34 +233,36 @@ class Shelly_Parser_MQTT extends IPSModule
private function EnsureBooleanVariable(string $deviceID, string $ident, string $name): int private function EnsureBooleanVariable(string $deviceID, string $ident, string $name): int
{ {
$folder = $this->GetDeviceFolder($deviceID); $folder = $this->GetDeviceFolder($deviceID);
$vid = 0;
// Gibt es die Variable schon?
foreach (IPS_GetChildrenIDs($folder) as $cid) { foreach (IPS_GetChildrenIDs($folder) as $cid) {
if (IPS_GetObject($cid)['ObjectIdent'] === $ident) { $obj = IPS_GetObject($cid);
if ($obj['ObjectIdent'] === $ident) {
// ---- Action wieder setzen, falls sie fehlt ---- $vid = $cid;
if (str_contains($ident, '_output_')) { break;
IPS_SetVariableCustomAction($cid, $this->InstanceID);
}
return $cid;
} }
} }
// Variable neu anlegen // Neu anlegen, falls nicht vorhanden
$vid = IPS_CreateVariable(0); if ($vid === 0) {
IPS_SetName($vid, $name); $vid = IPS_CreateVariable(0); // 0 = Boolean
IPS_SetIdent($vid, $ident); IPS_SetName($vid, $name);
IPS_SetParent($vid, $folder); IPS_SetIdent($vid, $ident);
IPS_SetParent($vid, $folder);
}
// ---- HIER: Action für Output-Variablen setzen ---- // ---- HIER: nur für Outputs Action + Profil setzen ----
if (str_contains($ident, '_output_')) { if (str_contains($ident, '_output_')) {
// Schaltprofil
IPS_SetVariableCustomProfile($vid, '~Switch');
// Aktion geht direkt an dieses Modul (RequestAction)
IPS_SetVariableCustomAction($vid, $this->InstanceID); IPS_SetVariableCustomAction($vid, $this->InstanceID);
} }
return $vid; return $vid;
} }
private function EnsureFloatVariable(string $deviceID, string $ident, string $name): int private function EnsureFloatVariable(string $deviceID, string $ident, string $name): int
{ {
$folder = $this->GetDeviceFolder($deviceID); $folder = $this->GetDeviceFolder($deviceID);