major changes to variables, weather and datalinkage

This commit is contained in:
jhartworks committed 2026-11-11 11:06:33 +01:00
1 parent d2c0f5b111
commit bc375e4c17
8 files changed
+1345 -1087

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
// Native variables and classic weekly schedule events; no live Symcon system is modified.
class IPSModuleStrict {}
$objects = [
10 => ['ParentID' => 0, 'ObjectName' => 'Gebäude', 'ObjectType' => 0],
11 => ['ParentID' => 10, 'ObjectName' => 'Heizung Wochenplan', 'ObjectType' => 4],
12 => ['ParentID' => 10, 'ObjectName' => 'Zyklischer Timer', 'ObjectType' => 4],
13 => ['ParentID' => 10, 'ObjectName' => 'Verknüpfte Schaltuhr', 'ObjectType' => 6],
14 => ['ParentID' => 10, 'ObjectName' => 'Heizung', 'ObjectType' => 2],
15 => ['ParentID' => 10, 'ObjectName' => 'Raumstatus', 'ObjectType' => 2],
];
$events = [11 => ['EventType' => 2, 'EventActive' => true, 'NextRun' => 1794387600, 'NextActionID' => 2,
'ScheduleActions' => [['ID' => 1, 'Name' => 'Nacht', 'Color' => 255, 'ScriptText' => 'SECRET_SCRIPT', 'ActionParameters' => ['secret' => true]], ['ID' => 2, 'Name' => 'Tag', 'Color' => 16711680]],
'ScheduleGroups' => [['ID' => 0, 'Days' => 31, 'Points' => [['ID' => 0, 'Start' => ['Hour' => 6, 'Minute' => 30, 'Second' => 0], 'ActionID' => 2]]]]], 12 => ['EventType' => 1]];
$writes = [];
function check(bool $value, string $message): void { if (!$value) throw new RuntimeException($message); }
function IPS_GetChildrenIDs(int $id): array { global $objects; return array_keys(array_filter($objects, fn($o) => $o['ParentID'] === $id)); }
function IPS_ObjectExists(int $id): bool { global $objects; return isset($objects[$id]); }
function IPS_GetObject(int $id): array { global $objects; return [...$objects[$id], 'ObjectPosition' => 0, 'ObjectIsHidden' => false, 'ObjectIcon' => '']; }
function IPS_GetName(int $id): string { global $objects; return $objects[$id]['ObjectName']; }
function IPS_GetLink(int $id): array { return ['TargetID' => 11]; }
function IPS_GetEvent(int $id): array { global $events; return $events[$id]; }
function IPS_EventExists(int $id): bool { global $events; return isset($events[$id]); }
function IPS_SetEventActive(int $id, bool $active): bool { global $events; $events[$id]['EventActive'] = $active; return true; }
function IPS_VariableExists(int $id): bool { return in_array($id, [14, 15]); }
function IPS_GetVariable(int $id): array { return ['VariableType' => $id === 14 ? 0 : 1, 'VariableProfile' => '', 'VariableCustomProfile' => '', 'VariableAction' => $id === 14 ? 123 : 0, 'VariableCustomAction' => 0]; }
function GetValue(int $id): mixed { return $id === 14 ? false : 2; }
function GetValueFormatted(int $id): string { return $id === 14 ? 'Aus' : 'Besprechung'; }
function IPS_GetVariablePresentation(int $id): array { return []; }
function IPS_VariableProfileExists(string $profile): bool { return false; }
function RequestAction(int $id, mixed $value): void { global $writes; $writes[] = [$id, $value]; }
function SetValue(int $id, mixed $value): void { throw new LogicException('Native controls must never silently write read-only variables'); }
require __DIR__ . '/../NextFloor/module.php';
$module = new NextFloor();
$tree = (new ReflectionMethod($module, 'objectTree'))->invoke($module);
$states = array_column($tree['variables'], null, 'entity_id');
$nodes = array_column($tree['objects'], null, 'object_id');
check($nodes[11]['entity_id'] === 'schedule.11' && $nodes[13]['entity_id'] === 'schedule.11', 'Schedule events and their links are selectable in the original object tree');
check(!isset($nodes[12]['entity_id']), 'Ordinary timers must not be offered as weekly schedules');
check($states['schedule.11']['attributes']['groups'][0]['days'] === 31 && $states['schedule.11']['attributes']['groups'][0]['points'][0]['minute'] === 30, 'Native day masks and switch times must survive export');
check(!str_contains(json_encode($tree), 'SECRET_SCRIPT') && !str_contains(json_encode($tree), 'ActionParameters'), 'Action scripts and parameters must not be exported');
check($states[$nodes[14]['entity_id']]['attributes']['symcon_value'] === false, 'Native Boolean false is preserved');
check($states[$nodes[15]['entity_id']]['attributes']['symcon_formatted'] === 'Besprechung', 'Integer status retains its Symcon alias');
$action = new ReflectionMethod($module, 'variableAction');
$before = $events[11]['ScheduleGroups'];
$action->invoke($module, 'schedule', 'set_active', ['entity_id' => 'schedule.11', 'active' => false]);
check($events[11]['EventActive'] === false && $events[11]['ScheduleGroups'] === $before, 'Disabling a linked clock must retain every switch point');
$action->invoke($module, 'symcon', 'set_value', ['entity_id' => 'switch.14', 'value' => true]);
check($writes === [[14, true]], 'Writable native Boolean uses RequestAction');
foreach ([['schedule', 'set_active', ['entity_id' => 'schedule.12', 'active' => true]], ['symcon', 'set_value', ['entity_id' => 'sensor.15', 'value' => 3]], ['symcon', 'set_value', ['entity_id' => 'switch.14', 'value' => 'false']]] as $call) {
try { $action->invoke($module, ...$call); throw new LogicException('Invalid native action accepted'); }
catch (InvalidArgumentException) {}
}
echo "OK: selectable native schedules, protected action data, aliases, raw Boolean controls and read-only guards\n";
+2 -1
View File
@@ -25,7 +25,7 @@ $objects = [
function IPS_GetChildrenIDs(int $id): array { global $objects; return array_keys(array_filter($objects, static fn(array $object): bool => $object['ParentID'] === $id)); }
function IPS_ObjectExists(int $id): bool { global $objects; return isset($objects[$id]); }
function IPS_GetObject(int $id): array { global $objects; return [...$objects[$id], 'ObjectIsHidden' => in_array($id, [10, 12], true), 'ObjectIcon' => 'Temperature']; }
function IPS_GetInstance(int $id): array { return ['ModuleInfo' => ['ModuleType' => [18 => 1, 20 => 0, 21 => 2, 22 => 4, 23 => 5, 24 => 6][$id] ?? 3]]; }
function IPS_GetInstance(int $id): array { return ['ModuleInfo' => ['ModuleType' => [18 => 1, 20 => 0, 21 => 2, 22 => 4, 23 => 5, 24 => 6][$id] ?? 3, 'ModuleID' => $id === 11 ? '{485D0419-BE97-4548-AA9C-C083EB82E61E}' : '{OTHER}']]; }
function IPS_GetName(int $id): string { global $objects; return $objects[$id]['ObjectName']; }
function IPS_GetLink(int $id): array { return ['TargetID' => 12]; }
function IPS_GetVariable(int $id): array { return ['VariableType' => 2, 'VariableProfile' => '', 'VariableCustomProfile' => '', 'VariableCustomAction' => 0, 'VariableAction' => 0]; }
@@ -48,4 +48,5 @@ check(!isset($nodes[16]['entity_id']), 'Scripts are visible but are not variable
check($nodes[10]['hidden'] === true && $nodes[11]['parent_id'] === 10, 'Hidden categories and all their children must be exported');
check(array_column(array_intersect_key($nodes, array_flip([18, 20, 21, 22, 23, 24])), 'module_type') === [1, 0, 2, 4, 5, 6], 'Export real module types for logical system grouping');
check($nodes[11]['module_type'] === 3 && $nodes[19]['parent_id'] === 18, 'Keep devices and system-variable parents unchanged in native export');
check($nodes[11]['module_id'] === '{485D0419-BE97-4548-AA9C-C083EB82E61E}', 'Export the real module ID so dummy utility containers can be recognized');
echo "OK: full native object hierarchy, positions, hidden nodes and variable links\n";