From 68bd1647c0359f969df4c9595b4a1989d2dd3200 Mon Sep 17 00:00:00 2001 From: Laurens <43173895+GreenGrassBlueOcean@users.noreply.github.com> Date: Sun, 11 Oct 2026 12:21:41 +0200 Subject: [PATCH] fix(cen): remove redundant log re-assignment in OWNScenarioPlusCommand builders Address review feedback on PR #91 from @fedem95 and @GreenGrassBlueOcean: OWNScenarioPlusCommand.__init__ already initializes _human_readable_log to 'Scenario plus {self._where}: {self._action}.'. Re-assigning it in each builder (turn_on, turn_off, increase, decrease, stop) was redundant. Simplify builders to directly return cls(...), matching the pattern in OWNSceneCommand. Assert action, object, and human_readable_log on builder commands in tests/test_who25_scenario_plus.py. --- OWNd/message/cen.py | 20 +++++--------------- tests/test_who25_scenario_plus.py | 16 +++++++++++----- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/OWNd/message/cen.py b/OWNd/message/cen.py index 21e6afc..0c03a33 100644 --- a/OWNd/message/cen.py +++ b/OWNd/message/cen.py @@ -198,33 +198,23 @@ def action(self) -> str | None: @classmethod def turn_on(cls, where: str | int) -> OWNScenarioPlusCommand: - message = cls(f"*25*11#0*{where}##") - message._human_readable_log = f"Scenario plus {where}: on." - return message + return cls(f"*25*11#0*{where}##") @classmethod def turn_off(cls, where: str | int) -> OWNScenarioPlusCommand: - message = cls(f"*25*12*{where}##") - message._human_readable_log = f"Scenario plus {where}: off." - return message + return cls(f"*25*12*{where}##") @classmethod def increase(cls, where: str | int) -> OWNScenarioPlusCommand: - message = cls(f"*25*13#0#5*{where}##") - message._human_readable_log = f"Scenario plus {where}: increase." - return message + return cls(f"*25*13#0#5*{where}##") @classmethod def decrease(cls, where: str | int) -> OWNScenarioPlusCommand: - message = cls(f"*25*14#0#5*{where}##") - message._human_readable_log = f"Scenario plus {where}: decrease." - return message + return cls(f"*25*14#0#5*{where}##") @classmethod def stop(cls, where: str | int) -> OWNScenarioPlusCommand: - message = cls(f"*25*15*{where}##") - message._human_readable_log = f"Scenario plus {where}: stop." - return message + return cls(f"*25*15*{where}##") class OWNDryContactCommand(OWNCommand): diff --git a/tests/test_who25_scenario_plus.py b/tests/test_who25_scenario_plus.py index c20b57a..31ccd1b 100644 --- a/tests/test_who25_scenario_plus.py +++ b/tests/test_who25_scenario_plus.py @@ -7,11 +7,17 @@ def test_builders_send_the_ts10_frames(): - assert str(OWNScenarioPlusCommand.turn_on(11)) == "*25*11#0*11##" - assert str(OWNScenarioPlusCommand.turn_off(11)) == "*25*12*11##" - assert str(OWNScenarioPlusCommand.increase(11)) == "*25*13#0#5*11##" - assert str(OWNScenarioPlusCommand.decrease(11)) == "*25*14#0#5*11##" - assert str(OWNScenarioPlusCommand.stop(11)) == "*25*15*11##" + for cmd, action, expected_frame in [ + (OWNScenarioPlusCommand.turn_on(11), "on", "*25*11#0*11##"), + (OWNScenarioPlusCommand.turn_off(11), "off", "*25*12*11##"), + (OWNScenarioPlusCommand.increase(11), "increase", "*25*13#0#5*11##"), + (OWNScenarioPlusCommand.decrease(11), "decrease", "*25*14#0#5*11##"), + (OWNScenarioPlusCommand.stop(11), "stop", "*25*15*11##"), + ]: + assert str(cmd) == expected_frame + assert cmd.action == action + assert cmd.object == "11" + assert cmd.human_readable_log == f"Scenario plus 11: {action}." def test_commands_and_events_are_routed():