createVariable(2, 'Produktion', 1200.0); $feedInId = $test->createVariable(2, 'Einspeisung', 350.0); $gridId = $test->createVariable(2, 'Netzbezug', 180.0); $moduleId = $test->createInstance( '{F73B8F8D-5E36-4B23-B379-4632A517A1D6}', 'Energiediagramm', [ 'ProduktionZaehlerID' => $productionId, 'EinspeisungZaehlerID' => $feedInId, 'NetzbezugZaehlerID' => $gridId, 'Standardzeitraum' => 'month', 'FarbeEigenverbrauch' => '#1259A7', 'FarbeAutarkie' => '#178A55', ] ); $test->runCase('Instanz und Eigenschaften werden angelegt', static function ( TestContext $test ) use ($moduleId): void { $test->assertInstanceStatus($moduleId); $test->assertSame('month', IPS_GetProperty($moduleId, 'Standardzeitraum')); $test->assertSame('#1259A7', IPS_GetProperty($moduleId, 'FarbeEigenverbrauch')); $test->assertSame('#178A55', IPS_GetProperty($moduleId, 'FarbeAutarkie')); $test->assertSame('#121216', IPS_GetProperty($moduleId, 'FarbeHintergrund')); $test->assertSame('#63B3FF', IPS_GetProperty($moduleId, 'FarbeHintergrundAkzent1')); $test->assertSame('#A855F7', IPS_GetProperty($moduleId, 'FarbeHintergrundAkzent2')); $test->assertSame(0x1259A7, IPS_GetProperty($moduleId, 'FarbeEigenverbrauchRGB')); $test->assertSame(0x178A55, IPS_GetProperty($moduleId, 'FarbeAutarkieRGB')); $test->assertSame(0x121216, IPS_GetProperty($moduleId, 'FarbeHintergrundRGB')); $test->assertSame(0x63B3FF, IPS_GetProperty($moduleId, 'FarbeHintergrundAkzent1RGB')); $test->assertSame(0xA855F7, IPS_GetProperty($moduleId, 'FarbeHintergrundAkzent2RGB')); }); $test->runCase('Konfigurationsformular ist gültiges JSON', static function ( TestContext $test ) use ($moduleId): void { $form = json_decode( IPS_GetConfigurationForm($moduleId), true, 512, JSON_THROW_ON_ERROR ); $test->assertTrue(is_array($form)); }); $test->runCase('Zeitraum und Datumsbereich werden angenommen', static function ( TestContext $test ) use ($moduleId): void { IPS_RequestAction($moduleId, 'SetRange', 'year'); IPS_RequestAction( $moduleId, 'SetCustomRange', json_encode( ['start' => '2026-01-01', 'end' => '2026-01-31'], JSON_THROW_ON_ERROR ) ); IPS_RequestAction($moduleId, 'Refresh', true); $test->assertSame(102, (int) IPS_GetInstance($moduleId)['InstanceStatus']); }); $test->runCase('Hintergrundfarben akzeptieren Hex- und Symcon-8-Farbwerte', static function ( TestContext $test ) use ($moduleId): void { $colors = [ 'FarbeHintergrund' => '#FFFFFF', 'FarbeHintergrundAkzent1' => '0', 'FarbeHintergrundAkzent2' => '16777215', ]; $test->configureInstance($moduleId, $colors); $test->assertInstanceStatus($moduleId); foreach ($colors as $property => $color) { $test->assertSame($color, IPS_GetProperty($moduleId, $property)); } }); $test->runCase('Ungueltige Hintergrundfarben werden abgewiesen', static function ( TestContext $test ) use ($moduleId): void { foreach (['FarbeHintergrund', 'FarbeHintergrundAkzent1', 'FarbeHintergrundAkzent2'] as $property) { $original = IPS_GetProperty($moduleId, $property); try { $test->configureInstance($moduleId, [$property => 'not-a-color']); $test->assertInstanceStatus($moduleId, 201); } finally { $test->configureInstance($moduleId, [$property => $original]); } $test->assertInstanceStatus($moduleId); } }); $test->runCase('Jede Farbauswahl speichert nur die geaenderte Farbe', static function ( TestContext $test ) use ($moduleId): void { $properties = ['FarbeEigenverbrauch', 'FarbeAutarkie', 'FarbeHintergrund', 'FarbeHintergrundAkzent1', 'FarbeHintergrundAkzent2']; foreach ($properties as $index => $property) { $before = json_decode(IPS_GetConfiguration($moduleId), true, 512, JSON_THROW_ON_ERROR); $rgb = [0xABCDEF, 0x000001, 0, 0xFFFFFF, 0x12AB34][$index]; $test->configureInstance($moduleId, [$property . 'RGB' => $rgb]); $test->assertInstanceStatus($moduleId); foreach ($properties as $other) { $test->assertSame($other === $property ? $rgb : $before[$other . 'RGB'], IPS_GetProperty($moduleId, $other . 'RGB')); $test->assertSame($other === $property ? sprintf('#%06X', $rgb) : $before[$other], IPS_GetProperty($moduleId, $other)); } } $before = json_decode(IPS_GetConfiguration($moduleId), true, 512, JSON_THROW_ON_ERROR); $test->configureInstance($moduleId, ['Aktualisierungsintervall' => 120]); IPS_ApplyChanges($moduleId); foreach ($properties as $property) { $test->assertSame($before[$property], IPS_GetProperty($moduleId, $property)); $test->assertSame($before[$property . 'RGB'], IPS_GetProperty($moduleId, $property . 'RGB')); } }); $test->runCase('Alte Farbschnittstelle bleibt mit der Farbauswahl synchron', static function ( TestContext $test ) use ($moduleId): void { foreach (['#000001' => 1, '11259375' => 0xABCDEF, '0' => 0] as $legacy => $rgb) { $test->configureInstance($moduleId, ['FarbeHintergrund' => (string) $legacy]); $test->assertSame($rgb, IPS_GetProperty($moduleId, 'FarbeHintergrundRGB')); $test->assertSame((string) $legacy, IPS_GetProperty($moduleId, 'FarbeHintergrund')); } $test->configureInstance($moduleId, [ 'FarbeHintergrund' => '#123456', 'FarbeHintergrundRGB' => 0x987654, ]); $test->assertSame('#987654', IPS_GetProperty($moduleId, 'FarbeHintergrund')); $test->assertSame(0x987654, IPS_GetProperty($moduleId, 'FarbeHintergrundRGB')); }); $test->runCase('Ungueltige numerische Farbauswahl wird abgewiesen', static function ( TestContext $test ) use ($moduleId): void { foreach ([-1, 0x1000000] as $invalid) { $test->configureInstance($moduleId, ['FarbeHintergrundRGB' => $invalid]); $test->assertInstanceStatus($moduleId, 201); } $test->configureInstance($moduleId, ['FarbeHintergrundRGB' => 0x121216]); $test->assertInstanceStatus($moduleId); }); };