feat: improve Symcon designer controls and KNX temperature selection
This commit is contained in:
1 parent
804f2d0494
commit
b934f78b9a
24 files changed
+908
-562
No files matched your search
@@ -417,7 +417,12 @@ class NextFloor extends IPSModuleStrict
|
||||
private function describeVariable(int $variableID, string $name, string $path, ?int $categoryID): array
|
||||
{
|
||||
$variable = IPS_GetVariable($variableID);
|
||||
$profile = (string) ($variable['VariableCustomProfile'] ?: $variable['VariableProfile']);
|
||||
$profile = (string) (($variable['VariableCustomProfile'] ?? '') ?: ($variable['VariableProfile'] ?? ''));
|
||||
// Symcon 9 presentations can carry a unit without any legacy variable profile.
|
||||
$presentation = IPS_GetVariablePresentation($variableID);
|
||||
$profile = (string) ($presentation['PROFILE'] ?? $profile);
|
||||
$profileData = $profile !== '' && IPS_VariableProfileExists($profile) ? IPS_GetVariableProfile($profile) : [];
|
||||
$unit = trim((string) ($presentation['SUFFIX'] ?? $profileData['Suffix'] ?? ''));
|
||||
$value = GetValue($variableID);
|
||||
$kind = $this->kindFor($variable, $profile, $name . ' ' . $path);
|
||||
$attributes = [
|
||||
@@ -427,11 +432,15 @@ class NextFloor extends IPSModuleStrict
|
||||
'symcon_variable_type' => (int) $variable['VariableType'],
|
||||
'symcon_has_action' => ((int) ($variable['VariableCustomAction'] ?: $variable['VariableAction'])) !== 0,
|
||||
'symcon_formatted' => GetValueFormatted($variableID),
|
||||
'device_class' => $this->deviceClassFor($profile, $name . ' ' . $path)
|
||||
'device_class' => $this->deviceClassFor($profile, $name . ' ' . $path, $unit)
|
||||
];
|
||||
$profileData = $profile !== '' && IPS_VariableProfileExists($profile) ? IPS_GetVariableProfile($profile) : null;
|
||||
if (is_array($profileData) && (string) ($profileData['Suffix'] ?? '') !== '') {
|
||||
$attributes['unit_of_measurement'] = trim((string) $profileData['Suffix']);
|
||||
if ($unit !== '') {
|
||||
$attributes['unit_of_measurement'] = $unit;
|
||||
}
|
||||
if (in_array((int) $variable['VariableType'], [1, 2], true)) {
|
||||
// Keep the actual numeric reading even when legacy name heuristics chose an actuator domain.
|
||||
// Existing synthetic entity IDs stay stable so saved plan mappings keep working.
|
||||
$attributes['symcon_numeric_value'] = $value;
|
||||
}
|
||||
if ($kind === 'light' && is_numeric($value)) {
|
||||
$attributes['brightness'] = (int) round(max(0, min(100, (float) $value)) * 2.55);
|
||||
@@ -490,9 +499,18 @@ class NextFloor extends IPSModuleStrict
|
||||
return 'sensor';
|
||||
}
|
||||
|
||||
private function deviceClassFor(string $profile, string $haystack): string
|
||||
private function deviceClassFor(string $profile, string $haystack, string $unit = ''): string
|
||||
{
|
||||
$text = mb_strtolower($profile . ' ' . $haystack);
|
||||
$unitClass = match (preg_replace('/[\s\x{00A0}]+/u', '', mb_strtolower($unit))) {
|
||||
'°c', '°f', '℃', '℉', 'k' => 'temperature',
|
||||
'ppm' => str_contains($text, 'co2') || str_contains($text, 'co₂') ? 'carbon_dioxide' : '',
|
||||
'w', 'kw' => 'power',
|
||||
default => ''
|
||||
};
|
||||
if ($unitClass !== '') {
|
||||
return $unitClass;
|
||||
}
|
||||
return match (true) {
|
||||
str_contains($text, 'temperature') || str_contains($text, 'temperatur') => 'temperature',
|
||||
str_contains($text, 'humidity') || str_contains($text, 'feuchte') => 'humidity',
|
||||
|
||||
Reference in new issue
Block a user