Skip to content

Commit

Permalink
Add schedule id to timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Jul 30, 2024
1 parent cc34d75 commit 74cbf0c
Show file tree
Hide file tree
Showing 5 changed files with 766 additions and 0 deletions.
1 change: 1 addition & 0 deletions custom_components/irrigation_unlimited/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
TIMELINE_STATUS = "status"
TIMELINE_START = "start"
TIMELINE_END = "end"
TIMELINE_SCHEDULE = "schedule"
TIMELINE_SCHEDULE_NAME = "schedule_name"
TIMELINE_ADJUSTMENT = "adjustment"

Expand Down
4 changes: 4 additions & 0 deletions custom_components/irrigation_unlimited/history.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""History access and caching. This module runs asynchronously collecting
and caching history data"""

from datetime import datetime, timedelta
from typing import Callable, OrderedDict, Any
from homeassistant.core import HomeAssistant, State, CALLBACK_TYPE
Expand All @@ -15,13 +16,15 @@
from .const import (
ATTR_CURRENT_ADJUSTMENT,
ATTR_CURRENT_NAME,
ATTR_CURRENT_SCHEDULE,
CONF_ENABLED,
CONF_HISTORY,
CONF_HISTORY_REFRESH,
CONF_HISTORY_SPAN,
CONF_REFRESH_INTERVAL,
CONF_SPAN,
TIMELINE_ADJUSTMENT,
TIMELINE_SCHEDULE,
TIMELINE_SCHEDULE_NAME,
TIMELINE_START,
TIMELINE_END,
Expand Down Expand Up @@ -166,6 +169,7 @@ def create_record(item: State, end: datetime) -> dict:
result = OrderedDict()
result[TIMELINE_START] = round_seconds_dt(item.last_changed)
result[TIMELINE_END] = round_seconds_dt(end)
result[TIMELINE_SCHEDULE] = item.attributes.get(ATTR_CURRENT_SCHEDULE)
result[TIMELINE_SCHEDULE_NAME] = item.attributes.get(ATTR_CURRENT_NAME)
result[TIMELINE_ADJUSTMENT] = item.attributes.get(
ATTR_CURRENT_ADJUSTMENT, ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
RES_TIMELINE_SCHEDULED,
TIMELINE_ADJUSTMENT,
TIMELINE_END,
TIMELINE_SCHEDULE,
TIMELINE_SCHEDULE_NAME,
TIMELINE_START,
MONTHS,
Expand Down Expand Up @@ -1530,6 +1531,7 @@ def as_dict(self) -> OrderedDict:
result = OrderedDict()
result[TIMELINE_START] = self._start_time
result[TIMELINE_END] = self._end_time
result[TIMELINE_SCHEDULE] = self.schedule.id1 if self.schedule else 0
result[TIMELINE_SCHEDULE_NAME] = self.schedule_name
result[TIMELINE_ADJUSTMENT] = self.adjustment
return result
Expand Down
53 changes: 53 additions & 0 deletions tests/configs/test_history_live.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
default_config:

irrigation_unlimited:
testing:
enabled: true
speed: 1.0
output_events: false
show_log: false
autoplay: false
times:
- name: "1-Sequence 1"
start: "2024-07-23 06:00"
end: "2024-07-23 07:00"
results:
- {t: '2024-07-23 06:05:00', c: 1, z: 0, s: 1}
- {t: '2024-07-23 06:05:00', c: 1, z: 1, s: 1}
- {t: '2024-07-23 06:11:00', c: 1, z: 1, s: 0}
- {t: '2024-07-23 06:11:00', c: 1, z: 0, s: 0}
- {t: '2024-07-23 06:12:00', c: 1, z: 0, s: 1}
- {t: '2024-07-23 06:12:00', c: 1, z: 2, s: 1}
- {t: '2024-07-23 06:24:00', c: 1, z: 2, s: 0}
- {t: '2024-07-23 06:24:00', c: 1, z: 0, s: 0}
- name: "2-Manual run"
start: "2024-07-23 08:00"
end: "2024-07-23 09:00"
results:
- {t: '2024-07-23 08:05:01', c: 1, z: 0, s: 1}
- {t: '2024-07-23 08:05:01', c: 1, z: 1, s: 1}
- {t: '2024-07-23 08:11:01', c: 1, z: 1, s: 0}
- {t: '2024-07-23 08:11:01', c: 1, z: 0, s: 0}
- {t: '2024-07-23 08:12:01', c: 1, z: 0, s: 1}
- {t: '2024-07-23 08:12:01', c: 1, z: 2, s: 1}
- {t: '2024-07-23 08:24:01', c: 1, z: 2, s: 0}
- {t: '2024-07-23 08:24:01', c: 1, z: 0, s: 0}
controllers:
- name: "Test controller 1"
all_zones_config:
show:
timeline: true
zones:
- name: "Zone 1"
- name: "Zone 2"
sequences:
- name: "Sequence 1"
delay: "0:01:00"
schedules:
- time: "06:05"
- time: "18:05"
zones:
- zone_id: 1
duration: "0:06:00"
- zone_id: 2
duration: "0:12:00"
Loading

0 comments on commit 74cbf0c

Please sign in to comment.