From 1e8904ca064eb5465b499b0cf3db3498d40beed3 Mon Sep 17 00:00:00 2001 From: rgc99 Date: Wed, 14 Aug 2024 07:19:35 +0000 Subject: [PATCH] Eliminate artefacts from timeline --- .../irrigation_unlimited.py | 2 + .../service_sequence_pause_resume_notify.yaml | 42 ++++++ tests/test_service_sequence_pause_resume.py | 130 +++++++++++++++++- 3 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 tests/configs/service_sequence_pause_resume_notify.yaml diff --git a/custom_components/irrigation_unlimited/irrigation_unlimited.py b/custom_components/irrigation_unlimited/irrigation_unlimited.py index 1190b2d..49c0ac4 100644 --- a/custom_components/irrigation_unlimited/irrigation_unlimited.py +++ b/custom_components/irrigation_unlimited/irrigation_unlimited.py @@ -2315,6 +2315,8 @@ def timeline(self) -> list: run[TIMELINE_STATUS] = RES_TIMELINE_HISTORY for run in self._run_queue: + if run.duration == timedelta(0): + continue dct = run.as_dict() if run.running: dct[TIMELINE_STATUS] = RES_TIMELINE_RUNNING diff --git a/tests/configs/service_sequence_pause_resume_notify.yaml b/tests/configs/service_sequence_pause_resume_notify.yaml new file mode 100644 index 0000000..2507492 --- /dev/null +++ b/tests/configs/service_sequence_pause_resume_notify.yaml @@ -0,0 +1,42 @@ +irrigation_unlimited: + refresh_interval: 2000 + controllers: + - name: Test Controller + all_zones_config: + show: + timeline: true + zones: + - name: 'Zone 1' + - name: 'Zone 2' + sequences: + - name: "Seq 1" + duration: "0:04:00" + delay: "0:02:00" + schedules: + - time: "06:05" + zones: + - zone_id: 1 + - zone_id: 2 + testing: + enabled: true + speed: 1.0 + output_events: false + show_log: false + autoplay: false + times: + - name: '1-Normal run' + start: '2024-08-14 06:00' + end: '2024-08-14 07:00' + results: + - {t: '2024-08-14 06:05:00', c: 1, z: 0, s: 1} + - {t: '2024-08-14 06:05:00', c: 1, z: 1, s: 1} + - {t: '2024-08-14 06:07:00', c: 1, z: 1, s: 0} + - {t: '2024-08-14 06:07:00', c: 1, z: 0, s: 0} + - {t: '2024-08-14 06:12:00', c: 1, z: 0, s: 1} + - {t: '2024-08-14 06:12:00', c: 1, z: 1, s: 1} + - {t: '2024-08-14 06:14:00', c: 1, z: 1, s: 0} + - {t: '2024-08-14 06:14:00', c: 1, z: 0, s: 0} + - {t: '2024-08-14 06:16:00', c: 1, z: 0, s: 1} + - {t: '2024-08-14 06:16:00', c: 1, z: 2, s: 1} + - {t: '2024-08-14 06:20:00', c: 1, z: 2, s: 0} + - {t: '2024-08-14 06:20:00', c: 1, z: 0, s: 0} diff --git a/tests/test_service_sequence_pause_resume.py b/tests/test_service_sequence_pause_resume.py index 9514368..e41478c 100644 --- a/tests/test_service_sequence_pause_resume.py +++ b/tests/test_service_sequence_pause_resume.py @@ -4,13 +4,141 @@ from custom_components.irrigation_unlimited.const import ( SERVICE_PAUSE, SERVICE_RESUME, + DOMAIN, + EVENT_FINISH, + EVENT_START, ) -from tests.iu_test_support import IUExam +from tests.iu_test_support import IUExam, mk_local IUExam.quiet_mode() # pylint: disable=unused-argument +async def test_service_sequence_pause_resume_notify( + hass: ha.HomeAssistant, skip_dependencies, skip_history +): + """Test pause/resume service calls to sequence notifications""" + async with IUExam(hass, "service_sequence_pause_resume_notify.yaml") as exam: + event_data: list[ha.Event] = [] + + def handle_event(event: ha.Event): + nonlocal event_data + event_data.append( + { + "event_type": event.event_type, + "event_time": exam.virtual_time, + "data": event.data, + } + ) + + hass.bus.async_listen(f"{DOMAIN}_{EVENT_START}", handle_event) + hass.bus.async_listen(f"{DOMAIN}_{EVENT_FINISH}", handle_event) + + await exam.begin_test(1) + await exam.run_until("2024-08-14 06:07:00") + await exam.call( + SERVICE_PAUSE, + { + "entity_id": "binary_sensor.irrigation_unlimited_c1_s1", + }, + ) + exam.check_iu_entity( + "c1_z1", + "off", + { + "timeline": [ + { + "start": mk_local("2024-08-16 06:05:00"), + "end": mk_local("2024-08-16 06:09:00"), + "schedule": 1, + "schedule_name": "Schedule 1", + "adjustment": "", + "status": "scheduled", + }, + { + "start": mk_local("2024-08-15 06:05:00"), + "end": mk_local("2024-08-15 06:09:00"), + "schedule": 1, + "schedule_name": "Schedule 1", + "adjustment": "", + "status": "next", + }, + { + "start": mk_local("2024-08-14 06:07:00"), + "end": mk_local("2024-08-14 06:09:00"), + "schedule": 1, + "schedule_name": "Schedule 1", + "adjustment": "", + "status": "scheduled", + }, + ], + }, + ) + await exam.run_until("2024-08-14 06:12:00") + await exam.call( + SERVICE_RESUME, + { + "entity_id": "binary_sensor.irrigation_unlimited_c1_s1", + }, + ) + exam.check_iu_entity( + "c1_z1", + "on", + { + "timeline": [ + { + "start": mk_local("2024-08-16 06:05:00"), + "end": mk_local("2024-08-16 06:09:00"), + "schedule": 1, + "schedule_name": "Schedule 1", + "adjustment": "", + "status": "scheduled", + }, + { + "start": mk_local("2024-08-15 06:05:00"), + "end": mk_local("2024-08-15 06:09:00"), + "schedule": 1, + "schedule_name": "Schedule 1", + "adjustment": "", + "status": "next", + }, + { + "start": mk_local("2024-08-14 06:12:00"), + "end": mk_local("2024-08-14 06:14:00"), + "schedule": 1, + "schedule_name": "Schedule 1", + "adjustment": "", + "status": "running", + }, + ], + }, + ) + await exam.finish_test() + assert event_data == [ + { + "event_type": "irrigation_unlimited_start", + "event_time": mk_local("2024-08-14 06:05"), + "data": { + "controller": {"index": 0, "name": "Test Controller"}, + "sequence": {"index": 0, "name": "Seq 1"}, + "run": {"duration": 600}, + "schedule": {"index": 0, "name": "Schedule 1"}, + }, + }, + { + "event_type": "irrigation_unlimited_finish", + "event_time": mk_local("2024-08-14 06:20"), + "data": { + "controller": {"index": 0, "name": "Test Controller"}, + "sequence": {"index": 0, "name": "Seq 1"}, + "run": {"duration": 900}, + "schedule": {"index": 0, "name": "Schedule 1"}, + }, + }, + ] + exam.check_summary() + + async def test_service_sequence_pause_resume_multi( hass: ha.HomeAssistant, skip_dependencies, skip_history ):