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

+55 -1
View File
@@ -419,7 +419,9 @@ class NextFloor extends IPSModuleStrict
'icon' => (string) $object['ObjectIcon']
];
if ($type === 1) { // OBJECTTYPE_INSTANCE: the logical console view separates system modules.
$node['module_type'] = (int) IPS_GetInstance($objectID)['ModuleInfo']['ModuleType'];
$module = IPS_GetInstance($objectID)['ModuleInfo'];
$node['module_type'] = (int) $module['ModuleType'];
$node['module_id'] = (string) ($module['ModuleID'] ?? '');
}
if ($type === 0) { // OBJECTTYPE_CATEGORY
$nearestCategory = $objectID;
@@ -430,12 +432,41 @@ class NextFloor extends IPSModuleStrict
$variables[] = $variable;
$node['entity_id'] = $variable['entity_id'];
}
if ($type === 4 && function_exists('IPS_GetEvent')) {
$event = IPS_GetEvent($objectID);
if ((int) ($event['EventType'] ?? -1) === 2) {
$schedule = $this->describeSchedule($objectID, $name, implode(' / ', $path), $event);
$variables[] = $schedule;
$node['entity_id'] = $schedule['entity_id'];
}
}
$nodes[] = $node;
foreach (IPS_GetChildrenIDs($objectID) as $child) {
$this->collectObjects($child, $path, $nearestCategory, $variables, $areas, $nodes);
}
}
private function describeSchedule(int $eventID, string $name, string $path, array $event): array
{
// Export presentation only; action scripts and action parameters stay in Symcon.
$actions = array_map(static fn(array $action): array => [
'id' => (int) $action['ID'], 'name' => (string) $action['Name'], 'color' => (int) ($action['Color'] ?? 0)
], $event['ScheduleActions'] ?? []);
$groups = array_map(static fn(array $group): array => [
'id' => (int) $group['ID'], 'days' => (int) $group['Days'],
'points' => array_map(static fn(array $point): array => [
'id' => (int) $point['ID'], 'hour' => (int) $point['Start']['Hour'],
'minute' => (int) $point['Start']['Minute'], 'second' => (int) $point['Start']['Second'],
'action' => (int) $point['ActionID']
], $group['Points'] ?? [])
], $event['ScheduleGroups'] ?? []);
return ['entity_id' => 'schedule.' . $eventID, 'name' => $name, 'path' => $path,
'state' => ($event['EventActive'] ?? false) ? 'on' : 'off',
'attributes' => ['symcon_id' => $eventID, 'symcon_schedule' => true,
'groups' => $groups, 'actions' => $actions, 'next_run' => (int) ($event['NextRun'] ?? 0),
'next_action' => (int) ($event['NextActionID'] ?? 0), 'last_action' => (int) ($event['LastActionID'] ?? 0)]];
}
private function describeVariable(int $variableID, string $name, string $path, ?int $categoryID): array
{
$variable = IPS_GetVariable($variableID);
@@ -451,6 +482,7 @@ class NextFloor extends IPSModuleStrict
'symcon_variable_type' => (int) $variable['VariableType'],
'symcon_has_action' => ((int) ($variable['VariableCustomAction'] ?: $variable['VariableAction'])) !== 0,
'symcon_formatted' => GetValueFormatted($variableID),
'symcon_value' => $value,
'device_class' => $this->deviceClassFor($profile, $name, $unit)
];
if ($unit !== '') {
@@ -814,6 +846,14 @@ class NextFloor extends IPSModuleStrict
if (!is_string($entityID)) {
continue;
}
if ($domain === 'schedule' && $service === 'set_active') {
if (preg_match('/^schedule\.(\d+)$/', $entityID, $match) !== 1 || !IPS_EventExists((int) $match[1])
|| (int) IPS_GetEvent((int) $match[1])['EventType'] !== 2 || !is_bool($data['active'] ?? null)) {
throw new InvalidArgumentException('invalid_schedule');
}
if (!IPS_SetEventActive((int) $match[1], $data['active'])) throw new RuntimeException('schedule_update_failed');
continue;
}
$variableID = $this->variableIdForEntity($entityID);
if ($variableID === null || !IPS_VariableExists($variableID)) {
continue;
@@ -832,6 +872,20 @@ class NextFloor extends IPSModuleStrict
{
$variable = IPS_GetVariable($variableID);
$current = GetValue($variableID);
if ($domain === 'symcon' && $service === 'set_value') {
if ((int) ($variable['VariableCustomAction'] ?: $variable['VariableAction']) === 0) throw new InvalidArgumentException('variable_readonly');
$type = (int) $variable['VariableType'];
$value = $data['value'] ?? null;
if ($type === 0 && !is_bool($value)) throw new InvalidArgumentException('invalid_boolean');
if (in_array($type, [1, 2], true)) {
$meta = $this->variableMetadata($variableID, $variable);
if (!is_numeric($value) || !is_finite((float) $value) || (float) $value < $meta['min'] || (float) $value > $meta['max']
|| ($type === 1 && (float) $value !== floor((float) $value))) throw new InvalidArgumentException('invalid_value');
}
if ($type === 3 && !is_string($value)) throw new InvalidArgumentException('invalid_string');
$this->setVariable($variableID, $variable, $value);
return;
}
if ($domain === 'cover' && $service === 'stop_cover') {
throw new InvalidArgumentException('cover_stop_not_supported');
}