Tests / test (push) Successful in 1m1s
Approved by Daniel Haefliger for develop and beta. Author dh_Agent, authenticated account dh. Preserve published battery, charging and overall Energy Pie changes. No deployment or plant control authorization.
76 lines
3.1 KiB
PHP
76 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Belevo\EnelixEMS;
|
|
|
|
use LogicException;
|
|
|
|
/** Exactly two operator switches; legacy configuration is retained but not exposed. */
|
|
final class ManagerPrognoseFormular
|
|
{
|
|
/** Stable identifiers remain for archives and integrations; operation belongs in Forecast. */
|
|
public static function laufzeitAnzeige(): array
|
|
{
|
|
return [
|
|
'NetzfahrplanV4Aktivtest' => 'Netzfahrplansteuerung (Testbetrieb)',
|
|
'NetzfahrplanV4Vorschau' => 'Netzfahrplanvorschau (keine Stellfreigabe)',
|
|
'NetzfahrplanV4VorschauJSON' => 'Netzfahrplandiagnose',
|
|
'NetzfahrplanV4Datenstatus' => 'Prognosedaten und Modellversorgung',
|
|
];
|
|
}
|
|
|
|
public static function startErlaubt(array $zustand): bool
|
|
{
|
|
foreach (['prognoseAktiv', 'lizenziert', 'ready'] as $feld) {
|
|
if (($zustand[$feld] ?? false) !== true) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static function statustext(array $zustand): string
|
|
{
|
|
$states = ['disabled' => 'Aus', 'collecting' => 'Daten sammeln', 'learning' => 'Lernen',
|
|
'ready' => 'Bereit', 'active' => 'Aktiv', 'interrupted' => 'Unterbrochen'];
|
|
return ($states[$zustand['state'] ?? 'disabled'] ?? 'Status unbekannt') . ': '
|
|
. ($zustand['reason'] ?? 'Aktuellen Status abwarten.');
|
|
}
|
|
|
|
public static function integrieren(array $formular, array $zustand): array
|
|
{
|
|
$gefunden = false;
|
|
foreach ($formular['elements'] as &$element) {
|
|
if (($element['name'] ?? null) !== 'PrognoseForecast') {
|
|
continue;
|
|
}
|
|
if ($gefunden) {
|
|
throw new LogicException('Prognosebereich ist nicht eindeutig.');
|
|
}
|
|
$gefunden = true;
|
|
$element['items'] = [
|
|
['type' => 'CheckBox', 'name' => 'PrognoseAktiv',
|
|
'caption' => '1. Netzdaten senden und Prognosen lernen',
|
|
'onChange' => "IPS_RequestAction(\$id, 'FormPrognoseAktiv', \$PrognoseAktiv);"],
|
|
['type' => 'CheckBox', 'name' => 'NetzfahrplanRegelungAktiv',
|
|
'caption' => '2. Batterie nach Netzfahrplan regeln',
|
|
'enabled' => ($zustand['controlRequested'] ?? false) || self::startErlaubt($zustand)],
|
|
['type' => 'Label', 'name' => 'PrognoseNetzfahrplanStatus', 'caption' => self::statustext($zustand)],
|
|
['type' => 'Label', 'name' => 'PrognoseLizenzInformation',
|
|
'caption' => 'V4-Netzziel und Batteriekorrektur. Andere Verbraucher bleiben in der bisherigen Managerregelung.'],
|
|
];
|
|
$element['items'][] = [
|
|
'type' => 'Button', 'name' => 'PrognoseLizenzVerwalten',
|
|
'caption' => 'Prognose und Netzfahrplan im Lizenzportal verwalten', 'link' => true,
|
|
'onClick' => "echo 'https://license.enelix.ch';",
|
|
];
|
|
}
|
|
unset($element);
|
|
if (!$gefunden) {
|
|
throw new LogicException('Prognosebereich fehlt; Formular nicht erweitert.');
|
|
}
|
|
return $formular;
|
|
}
|
|
}
|