58 lines
5.1 KiB
PHP
58 lines
5.1 KiB
PHP
<?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";
|