Skip to content

Commit

Permalink
Fix Availability in ReceiveFilter & SetValue
Browse files Browse the repository at this point in the history
Fix Array to String conversion in DecodeData
  • Loading branch information
Nall-chan committed Oct 20, 2024
1 parent 418c15a commit e8645ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Device/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"Auto": "Automatisch",
"Automatic": "Automatisch",
"Autumn Gold": "Herbstgold",
"Availability": "Verfügbarkeit",
"Away Mode": "Urlaubsmodus",
"Away or Vacation": "Abwesend / Urlaub",
"Away Preset Days": "Urlaubsmodus default Tage",
Expand Down Expand Up @@ -896,4 +897,4 @@
"IEEE Address": "IEEE Adresse"
}
}
}
}
14 changes: 7 additions & 7 deletions libs/ModulBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function ApplyChanges()
return;
}
//Setze Filter für ReceiveData
$Filter1 = preg_quote('"Topic":"' . $BaseTopic . '/' . $MQTTTopic . '"');
$Filter1 = preg_quote('"Topic":"' . $BaseTopic . '/' . $MQTTTopic);
$Filter2 = preg_quote('"Topic":"' . $BaseTopic . '/SymconExtension/response/' . static::$ExtensionTopic . $MQTTTopic);
$this->SendDebug('Filter', '.*(' . $Filter1 . '|' . $Filter2 . ').*', 0);
$this->SetReceiveDataFilter('.*(' . $Filter1 . '|' . $Filter2 . ').*');
Expand Down Expand Up @@ -312,8 +312,8 @@ public function ReceiveData($JSONString)

// Separates Verarbeiten des Verfügbarkeitsstatus (online/offline)
if (end($Topics) == 'availability') {
$this->RegisterVariableBoolean('Z2M_Status', $this->Translate('Status'), 'Z2M.DeviceStatus');
$this->SetValue('Z2M_Status', $Buffer['Payload'] == 'online');
$this->RegisterVariableBoolean('Z2M_Status', $this->Translate('Availability'), 'Z2M.DeviceStatus');
$this->SetValue('Z2M_Status', $Buffer['Payload'] == '{"state":"online"}');
return '';
}

Expand Down Expand Up @@ -540,7 +540,7 @@ protected function DecodeData($Payload)
// Umrechnung von Mired in Kelvin für 'color_temp'
if ($key === 'color_temp') {
$value = intval(1000000 / $value); // Umrechnung Mired nach Kelvin
$this->SendDebug(__FUNCTION__ . ' :: ' . __LINE__ . ' :: Converted color_temp to Kelvin: ', $value, 0);
$this->SendDebug(__FUNCTION__ . ' :: ' . __LINE__ . ' :: Converted color_temp to Kelvin: ', (string) $value, 0);
}
// Erstelle den Ident-Namen basierend auf dem Property-Namen
$ident = self::convertPropertyToIdent($key);
Expand Down Expand Up @@ -625,7 +625,7 @@ protected function DecodeData($Payload)
}
} else {
// Fallback: Wert ohne Typinformationen setzen
$this->SetValue($ident, $value);
$this->SetValue($ident, is_array($value) ? json_encode($value) : $value);
}
}
}
Expand Down Expand Up @@ -666,7 +666,7 @@ protected function DecodeData($Payload)
*/
protected function SetValue($Ident, $Value)
{
$this->SendDebug(__FUNCTION__ . ' :: ' . __LINE__ . ' :: Incoming value for ' . $Ident, (is_array($Value) ? json_encode($Value) : $Value), 0);
$this->SendDebug(__FUNCTION__ . ' :: ' . __LINE__ . ' :: Incoming value for ' . $Ident, $Value, 0);

// Standardwert für adjustedValue setzen
$adjustedValue = $Value;
Expand Down Expand Up @@ -763,7 +763,7 @@ protected function SetValue($Ident, $Value)
$adjustedValue = (string) $Value;
break;
default:
$adjustedValue = $Value; // Fallback, falls der Typ unbekannt ist
$adjustedValue = (string) $Value; // Fallback, falls der Typ unbekannt ist
break;
}
}
Expand Down

0 comments on commit e8645ed

Please sign in to comment.