From d9dc61a7c2859909075bc4309e9833434d09a13b Mon Sep 17 00:00:00 2001 From: Laurens <43173895+GreenGrassBlueOcean@users.noreply.github.com> Date: Sun, 11 Oct 2026 13:47:35 +0200 Subject: [PATCH] test(energy): assert parsed properties on negative and empty auto-update intervals Follow-up to PR #102 review observation from @fedem95: - Exercise OWNEnergyEvent.__init__ parsing path with corrupted negative interval via monkeypatch - Assert update_interval, stream_duration, is_streaming_active, and human_readable_log - Add test_empty_interval_clamped_to_stopped to verify on-wire empty parameter fallback --- tests/test_who18_auto_update_reply.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/test_who18_auto_update_reply.py b/tests/test_who18_auto_update_reply.py index f61e211..6a18cec 100644 --- a/tests/test_who18_auto_update_reply.py +++ b/tests/test_who18_auto_update_reply.py @@ -75,12 +75,29 @@ def test_builder_duration_zero_or_negative(): assert "Stopping" in negative_clamped.human_readable_log -def test_negative_interval_clamped_to_stopped(): +def test_negative_interval_clamped_to_stopped(monkeypatch): + orig_init = OWNEvent.__init__ + + def fake_init(self, data): + orig_init(self, data) + self._dimension_value = ["-5"] + + monkeypatch.setattr(OWNEvent, "__init__", fake_init) event = OWNEnergyEvent("*#18*51*1200#1*0##") - # Simulate a corrupted non-standard negative value in _dimension_value - event._dimension_value = ["-5"] - parsed_interval = max(0, int(event._dimension_value[0])) - assert parsed_interval == 0 + + assert event.update_interval == 0 + assert event.stream_duration == 0 + assert event.is_streaming_active is False + assert event.human_readable_log == "Sensor 1 automatic updates stopped." + + +def test_empty_interval_clamped_to_stopped(): + event = OWNEvent.parse("*#18*51*1200#1*##") + assert isinstance(event, OWNEnergyEvent) + assert event.update_interval == 0 + assert event.stream_duration == 0 + assert event.is_streaming_active is False + assert event.human_readable_log == "Sensor 1 automatic updates stopped." def test_actuator_address_preserves_hash_zero():