Add opt-in SDL measurement sources and independent visualization toggles. Exclude balancing power from household telemetry and new household energy. Preserve custom views and cover measurement, migration and Symcon 8.0 behavior.
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/** Minimal Symcon runtime, loaded only inside isolated ManagerSDLTest processes. */
|
||||
final class ManagerSDLRuntime
|
||||
{
|
||||
public static array $variables = [];
|
||||
public static array $children = [];
|
||||
public static array $properties = [];
|
||||
public static array $media = [];
|
||||
public static array $writes = [];
|
||||
public static array $hidden = [];
|
||||
private static int $nextID = 10000;
|
||||
|
||||
public static function reset(): void
|
||||
{
|
||||
self::$variables = [];
|
||||
self::$children = [];
|
||||
self::$properties = [];
|
||||
self::$media = [];
|
||||
self::$writes = [];
|
||||
self::$hidden = [];
|
||||
self::$nextID = 10000;
|
||||
}
|
||||
|
||||
public static function variable(int $id, $value, int $type = 2): int
|
||||
{
|
||||
self::$variables[$id] = ['VariableType' => $type, 'Value' => $value];
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function child(int $parent, string $ident, int $type = 2): int
|
||||
{
|
||||
if (!isset(self::$children[$parent][$ident])) {
|
||||
$id = self::$nextID++;
|
||||
self::$children[$parent][$ident] = $id;
|
||||
self::variable($id, $type === 3 ? '' : 0.0, $type);
|
||||
}
|
||||
|
||||
return self::$children[$parent][$ident];
|
||||
}
|
||||
}
|
||||
|
||||
class IPSModule
|
||||
{
|
||||
public int $InstanceID;
|
||||
public array $testProperties = [];
|
||||
public array $testAttributes = [];
|
||||
|
||||
public function __construct(int $instanceID)
|
||||
{
|
||||
$this->InstanceID = $instanceID;
|
||||
}
|
||||
|
||||
public function Create(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function __call(string $method, array $arguments)
|
||||
{
|
||||
if (preg_match('/^(Register|Read|Write)(Property|Attribute)(Boolean|Integer|Float|String)$/', $method, $parts)) {
|
||||
$storage = $parts[2] === 'Property' ? 'testProperties' : 'testAttributes';
|
||||
$ident = $arguments[0];
|
||||
if ($parts[1] === 'Register') {
|
||||
$this->{$storage}[$ident] = $this->{$storage}[$ident] ?? $arguments[1];
|
||||
|
||||
return null;
|
||||
}
|
||||
if ($parts[1] === 'Write') {
|
||||
$this->{$storage}[$ident] = $arguments[1];
|
||||
|
||||
return null;
|
||||
}
|
||||
if (!array_key_exists($ident, $this->{$storage})) {
|
||||
throw new RuntimeException('Unregistered test property or attribute: ' . $ident);
|
||||
}
|
||||
|
||||
return $this->{$storage}[$ident];
|
||||
}
|
||||
if (preg_match('/^RegisterVariable(Boolean|Integer|Float|String)$/', $method, $parts)) {
|
||||
$types = ['Boolean' => 0, 'Integer' => 1, 'Float' => 2, 'String' => 3];
|
||||
|
||||
return ManagerSDLRuntime::child($this->InstanceID, $arguments[0], $types[$parts[1]]);
|
||||
}
|
||||
|
||||
throw new BadMethodCallException('Unsupported Symcon test call: ' . $method);
|
||||
}
|
||||
|
||||
public function EnableAction(string $ident): void
|
||||
{
|
||||
}
|
||||
|
||||
public function RegisterTimer(string $ident, int $interval, string $script): void
|
||||
{
|
||||
}
|
||||
|
||||
public function GetIDForIdent(string $ident): int
|
||||
{
|
||||
if (!isset(ManagerSDLRuntime::$children[$this->InstanceID][$ident])) {
|
||||
throw new RuntimeException('Unknown test child: ' . $ident);
|
||||
}
|
||||
|
||||
return ManagerSDLRuntime::$children[$this->InstanceID][$ident];
|
||||
}
|
||||
|
||||
public function SetValue(string $ident, $value): void
|
||||
{
|
||||
ManagerSDLRuntime::$variables[$this->GetIDForIdent($ident)]['Value'] = $value;
|
||||
}
|
||||
|
||||
public function GetValue(string $ident)
|
||||
{
|
||||
return GetValue($this->GetIDForIdent($ident));
|
||||
}
|
||||
}
|
||||
|
||||
function IPS_VariableExists(int $variableID): bool
|
||||
{
|
||||
return isset(ManagerSDLRuntime::$variables[$variableID]);
|
||||
}
|
||||
|
||||
function IPS_GetVariable(int $variableID): array
|
||||
{
|
||||
if (!IPS_VariableExists($variableID)) {
|
||||
throw new RuntimeException('Unknown test variable: ' . $variableID);
|
||||
}
|
||||
|
||||
return ManagerSDLRuntime::$variables[$variableID];
|
||||
}
|
||||
|
||||
function GetValue(int $variableID)
|
||||
{
|
||||
return IPS_GetVariable($variableID)['Value'];
|
||||
}
|
||||
|
||||
function IPS_GetObjectIDByIdent(string $ident, int $parentID)
|
||||
{
|
||||
return ManagerSDLRuntime::$children[$parentID][$ident] ?? false;
|
||||
}
|
||||
|
||||
function IPS_GetProperty(int $instanceID, string $property)
|
||||
{
|
||||
return ManagerSDLRuntime::$properties[$instanceID][$property];
|
||||
}
|
||||
|
||||
function IPS_SetProperty(int $instanceID, string $property, $value): void
|
||||
{
|
||||
ManagerSDLRuntime::$properties[$instanceID][$property] = $value;
|
||||
ManagerSDLRuntime::$writes[] = ['property', $instanceID, $property];
|
||||
}
|
||||
|
||||
function IPS_ApplyChanges(int $instanceID): void
|
||||
{
|
||||
ManagerSDLRuntime::$writes[] = ['apply', $instanceID];
|
||||
}
|
||||
|
||||
function IPS_GetMediaContent(int $mediaID): string
|
||||
{
|
||||
return ManagerSDLRuntime::$media[$mediaID];
|
||||
}
|
||||
|
||||
function IPS_SetMediaContent(int $mediaID, string $content): void
|
||||
{
|
||||
ManagerSDLRuntime::$media[$mediaID] = $content;
|
||||
ManagerSDLRuntime::$writes[] = ['media', $mediaID];
|
||||
}
|
||||
|
||||
function IPS_SetHidden(int $objectID, bool $hidden): void
|
||||
{
|
||||
ManagerSDLRuntime::$hidden[$objectID] = $hidden;
|
||||
}
|
||||
Reference in New Issue
Block a user