Tests / test (push) Waiting to run
Do not latch full on transient zero current; require explicit completion. Validate go-e errors and Pico status/timestamps, keep historical events diagnostic, and preserve faults until a fresh successful poll. Budget the 6 A phase probe through the manager and correct stale phase counts conservatively. Add adapter, regulator, isolated runtime and Symcon regression cases plus migration documentation. Verified: composer check (402 tests, 1875 assertions), 92 pure-function assertions in Symcon 8.0, git diff --check. No plant deployment or hardware commands.
215 lines
8.4 KiB
PHP
215 lines
8.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Belevo\EnelixEMS\Tests;
|
|
|
|
use Belevo\EnelixEMS\LadestationRegler;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class LadestationReglerTest extends TestCase
|
|
{
|
|
public function testPhasenprobeUnterscheidetBeiMindeststromOhneMaximalstromsprung(): void
|
|
{
|
|
self::assertSame(
|
|
LadestationRegler::PHASEN_EIN,
|
|
LadestationRegler::erkennePhasenzahlAusLeistung(1380.0, 6)
|
|
);
|
|
self::assertSame(
|
|
LadestationRegler::PHASEN_DREI,
|
|
LadestationRegler::erkennePhasenzahlAusLeistung(4104.0, 6)
|
|
);
|
|
}
|
|
|
|
public function testPhasenprobeWeistUngueltigenErkennungsstromAb(): void
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
LadestationRegler::erkennePhasenzahlAusLeistung(4104.0, 5);
|
|
}
|
|
|
|
public function testFahrzeugUndDreiPhasenWerdenWieInEnelixEinsErkannt(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2,
|
|
'Istleistung_W' => 11000.0,
|
|
], false);
|
|
|
|
self::assertTrue($status['FahrzeugVerbunden']);
|
|
self::assertFalse($status['FahrzeugGeladen']);
|
|
self::assertSame(3, $status['Fahrzeugstatus']);
|
|
self::assertSame(LadestationRegler::PHASEN_DREI, $status['Phasenzahl']);
|
|
}
|
|
|
|
public function testDirektGemeldeteEinphasigkeitWirdAuchUnter7500WErkannt(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2,
|
|
'Istleistung_W' => 2300.0,
|
|
'Phasenzahl' => 1,
|
|
], false);
|
|
|
|
self::assertSame(LadestationRegler::PHASEN_EIN, $status['Phasenzahl']);
|
|
self::assertEqualsWithDelta(10.0, $status['Ladestrom_A'], 0.01);
|
|
}
|
|
|
|
public function testErkannteDreiphasigkeitBleibtWaehrendLadepauseErhalten(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2,
|
|
'Istleistung_W' => 0.0,
|
|
], true, false, false, true, LadestationRegler::PHASEN_DREI);
|
|
|
|
self::assertSame(LadestationRegler::PHASEN_DREI, $status['Phasenzahl']);
|
|
self::assertSame(0.0, $status['Ladestrom_A']);
|
|
}
|
|
|
|
public function testPhasenBleibenOhneMessungBisZurErkennungUnbekannt(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2,
|
|
'Istleistung_W' => 0.0,
|
|
], false);
|
|
|
|
self::assertSame(LadestationRegler::PHASEN_UNBEKANNT, $status['Phasenzahl']);
|
|
self::assertSame([0, 4104], LadestationRegler::leistungsangebot(
|
|
true,
|
|
true,
|
|
true,
|
|
false,
|
|
LadestationRegler::PHASEN_UNBEKANNT,
|
|
16,
|
|
true,
|
|
false
|
|
));
|
|
}
|
|
|
|
public function testAnlaufOhneGemesseneLadeleistungGiltNichtAlsLadeende(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2,
|
|
'Istleistung_W' => 0.0,
|
|
], true, false, true, false);
|
|
|
|
self::assertFalse($status['FahrzeugGeladen']);
|
|
self::assertSame(2, $status['Fahrzeugstatus']);
|
|
}
|
|
|
|
public function testNiedrigstromNachLadungIstKeinBestaetigtesLadeende(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2,
|
|
'Istleistung_W' => 0.0,
|
|
], true, false, true, true);
|
|
|
|
self::assertFalse($status['FahrzeugGeladen']);
|
|
self::assertSame(2, $status['Fahrzeugstatus']);
|
|
}
|
|
|
|
public function testAbsichtlichGestoppteLadungWirdNichtAlsGeladenErkannt(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2,
|
|
'Istleistung_W' => 0.0,
|
|
], true, false, false);
|
|
|
|
self::assertFalse($status['FahrzeugGeladen']);
|
|
self::assertSame(2, $status['Fahrzeugstatus']);
|
|
}
|
|
|
|
public function testAltesLadeendeOhneAktuelleBestaetigungWirdVerworfen(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2,
|
|
'Istleistung_W' => 0.0,
|
|
], true, true, false);
|
|
|
|
self::assertFalse($status['FahrzeugGeladen']);
|
|
self::assertSame(2, $status['Fahrzeugstatus']);
|
|
}
|
|
|
|
public function testExplizitesLadeendeWirdBeiErneuterLadungZurueckgenommen(): void
|
|
{
|
|
$ende = ['Rohstatus' => 4, 'Istleistung_W' => 0.0, 'LadeendeBestaetigt' => true];
|
|
self::assertTrue(LadestationRegler::normalisiereStatus($ende, true)['FahrzeugGeladen']);
|
|
$ende['Istleistung_W'] = 1380.0;
|
|
self::assertFalse(LadestationRegler::normalisiereStatus($ende, true, true)['FahrzeugGeladen']);
|
|
$ende['Rohstatus'] = 1;
|
|
$ende['Istleistung_W'] = 0.0;
|
|
self::assertFalse(LadestationRegler::normalisiereStatus($ende, true, true)['FahrzeugGeladen']);
|
|
}
|
|
|
|
public function testFrischePhasenmessungKorrigiertGespeicherteEinphasigkeit(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2, 'Istleistung_W' => 4104.0, 'Iststrom_A' => 6.0, 'Phasenzahl' => 3,
|
|
], true, false, true, true, 1);
|
|
self::assertSame(3, $status['Phasenzahl']);
|
|
}
|
|
|
|
public function testNullUndSchwacheLeistungBeweisenKeinePhase(): void
|
|
{
|
|
foreach ([0.0, 100.0, 800.0, 1264.0] as $leistung) {
|
|
self::assertSame(0, LadestationRegler::erkennePhasenzahlAusLeistung($leistung, 6));
|
|
}
|
|
}
|
|
|
|
public function testEinzelneAktivePhaseVerkleinertKeinBestaetigtesDreiphasenbudget(): void
|
|
{
|
|
$rohstatus = ['Rohstatus' => 2, 'Istleistung_W' => 1380.0, 'Phasenzahl' => 1];
|
|
self::assertSame(3, LadestationRegler::normalisiereStatus($rohstatus, true, false, true, true, 3)['Phasenzahl']);
|
|
self::assertSame(1, LadestationRegler::normalisiereStatus($rohstatus, false, false, true, true, 3)['Phasenzahl']);
|
|
$rohstatus['Istleistung_W'] = 11000.0;
|
|
self::assertSame(3, LadestationRegler::normalisiereStatus($rohstatus, false)['Phasenzahl']);
|
|
}
|
|
|
|
public function testUnbekanntePhasenHabenNurKonservativesStartbudget(): void
|
|
{
|
|
self::assertSame([0], LadestationRegler::leistungsangebot(true, true, true, false, 0, 16, true, true));
|
|
self::assertSame([0, 4104], LadestationRegler::leistungsangebot(true, true, true, false, 0, 16, false, true));
|
|
self::assertSame([0], LadestationRegler::leistungsangebot(false, true, true, false, 0, 16, false, false));
|
|
self::assertSame([0], LadestationRegler::leistungsangebot(true, false, true, false, 0, 16, false, false));
|
|
self::assertSame(0, LadestationRegler::stromFuerLeistung(4103, 0));
|
|
self::assertSame(6, LadestationRegler::stromFuerLeistung(4104, 0));
|
|
self::assertSame(6, LadestationRegler::stromFuerLeistung(22000, 0));
|
|
}
|
|
|
|
public function testDirekterPhasenstromHatVorrangVorNominalerLeistungsumrechnung(): void
|
|
{
|
|
$status = LadestationRegler::normalisiereStatus([
|
|
'Rohstatus' => 2,
|
|
'Istleistung_W' => 10263.0,
|
|
'Iststrom_A' => 15.9,
|
|
], true);
|
|
|
|
self::assertEqualsWithDelta(15.9, $status['Ladestrom_A'], 0.01);
|
|
}
|
|
|
|
public function testFahrzeugMaximalstromWirdMitZweiAmpereAbstandErkannt(): void
|
|
{
|
|
self::assertSame(18, LadestationRegler::ermittleFahrzeugMaximalstrom(20, 15.9, 20));
|
|
self::assertNull(LadestationRegler::ermittleFahrzeugMaximalstrom(17, 15.9, 20));
|
|
self::assertNull(LadestationRegler::ermittleFahrzeugMaximalstrom(20, 0.0, 20));
|
|
}
|
|
|
|
public function testBetriebsartUndSolarladenBestimmenDasLeistungsangebot(): void
|
|
{
|
|
$solarPV = LadestationRegler::leistungsangebot(true, true, true, false, 1, 16, true, false);
|
|
$normalPV = LadestationRegler::leistungsangebot(true, true, true, false, 1, 16, false, false);
|
|
$solarPeak = LadestationRegler::leistungsangebot(true, true, true, false, 1, 16, true, true);
|
|
$normalPeak = LadestationRegler::leistungsangebot(true, true, true, false, 1, 16, false, true);
|
|
|
|
self::assertSame(0, $solarPV[0]);
|
|
self::assertCount(12, $solarPV);
|
|
self::assertSame([3680], $normalPV);
|
|
self::assertSame([0], $solarPeak);
|
|
self::assertSame($solarPV, $normalPeak);
|
|
}
|
|
|
|
public function testPeakKannJedesFahrzeugAufNullSetzen(): void
|
|
{
|
|
self::assertSame(0, LadestationRegler::stromFuerLeistung(0, 3));
|
|
self::assertSame(6, LadestationRegler::stromFuerLeistung(4104, 3));
|
|
self::assertSame(16, LadestationRegler::stromFuerLeistung(10944, 3));
|
|
}
|
|
}
|