feat: add native Symcon archive trends and explicit room naming

This commit is contained in:
jhartworks committed 2026-11-11 12:00:51 +01:00
1 parent a4d195ba10
commit 9276d1c28a
8 files changed
+1057 -584

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
// Read-only native Archive Control fixtures exercise the actual module methods.
class IPSModuleStrict {}
$types = [30 => 2, 31 => 0, 32 => 3, 33 => 1, 34 => 2, 35 => 1];
$calls = []; $dense = false; $metadataQueries = 0;
function check(bool $ok, string $message): void { if (!$ok) throw new RuntimeException($message); }
function IPS_GetInstanceListByModuleID(string $id): array { check($id === '{43192F0B-135B-4CE7-A0A7-1475603F3060}', 'Discover native Archive Control'); return [100]; }
function AC_GetAggregationVariables(int $archive, bool $database): array {
global $metadataQueries; ++$metadataQueries;
return array_map(fn($id) => ['VariableID' => $id, 'AggregationActive' => $id !== 35, 'AggregationVisible' => false, 'AggregationType' => $id === 34 ? 1 : 0, 'FirstTime' => 100, 'LastTime' => 1900], [30, 31, 32, 34, 35]);
}
function IPS_GetChildrenIDs(int $id): array { global $types; return $id === 0 ? [10] : ($id === 10 ? array_keys($types) : []); }
function IPS_ObjectExists(int $id): bool { return $id === 10 || IPS_VariableExists($id); }
function IPS_VariableExists(int $id): bool { global $types; return isset($types[$id]); }
function IPS_GetObject(int $id): array { return ['ParentID' => $id === 10 ? 0 : 10, 'ObjectType' => $id === 10 ? 0 : 2, 'ObjectName' => $id === 10 ? 'Raum' : 'Wert ' . $id, 'ObjectPosition' => 0, 'ObjectIsHidden' => false, 'ObjectIcon' => '']; }
function IPS_GetName(int $id): string { return IPS_GetObject($id)['ObjectName']; }
function IPS_GetVariable(int $id): array { global $types; return ['VariableType' => $types[$id], 'VariableCustomProfile' => '', 'VariableProfile' => '', 'VariableAction' => 0, 'VariableCustomAction' => 0]; }
function IPS_GetVariablePresentation(int $id): array { return []; }
function IPS_VariableProfileExists(string $profile): bool { return false; }
function GetValue(int $id): mixed { return [31 => false, 32 => 'Bereit'][$id] ?? 10; }
function GetValueFormatted(int $id): string { return (string) GetValue($id); }
function AC_GetLoggedValues(int $archive, int $id, int $start, int $end, int $limit): array {
global $calls, $dense; $calls[] = ['raw', $id, $start, $end, $limit];
$value = $id === 32 ? '=1+2' : ($id === 31 ? false : 21.5);
if ($limit === 1) return [['TimeStamp' => 900, 'Value' => $value, 'Duration' => 500]];
if ($dense) return array_fill(0, 10000, ['TimeStamp' => 1500, 'Value' => $value, 'Duration' => 0]);
return [['TimeStamp' => 1900, 'Value' => $id === 32 ? 'Fertig' : 0, 'Duration' => 100], ['TimeStamp' => 1300, 'Value' => $value, 'Duration' => 600]];
}
function AC_GetAggregatedValues(int $archive, int $id, int $level, int $start, int $end, int $limit): array {
global $calls; $calls[] = ['aggregated', $id, $level, $start, $end, $limit];
return [['TimeStamp' => $start + 60, 'Avg' => 2.5, 'Min' => 1, 'Max' => 4, 'Duration' => 60], ['TimeStamp' => $start, 'Avg' => 1.5, 'Min' => 0, 'Max' => 3, 'Duration' => 60]];
}
require __DIR__ . '/../NextFloor/module.php';
$module = new NextFloor();
$tree = (new ReflectionMethod($module, 'objectTree'))->invoke($module);
$states = array_column($tree['variables'], null, 'entity_id');
check($metadataQueries === 1, 'Query logging metadata in bulk, not per variable');
foreach ([30, 31, 32, 34] as $id) {
$state = array_values(array_filter($tree['variables'], fn($v) => $v['attributes']['symcon_id'] === $id))[0];
check($state['attributes']['symcon_archive']['id'] === 100, 'Logged values get trend metadata even with graph visibility off');
}
foreach ([33, 35] as $id) {
$state = array_values(array_filter($tree['variables'], fn($v) => $v['attributes']['symcon_id'] === $id))[0];
check(!isset($state['attributes']['symcon_archive']), 'Unlogged and disabled variables have no trend icon metadata');
}
$method = new ReflectionMethod($module, 'archiveTrend');
$request = ['entity_id' => 'sensor.30', 'start' => 1000, 'end' => 2000, 'aggregation' => 'raw'];
$result = $method->invoke($module, $request);
check(array_column($result['points'], 't') === [1000, 1300, 1900], 'Return chronological data and carry the state at the left boundary');
check($result['points'][2]['v'] === 0.0, 'Zero is a real archived value');
$epoch = $method->invoke($module, [...$request, 'start' => 1, 'end' => 10]);
check($epoch['points'] === [], 'Do not use native EndTime=0 (until now) as a previous value at the Unix epoch');
$boolean = $method->invoke($module, [...$request, 'entity_id' => 'light.31']);
check($boolean['points'][0]['v'] === 0.0 && $boolean['points'][1]['v'] === 0 && $boolean['type'] === 0, 'Boolean archives and actuator domains retain native zero');
$string = $method->invoke($module, [...$request, 'entity_id' => 'sensor.32', 'aggregation' => 'day']);
check($string['aggregation'] === 'raw' && $string['points'][0]['v'] === '=1+2', 'Strings use raw event records');
$counter = $method->invoke($module, [...$request, 'entity_id' => 'sensor.34', 'aggregation' => 'day']);
check($counter['counter'] && $counter['points'][1]['v'] === 2.5 && $counter['points'][1]['min'] === 1.0, 'Use native counter deltas and native min/max, without differentiating a counter twice');
check(end($calls)[2] === 1, 'Daily aggregation uses the native level 1');
$dense = true;
$auto = $method->invoke($module, [...$request, 'aggregation' => 'auto']);
check($auto['aggregation'] === 'minute' && !$auto['truncated'], 'Dense automatic raw data falls back to native minute aggregates');
$raw = $method->invoke($module, $request);
check($raw['truncated'] && count($raw['points']) === 10000, 'Explicit raw queries report the hard limit and avoid inventing a left boundary');
$dense = false;
foreach ([['start' => 2000], ['start' => 1.5], ['entity_id' => []], ['entity_id' => 'sensor.33'], ['entity_id' => 'sensor.35'], ['aggregation' => 'invalid'], ['start' => 1, 'end' => 1700000000, 'aggregation' => 'minute']] as $bad) {
$rejected = false;
try { $method->invoke($module, [...$request, ...$bad]); }
catch (InvalidArgumentException | RuntimeException) { $rejected = true; }
check($rejected, 'Reject invalid parameters');
}
echo "OK: bulk logging discovery, hidden graphs, raw/Boolean/string archives, carried values, counter aggregation, dense fallback, truncation and invalid request guards\n";
+1 -1
View File
@@ -59,7 +59,7 @@ export function validateSymconPackage(root = fileURLToPath(new URL("../", import
assert.match(php, new RegExp(`class\\s+${entry.name}\\s+extends\\s+IPSModuleStrict\\b`), "Module PHP class is missing or mismatched");
const form = readJson(join(directory, "form.json"));
assert.ok(Array.isArray(form.elements) && Array.isArray(form.actions), "Module form must contain elements and actions");
for (const asset of ["nextfloor-designer.js", "nextfloor-3d.js", "nextfloor-editor.js", "nextfloor-card-editor.js"]) {
for (const asset of ["nextfloor-designer.js", "nextfloor-3d.js", "nextfloor-editor.js", "nextfloor-card-editor.js", "nextfloor-trend.js"]) {
assert.ok(readFileSync(join(directory, "assets", asset)).length > 0, `Missing build asset: ${asset}`);
}
modules.push(module);