feat(energy-pie): finish configurable colors and Symcon 8 migration
Tests / test (push) Waiting to run
Tests / test (push) Waiting to run
This commit is contained in:
@@ -29,6 +29,14 @@ return static function (TestContext $test): void {
|
||||
$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 (
|
||||
@@ -58,4 +66,86 @@ return static function (TestContext $test): void {
|
||||
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);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user