Skip to content

Commit

Permalink
Timeline information #173. Don't add history to running item
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Aug 14, 2024
1 parent 460701f commit c77da10
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 21 deletions.
3 changes: 0 additions & 3 deletions custom_components/irrigation_unlimited/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ def create_record(item: State, end: datetime) -> dict:
run_history.append(create_record(front_marker, item.last_changed))
front_marker = None

if front_marker is not None:
run_history.append(create_record(front_marker, stime))

return run_history

async def _async_update_history(self, stime: datetime) -> None:
Expand Down
306 changes: 288 additions & 18 deletions tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import OrderedDict, List, Any, NamedTuple
from homeassistant.const import (
STATE_OFF,
STATE_ON,
)
import homeassistant.core as ha
from homeassistant.util import dt
Expand Down Expand Up @@ -683,15 +684,6 @@ def service_history(entity_ids: set[str]) -> None:
("adjustment", ""),
]
),
OrderedDict(
[
("start", mk_utc("2021-06-04 04:29")),
("end", mk_utc("2021-06-04 04:32")),
("schedule", None),
("schedule_name", None),
("adjustment", ""),
]
),
],
"today_on": timedelta(seconds=1020),
},
Expand Down Expand Up @@ -742,15 +734,6 @@ def service_history(entity_ids: set[str]) -> None:
("adjustment", ""),
]
),
OrderedDict(
[
("start", mk_utc("2021-06-04 04:30")),
("end", mk_utc("2021-06-04 04:32")),
("schedule", None),
("schedule_name", None),
("adjustment", ""),
]
),
],
"today_on": timedelta(seconds=720),
},
Expand Down Expand Up @@ -896,6 +879,285 @@ async def test_history_live(hass: ha.HomeAssistant, allow_memory_db):
},
)

await exam.run_until("2024-07-16 06:08")
exam.check_iu_entity(
"c1_z1",
STATE_ON,
{
"current_schedule": 1,
"current_name": "Schedule 1",
"current_start": mk_local("2024-07-16 06:05:00"),
"current_duration": "0:06:00",
"time_remaining": "0:03:00",
"percent_complete": 50,
"next_schedule": 2,
"next_name": "Schedule 2",
"next_start": mk_local("2024-07-16 18:05:00"),
"next_duration": "0:06:00",
"today_total": 3.0,
"timeline": [
{
"start": mk_local("2024-07-18 18:05:00"),
"end": mk_local("2024-07-18 18:11:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"status": "scheduled",
},
{
"start": mk_local("2024-07-18 06:05:00"),
"end": mk_local("2024-07-18 06:11:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"status": "scheduled",
},
{
"start": mk_local("2024-07-17 18:05:00"),
"end": mk_local("2024-07-17 18:11:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-17 06:05:00"),
"end": mk_local("2024-07-17 06:11:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"status": "scheduled",
},
{
"start": mk_local("2024-07-16 18:05:00"),
"end": mk_local("2024-07-16 18:11:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"status": "next",
},
{
"start": mk_local("2024-07-16 06:05:00"),
"end": mk_local("2024-07-16 06:11:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"status": "running",
},
],
},
)
exam.check_iu_entity(
"c1_z2",
STATE_OFF,
{
"status": "off",
"current_schedule": None,
"percent_complete": 0,
"next_adjustment": "",
"next_schedule": 1,
"next_name": "Schedule 1",
"next_start": mk_local("2024-07-16 06:12:00"),
"next_duration": "0:12:00",
"today_total": 0.0,
"timeline": [
{
"start": mk_local("2024-07-18 18:12:00"),
"end": mk_local("2024-07-18 18:24:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-18 06:12:00"),
"end": mk_local("2024-07-18 06:24:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-17 18:12:00"),
"end": mk_local("2024-07-17 18:24:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-17 06:12:00"),
"end": mk_local("2024-07-17 06:24:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-16 18:12:00"),
"end": mk_local("2024-07-16 18:24:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-16 06:12:00"),
"end": mk_local("2024-07-16 06:24:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "next",
},
],
"volume": None,
"flow_rate": None,
"icon": "mdi:valve-closed",
"friendly_name": "Zone 2",
},
)
await exam.run_until("2024-07-16 06:18")
exam.check_iu_entity(
"c1_z1",
STATE_OFF,
{
"status": "off",
"current_schedule": None,
"percent_complete": 0,
"next_adjustment": "",
"next_schedule": 2,
"next_name": "Schedule 2",
"next_start": mk_local("2024-07-16 18:05:00"),
"next_duration": "0:06:00",
"today_total": 6.0,
"timeline": [
{
"start": mk_local("2024-07-18 18:05:00"),
"end": mk_local("2024-07-18 18:11:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-18 06:05:00"),
"end": mk_local("2024-07-18 06:11:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-17 18:05:00"),
"end": mk_local("2024-07-17 18:11:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-17 06:05:00"),
"end": mk_local("2024-07-17 06:11:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-16 18:05:00"),
"end": mk_local("2024-07-16 18:11:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "next",
},
{
"start": mk_local("2024-07-16 06:05:00"),
"end": mk_local("2024-07-16 06:11:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-16 06:05:00"),
"end": mk_local("2024-07-16 06:11:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "history",
},
],
},
)
exam.check_iu_entity(
"c1_z2",
STATE_ON,
{
"status": "on",
"current_schedule": 1,
"current_name": "Schedule 1",
"current_start": mk_local("2024-07-16 06:12:00"),
"current_duration": "0:12:00",
"time_remaining": "0:06:00",
"percent_complete": 50,
"next_schedule": 2,
"next_name": "Schedule 2",
"next_start": mk_local("2024-07-16 18:12:00"),
"next_duration": "0:12:00",
"today_total": 6.0,
"timeline": [
{
"start": mk_local("2024-07-18 18:12:00"),
"end": mk_local("2024-07-18 18:24:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-18 06:12:00"),
"end": mk_local("2024-07-18 06:24:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-17 18:12:00"),
"end": mk_local("2024-07-17 18:24:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-17 06:12:00"),
"end": mk_local("2024-07-17 06:24:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-16 18:12:00"),
"end": mk_local("2024-07-16 18:24:00"),
"schedule": 2,
"schedule_name": "Schedule 2",
"adjustment": "",
"status": "next",
},
{
"start": mk_local("2024-07-16 06:12:00"),
"end": mk_local("2024-07-16 06:24:00"),
"schedule": 1,
"schedule_name": "Schedule 1",
"adjustment": "",
"status": "running",
},
],
"volume": None,
"flow_rate": None,
"icon": "mdi:valve-open",
"friendly_name": "Zone 2",
},
)

await exam.run_until("2024-07-16 06:30")
exam.check_iu_entity(
"c1_z1",
Expand Down Expand Up @@ -1330,6 +1592,14 @@ async def test_history_live(hass: ha.HomeAssistant, allow_memory_db):
"adjustment": "",
"status": "scheduled",
},
{
"start": mk_local("2024-07-23 08:12:00"),
"end": mk_local("2024-07-23 08:24:00"),
"schedule": 0,
"schedule_name": "Manual",
"adjustment": "",
"status": "history",
},
],
},
)
Expand Down

0 comments on commit c77da10

Please sign in to comment.