Skip to content

Commit 02a08a2

Browse files
committed
Fix enable_phase_switching_on_host_only config
- type seems mandatory for @DataClass - added more tests
1 parent 273c7ec commit 02a08a2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pvcontrol/chargecontroller.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ class ChargeControllerData(BaseData):
5454
class ChargeControllerConfig(BaseConfig):
5555
cycle_time: int = 30 # [s] control loop cycle time, used by scheduler
5656
enable_phase_switching: bool = True # set to False of phase relay is not in operation
57-
enable_phase_switching_on_host_only = "" # if set, phase switching is only allowed when running on specified host (env var: HOSTNAME)
57+
enable_phase_switching_on_host_only: str = (
58+
"" # if set, phase switching is only allowed when running on specified host (env var: HOSTNAME)
59+
)
5860
enable_auto_phase_switching: bool = True # automatic phase switching depending on available PV
5961
enable_charging_when_connecting_car: ChargeMode = ChargeMode.OFF
6062
line_voltage: float = 230 # [V]

tests/test_chargecontroller.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,29 @@ def test_1P(self):
296296
self.assertEqual(1, self.wallbox.get_data().phases_in)
297297

298298

299+
class ChargeControllerDisabledPhaseSwitchingHostnameTest(unittest.TestCase):
300+
def setUp(self) -> None:
301+
self.wallbox = SimulatedWallbox(WallboxConfig())
302+
self.meter = TestMeter(self.wallbox)
303+
reset_controller_metrics()
304+
305+
def test_matching_hostname(self):
306+
self.controller = ChargeController(
307+
ChargeControllerConfig(enable_phase_switching_on_host_only="pi1"), self.meter, self.wallbox, "pi1"
308+
)
309+
self.assertTrue(self.controller._enable_phase_switching)
310+
self.controller.run() # init
311+
self.assertEqual(PhaseMode.AUTO, self.controller.get_data().phase_mode)
312+
313+
def test_wrong_hostname(self):
314+
self.controller = ChargeController(
315+
ChargeControllerConfig(enable_phase_switching_on_host_only="pi1"), self.meter, self.wallbox, "pi2"
316+
)
317+
self.assertFalse(self.controller._enable_phase_switching)
318+
self.controller.run() # init
319+
self.assertEqual(PhaseMode.DISABLED, self.controller.get_data().phase_mode)
320+
321+
299322
class ChargeControllerManualModeTest(unittest.TestCase):
300323
def setUp(self) -> None:
301324
self.wallbox = SimulatedWallbox(WallboxConfig())

0 commit comments

Comments
 (0)