Skip to content

Commit

Permalink
Eliminate artefacts from timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Aug 14, 2024
1 parent 208ba8c commit 1e8904c
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions tests/configs/service_sequence_pause_resume_notify.yaml
Original file line number Diff line number Diff line change
@@ -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}
130 changes: 129 additions & 1 deletion tests/test_service_sequence_pause_resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down

0 comments on commit 1e8904c

Please sign in to comment.