[], 'properties' => [], 'writes' => [], 'initialized' => false]; function persistFixture(): void { global $fixture, $fixtureFile; if ($fixtureFile !== '') file_put_contents($fixtureFile, json_encode($fixture, JSON_THROW_ON_ERROR), LOCK_EX); } function check(bool $condition, string $message): void { if (!$condition) throw new RuntimeException($message); } class IPSModuleStrict { protected int $InstanceID; public array $fields = []; public function __construct(int $id = 12345) { $this->InstanceID = $id; } public function Create(): void {} public function ApplyChanges(): void {} public function MessageSink(int $t, int $s, int $m, array $d): void {} protected function RegisterPropertyString(string $name, string $value): void { global $fixture; $fixture['properties'][$name] ??= $value; persistFixture(); } protected function RegisterAttributeString(string $name, string $value): void { global $fixture; $fixture['attributes'][$name] ??= $value; persistFixture(); } protected function RegisterAttributeInteger(string $name, int $value): void { global $fixture; $fixture['attributes'][$name] ??= $value; persistFixture(); } protected function ReadAttributeString(string $name): string { global $fixture; return (string) ($fixture['attributes'][$name] ?? ''); } protected function ReadAttributeInteger(string $name): int { global $fixture; return (int) ($fixture['attributes'][$name] ?? 0); } protected function WriteAttributeString(string $name, string $value): void { global $fixture; $fixture['attributes'][$name] = $value; persistFixture(); } protected function WriteAttributeInteger(string $name, int $value): void { global $fixture; $fixture['attributes'][$name] = $value; persistFixture(); } protected function ReadPropertyString(string $name): string { global $fixture; return (string) ($fixture['properties'][$name] ?? ''); } protected function RegisterMessage(int $sender, int $message): void {} protected function RegisterTimer(string $name, int $interval, string $script): void {} protected function SetTimerInterval(string $name, int $interval): void {} protected function SetVisualizationType(int $type): void {} protected function SetStatus(int $status): void {} protected function LogMessage(string $message, int $type): void { throw new RuntimeException('Unexpected module log: ' . $message); } protected function RegisterHook(string $path): bool { return true; } protected function UpdateFormField(string $name, string $key, mixed $value): void { $this->fields[$name][$key] = $value; } protected function UpdateVisualizationValue(string $value): void {} } function IPS_GetKernelRunlevel(): int { return KR_READY; } function IPS_GetInstanceListByModuleID(string $module): array { return $module === '{43192F0B-135B-4CE7-A0A7-1475603F3060}' ? [700] : []; } function fixtureObjects(): array { return [1 => [0, 0, 'Gebäude'], 10 => [1, 0, 'Büro 2'], 20 => [1, 0, 'Büro 3'], 900 => [20, 1, 'Privates Gerät'], 101 => [10, 2, 'Licht'], 102 => [10, 2, 'Wallbox schalten'], 103 => [10, 2, 'Wallbox Leistung'], 104 => [10, 2, 'Raumtemperatur'], 105 => [10, 4, 'Schaltuhr'], 201 => [900, 2, 'Licht privat'], 203 => [900, 2, 'Leistung privat'], 204 => [20, 2, 'Temperatur privat'], 999 => [1, 2, 'Gesamtleistung'], 888 => [1, 2, 'Nicht mit NextFloor verknüpftes Geheimnis'], 109 => [10, 6, 'Link auf privaten Datenpunkt']]; } function IPS_ObjectExists(int $id): bool { return isset(fixtureObjects()[$id]); } function IPS_VariableExists(int $id): bool { return (fixtureObjects()[$id][1] ?? -1) === 2; } function IPS_EventExists(int $id): bool { return $id === 105; } function IPS_GetName(int $id): string { return fixtureObjects()[$id][2]; } function IPS_GetObject(int $id): array { $o = fixtureObjects()[$id]; return ['ParentID' => $o[0], 'ObjectType' => $o[1], 'ObjectPosition' => $id, 'ObjectIsHidden' => false, 'ObjectIcon' => '']; } function IPS_GetChildrenIDs(int $id): array { return array_keys(array_filter(fixtureObjects(), static fn(array $o): bool => $o[0] === $id)); } function IPS_GetLink(int $id): array { return ['TargetID' => 201]; } function IPS_GetInstance(int $id): array { return ['ModuleInfo' => ['ModuleType' => 3, 'ModuleID' => '{00000000-0000-0000-0000-000000000001}']]; } function IPS_GetVariable(int $id): array { return ['VariableType' => in_array($id, [101, 102, 201], true) ? 0 : 2, 'VariableCustomAction' => 0, 'VariableAction' => in_array($id, [101, 102, 201], true) ? 1 : 0, 'VariableCustomProfile' => '', 'VariableProfile' => '']; } function IPS_GetVariablePresentation(int $id): array { return ['SUFFIX' => in_array($id, [104, 204], true) ? '°C' : (in_array($id, [103, 203, 999], true) ? 'W' : ''), 'MIN' => 0, 'MAX' => 100]; } function IPS_VariableProfileExists(string $name): bool { return false; } function GetValue(int $id): mixed { global $fixture; return $fixture['values'][$id] ?? match ($id) { 101, 102 => true, 201 => false, 104 => 22.3, 204 => 26.7, 103 => 7400.0, 203 => 531.0, default => 7931.0 }; } function GetValueFormatted(int $id): string { $v = GetValue($id); return is_bool($v) ? ($v ? 'An' : 'Aus') : (string) $v; } function RequestAction(int $id, mixed $value): void { global $fixture; $fixture['writes'][] = [$id, $value]; $fixture['values'][$id] = $value; persistFixture(); } function SetValue(int $id, mixed $value): void { RequestAction($id, $value); } function IPS_GetEvent(int $id): array { global $fixture; return ['EventType' => 2, 'EventActive' => $fixture['values'][105] ?? true, 'ScheduleActions' => [], 'ScheduleGroups' => []]; } function IPS_SetEventActive(int $id, bool $active): bool { RequestAction($id, $active); return true; } function AC_GetAggregationVariables(int $id, bool $all): array { return array_map(static fn(int $v): array => ['VariableID' => $v, 'AggregationActive' => true, 'AggregationType' => 0], [104, 204]); } function AC_GetLoggedValues(int $a, int $id, int $start, int $end, int $limit): array { return $start === 0 ? [] : [['TimeStamp' => $start, 'Value' => GetValue($id), 'Duration' => 60], ['TimeStamp' => $end, 'Value' => GetValue($id), 'Duration' => 0]]; } function AC_GetAggregatedValues(int $a, int $id, int $level, int $start, int $end, int $limit): array { return []; } require_once __DIR__ . '/../../NextFloor/module.php'; class AccessFixtureModule extends NextFloor { public function hook(): void { $this->ProcessHookData(); } } function fixtureBuilding(): array { $room = static fn(string $id, string $name, int $x, int $category, string $temperature): array => ['id' => $id, 'name' => $name, 'area_id' => 'symcon-category-' . $category, 'points' => [[$x, 0], [$x + 4, 0], [$x + 4, 3], [$x, 3]], 'floor_material' => 'wood', 'climate_card' => true, 'climate' => ['temperature' => $temperature]]; return ['version' => 1, 'settings' => ['grid' => 0.1, 'north' => 0, 'wall_exterior' => 0.24, 'wall_interior' => 0.12, 'roof' => ['type' => 'none'], 'plugins' => []], 'energy' => ['consumption' => 'sensor.999'], 'presence' => [], 'floors' => [['id' => 'eg', 'name' => 'Erdgeschoss', 'elevation' => 0, 'height' => 2.7, 'cut_height' => 1.2, 'rooms' => [$room('office2', 'Büro 2', 0, 10, 'sensor.104'), $room('office3', 'Büro 3', 5, 20, 'sensor.204')], 'openings' => [], 'walls' => [], 'outdoor' => [], 'background' => null, 'placements' => [['entity_id' => 'light.101', 'x' => 2, 'z' => 1, 'y' => null], ['entity_id' => 'light.201', 'x' => 7, 'z' => 1, 'y' => null]], 'furniture' => [['id' => 'wallbox', 'type' => 'wallbox', 'name' => 'Wallbox Büro 2', 'x' => 3, 'z' => 2, 'w' => 0.3, 'd' => 0.3, 'h' => 0.4, 'rotation' => 0, 'entity' => 'light.102', 'power' => 'sensor.103', 'power_card' => true]]]]]; } function initializeAccessFixture(AccessFixtureModule $module): void { global $fixture; $module->Create(); if ($fixture['initialized']) return; $fixture['properties']['Title'] = 'Bürogebäude'; $fixture['attributes']['Building'] = json_encode(fixtureBuilding(), JSON_THROW_ON_ERROR); $fixture['attributes']['BuildingRevision'] = 1; $make = static function (string $name, string $role, bool $viewAll, bool $controlAll, array $rooms = [], array $devices = [], array $objects = []) use ($module): void { $result = $module->SaveAccessUser('', $name, $role, true, $viewAll, $controlAll, json_encode($rooms), json_encode($devices), json_encode($objects), $name . '-test-password'); check(str_starts_with($result, 'Benutzer gespeichert'), $result); }; $make('admin', 'admin', true, true); $make('reader', 'user', true, false); $make('office', 'user', false, false, [['target' => 'room:eg:office2', 'access' => 'control']]); $make('officeview', 'user', false, false, [['target' => 'room:eg:office2', 'access' => 'view']]); $make('device', 'user', false, false, [], [['target' => 'furniture:eg:wallbox', 'access' => 'control']]); $make('empty', 'user', false, false); $make('operator', 'user', true, true); $make('native', 'user', false, false, [], [], [['target' => 900, 'access' => 'view']]); $fixture['initialized'] = true; persistFixture(); }