feat(utils): adapt WAGO CC100 hardware module

This commit is contained in:
dh
2026-09-27 08:50:16 +00:00
parent db704dd011
commit 92eec804a7
15 changed files with 1407 additions and 26 deletions
+6
View File
@@ -3,6 +3,12 @@
declare(strict_types=1);
return [
'CC100Hardware' => [
'file' => __DIR__ . '/modules/CC100Hardware.php',
'paths' => [
'CC100Hardware/*',
],
],
'Energiediagramm' => [
'file' => __DIR__ . '/modules/Energiediagramm.php',
'paths' => [
+118
View File
@@ -0,0 +1,118 @@
<?php
declare(strict_types=1);
use Belevo\EnelixUtils\SymconTest\TestContext;
return static function (TestContext $test): void {
$temporaryFiles = [];
$createFile = static function (string $content) use (&$temporaryFiles): string {
$path = tempnam(sys_get_temp_dir(), 'enelix_cc100_');
if ($path === false || file_put_contents($path, $content) === false) {
throw new RuntimeException('Temporäre CC100-Testdatei konnte nicht erstellt werden.');
}
$temporaryFiles[] = $path;
return $path;
};
$digitalInput = $createFile('5');
$digitalOutput = $createFile('0');
$calibration = $createFile(
"PT1 PT2 AI1 AI2 A01 A02\n"
. "1000 1000 2000 1385.05\n"
. "1000 1000 2000 1385.05\n"
. "100 0 1100 10000\n"
. "100 0 1100 10000\n"
. "200 0 1200 10000\n"
. "200 0 1200 10000\n"
);
$ai1 = $createFile('600');
$ao1 = $createFile('700');
$ao1Power = $createFile('1');
$pt1 = $createFile('1000');
$channels = json_encode([
[
'Aktiv' => true,
'Typ' => 'DI',
'Kanal' => 1,
'Anzeigename' => 'Test Eingang',
'Abfrageintervall' => 1000,
],
[
'Aktiv' => true,
'Typ' => 'DO',
'Kanal' => 1,
'Anzeigename' => 'Test Ausgang',
'Abfrageintervall' => 1000,
],
[
'Aktiv' => true,
'Typ' => 'AI',
'Kanal' => 1,
'Anzeigename' => 'Test Spannung Eingang',
'Abfrageintervall' => 1000,
],
[
'Aktiv' => true,
'Typ' => 'AO',
'Kanal' => 1,
'Anzeigename' => 'Test Spannung Ausgang',
'Abfrageintervall' => 1000,
],
[
'Aktiv' => true,
'Typ' => 'PT',
'Kanal' => 1,
'Anzeigename' => 'Test Temperatur',
'Abfrageintervall' => 1000,
],
], JSON_THROW_ON_ERROR);
$moduleId = $test->createInstance(
'{D62EA550-68A5-48E2-BF31-1C721AA1BD4E}',
'CC100 Hardware',
[
'Kanalauswahl' => $channels,
'DigitalInputPath' => $digitalInput,
'DigitalOutputPath' => $digitalOutput,
'CalibrationPath' => $calibration,
'AI1Path' => $ai1,
'AO1ValuePath' => $ao1,
'AO1PowerPath' => $ao1Power,
'PT1Path' => $pt1,
]
);
$test->runCase('Nur ausgewaehlte Kanaele werden angelegt und gelesen', static function (
TestContext $test
) use ($moduleId): void {
$test->assertInstanceStatus($moduleId);
$test->assertSame(true, GetValue($test->objectByIdent('DI1', $moduleId)));
$test->assertSame(false, @IPS_GetObjectIDByIdent('DI2', $moduleId));
$test->assertEquals(5.0, (float) GetValue($test->objectByIdent('AI1', $moduleId)), 0.001);
$test->assertEquals(0.0, (float) GetValue($test->objectByIdent('PT1', $moduleId)), 0.1);
});
$test->runCase('Digitaler Ausgang erhaelt die anderen Bits', static function (
TestContext $test
) use ($moduleId, $digitalOutput): void {
file_put_contents($digitalOutput, '4');
IPS_RequestAction($moduleId, 'DO1', true);
$test->assertSame('5', trim((string) file_get_contents($digitalOutput)));
$test->assertSame(true, GetValue($test->objectByIdent('DO1', $moduleId)));
});
$test->runCase('Analoger Ausgang wird invers kalibriert geschrieben', static function (
TestContext $test
) use ($moduleId, $ao1, $ao1Power): void {
IPS_RequestAction($moduleId, 'AO1', 2.5);
$test->assertSame('0', trim((string) file_get_contents($ao1Power)));
$test->assertSame('450', trim((string) file_get_contents($ao1)));
$test->assertEquals(2.5, (float) GetValue($test->objectByIdent('AO1', $moduleId)), 0.001);
});
foreach ($temporaryFiles as $path) {
@unlink($path);
}
};