no message
This commit is contained in:
@@ -15,9 +15,12 @@ class ShellyParser
|
|||||||
return 'unknown';
|
return 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
// alles nach "shelly"
|
// nach 'shelly' den Rest nehmen
|
||||||
$rest = substr($src, 6); // z.B. "1g4-12345" oder "plusplugs-xyz"
|
$rest = substr($src, 6); // z.B. "1g4-12345" oder "mini3-abc"
|
||||||
|
|
||||||
|
// alles vor dem ersten "-" ist der Typ
|
||||||
$parts = explode('-', $rest);
|
$parts = explode('-', $rest);
|
||||||
|
|
||||||
return $parts[0] ?? 'unknown';
|
return $parts[0] ?? 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,14 +139,16 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
private function HandleOnline(string $deviceID, string $payload): void
|
private function HandleOnline(string $deviceID, string $payload): void
|
||||||
{
|
{
|
||||||
$ident = $deviceID . '_online';
|
$value = ($payload === 'true' || $payload === '1');
|
||||||
$name = "Online";
|
|
||||||
|
|
||||||
$varID = $this->EnsureBooleanVariable($deviceID, $ident, $name);
|
$this->SetValue(
|
||||||
$this->SetValue($ident, $payload === 'true' || $payload === '1');
|
$this->EnsureBooleanVariable($deviceID, $deviceID . '_online', 'Online'),
|
||||||
|
$value
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* RPC-EVENTS
|
* RPC-EVENTS
|
||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
@@ -158,43 +160,44 @@ private function HandleRPC(string $deviceID, string $payload): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
$src = $json['src'] ?? '';
|
$src = $json['src'] ?? '';
|
||||||
if (!str_starts_with($src, 'shelly')) {
|
if (!is_string($src) || !str_starts_with($src, 'shelly')) {
|
||||||
return; // kein Shelly-Gerät
|
|
||||||
}
|
|
||||||
|
|
||||||
// Typ extrahieren
|
|
||||||
$type = ShellyParser::ExtractType($src);
|
|
||||||
$typeIdent = $deviceID . '_type';
|
|
||||||
$this->EnsureStringVariable($deviceID, $typeIdent, 'Typ');
|
|
||||||
$this->SetValue($typeIdent, $type);
|
|
||||||
|
|
||||||
$params = $json['params'] ?? [];
|
|
||||||
if (!is_array($params)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modell Typ extrahieren
|
||||||
|
$type = ShellyParser::ExtractType($src);
|
||||||
|
|
||||||
|
// Typ Variable
|
||||||
|
$this->SetValue(
|
||||||
|
$this->EnsureStringVariable($deviceID, $deviceID . '_type', 'Typ'),
|
||||||
|
$type
|
||||||
|
);
|
||||||
|
|
||||||
|
// PARAMETER MAPPEN
|
||||||
|
$params = $json['params'] ?? [];
|
||||||
$mapped = ShellyParser::MapParams($params);
|
$mapped = ShellyParser::MapParams($params);
|
||||||
|
|
||||||
// INPUT
|
// INPUT
|
||||||
if (array_key_exists('input', $mapped)) {
|
if (isset($mapped['input'])) {
|
||||||
$ident = $deviceID . '_input';
|
$this->SetValue(
|
||||||
$this->EnsureBooleanVariable($deviceID, $ident, 'Input');
|
$this->EnsureBooleanVariable($deviceID, $deviceID . '_input', 'Input'),
|
||||||
$this->SetValue($ident, (bool)$mapped['input']);
|
(bool)$mapped['input']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// OUTPUT
|
// OUTPUT
|
||||||
if (array_key_exists('output', $mapped)) {
|
if (isset($mapped['output'])) {
|
||||||
$ident = $deviceID . '_output';
|
$varID = $this->EnsureBooleanVariable($deviceID, $deviceID . '_output', 'Output');
|
||||||
$varID = $this->EnsureBooleanVariable($deviceID, $ident, 'Output');
|
$this->EnableAction($deviceID . '_output');
|
||||||
$this->EnableAction($ident);
|
$this->SetValue($varID, (bool)$mapped['output']);
|
||||||
$this->SetValue($ident, (bool)$mapped['output']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEMPERATUR
|
// TEMPERATURE
|
||||||
if (array_key_exists('temperature', $mapped)) {
|
if (isset($mapped['temperature'])) {
|
||||||
$ident = $deviceID . '_temperature';
|
$this->SetValue(
|
||||||
$this->EnsureFloatVariable($deviceID, $ident, 'Temperatur');
|
$this->EnsureFloatVariable($deviceID, $deviceID . '_temperature', 'Temperatur'),
|
||||||
$this->SetValue($ident, (float)$mapped['temperature']);
|
(float)$mapped['temperature']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,11 +209,17 @@ private function HandleRPC(string $deviceID, string $payload): void
|
|||||||
{
|
{
|
||||||
$folderID = $this->GetDeviceFolder($deviceID);
|
$folderID = $this->GetDeviceFolder($deviceID);
|
||||||
|
|
||||||
$varID = @$this->GetIDForIdent($ident);
|
// Immer im Ordner suchen
|
||||||
if ($varID === false) {
|
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
|
||||||
$varID = $this->RegisterVariableBoolean($ident, $name);
|
if (IPS_GetObject($cid)['ObjectIdent'] === $ident) {
|
||||||
IPS_SetParent($varID, $folderID);
|
return $cid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Neue Variable anlegen
|
||||||
|
$varID = $this->RegisterVariableBoolean($ident, $name);
|
||||||
|
IPS_SetParent($varID, $folderID);
|
||||||
|
|
||||||
return $varID;
|
return $varID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,11 +227,15 @@ private function HandleRPC(string $deviceID, string $payload): void
|
|||||||
{
|
{
|
||||||
$folderID = $this->GetDeviceFolder($deviceID);
|
$folderID = $this->GetDeviceFolder($deviceID);
|
||||||
|
|
||||||
$varID = @$this->GetIDForIdent($ident);
|
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
|
||||||
if ($varID === false) {
|
if (IPS_GetObject($cid)['ObjectIdent'] === $ident) {
|
||||||
$varID = $this->RegisterVariableFloat($ident, $name);
|
return $cid;
|
||||||
IPS_SetParent($varID, $folderID);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$varID = $this->RegisterVariableFloat($ident, $name);
|
||||||
|
IPS_SetParent($varID, $folderID);
|
||||||
|
|
||||||
return $varID;
|
return $varID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,32 +243,37 @@ private function HandleRPC(string $deviceID, string $payload): void
|
|||||||
{
|
{
|
||||||
$folderID = $this->GetDeviceFolder($deviceID);
|
$folderID = $this->GetDeviceFolder($deviceID);
|
||||||
|
|
||||||
$varID = @$this->GetIDForIdent($ident);
|
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
|
||||||
if ($varID === false) {
|
if (IPS_GetObject($cid)['ObjectIdent'] === $ident) {
|
||||||
$varID = $this->RegisterVariableString($ident, $name);
|
return $cid;
|
||||||
IPS_SetParent($varID, $folderID);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$varID = $this->RegisterVariableString($ident, $name);
|
||||||
|
IPS_SetParent($varID, $folderID);
|
||||||
|
|
||||||
return $varID;
|
return $varID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function GetDeviceFolder(string $deviceID): int
|
private function GetDeviceFolder(string $deviceID): int
|
||||||
{
|
{
|
||||||
$folderIdent = 'folder_' . $deviceID;
|
$folderIdent = 'folder_' . $deviceID;
|
||||||
|
|
||||||
$folderID = @$this->GetIDForIdent($folderIdent);
|
$folderID = @IPS_GetObjectIDByIdent($folderIdent);
|
||||||
if ($folderID !== false) {
|
if ($folderID !== false) {
|
||||||
return $folderID;
|
return $folderID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ordner erzeugen
|
|
||||||
$folderID = IPS_CreateCategory();
|
$folderID = IPS_CreateCategory();
|
||||||
IPS_SetParent($folderID, $this->InstanceID);
|
IPS_SetParent($folderID, $this->InstanceID);
|
||||||
IPS_SetIdent($folderID, $folderIdent);
|
|
||||||
IPS_SetName($folderID, $deviceID);
|
IPS_SetName($folderID, $deviceID);
|
||||||
|
IPS_SetIdent($folderID, $folderIdent);
|
||||||
|
|
||||||
return $folderID;
|
return $folderID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user