Skip to content

Commit

Permalink
Add repeat attribute on sequence entity
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Sep 5, 2024
1 parent 03d1574 commit c720a66
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
4 changes: 4 additions & 0 deletions custom_components/irrigation_unlimited/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
ATTR_FLOW_RATE,
ATTR_SEQUENCE_COUNT,
ATTR_ZONES,
ATTR_REPEAT,
)


Expand Down Expand Up @@ -329,6 +330,9 @@ def extra_state_attributes(self):
attr[ATTR_CURRENT_DURATION] = str(current.total_time)
attr[ATTR_TIME_REMAINING] = str(current.time_remaining)
attr[ATTR_PERCENT_COMPLETE] = current.percent_complete
attr[ATTR_REPEAT] = (
f"{current.current_zone.sequence_repeat + 1}/{self._sequence.repeat}"
)
if current.schedule is not None:
attr[ATTR_CURRENT_SCHEDULE] = current.schedule.id1
attr[ATTR_CURRENT_NAME] = current.schedule.name
Expand Down
1 change: 1 addition & 0 deletions custom_components/irrigation_unlimited/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
ATTR_CONTROLLERS = "controllers"
ATTR_SEQUENCES = "sequences"
ATTR_VERSION = "version"
ATTR_REPEAT = "repeat"

# Resources
RES_MANUAL = "Manual"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2843,6 +2843,11 @@ def active_zone(self) -> IUSequenceZoneRun:
if sequence is in a delay state"""
return self._active_zone

@property
def current_zone(self) -> IUSequenceZoneRun:
"""Return the current/running zone in the sequence"""
return self._current_zone

@property
def runs(self) -> dict[IURun, IUSequenceZoneRun]:
"""Return the runs"""
Expand Down
92 changes: 92 additions & 0 deletions tests/configs/test_sequence_repeat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
irrigation_unlimited:
refresh_interval: 10
controllers:
- name: "Test controller 1"
zones:
- name: "Zone 1"
- name: "Zone 2"
- name: "Zone 3"
- name: "Zone 4"
sequences:
- name: "Seq 1"
delay: "0:01:00"
repeat: 2
schedules:
- name: "Dawn"
time: "06:05"
zones:
- zone_id: 1
duration: "0:03:00"
repeat: 3
- zone_id: [2, 3]
duration: "0:06:00"
repeat: 2
- zone_id: 4
duration: "0:09:00"
testing:
enabled: true
speed: 1.0
output_events: false
show_log: false
autoplay: false
times:
- name: "1-Normal run"
start: "2024-09-05 06:00"
end: "2024-09-05 08:00"
results:
- {t: '2024-09-05 06:05:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:05:00', c: 1, z: 1, s: 1}
- {t: '2024-09-05 06:08:00', c: 1, z: 1, s: 0}
- {t: '2024-09-05 06:08:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 06:09:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:09:00', c: 1, z: 1, s: 1}
- {t: '2024-09-05 06:12:00', c: 1, z: 1, s: 0}
- {t: '2024-09-05 06:12:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 06:13:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:13:00', c: 1, z: 1, s: 1}
- {t: '2024-09-05 06:16:00', c: 1, z: 1, s: 0}
- {t: '2024-09-05 06:16:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 06:17:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:17:00', c: 1, z: 2, s: 1}
- {t: '2024-09-05 06:17:00', c: 1, z: 3, s: 1}
- {t: '2024-09-05 06:23:00', c: 1, z: 2, s: 0}
- {t: '2024-09-05 06:23:00', c: 1, z: 3, s: 0}
- {t: '2024-09-05 06:23:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 06:24:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:24:00', c: 1, z: 2, s: 1}
- {t: '2024-09-05 06:24:00', c: 1, z: 3, s: 1}
- {t: '2024-09-05 06:30:00', c: 1, z: 2, s: 0}
- {t: '2024-09-05 06:30:00', c: 1, z: 3, s: 0}
- {t: '2024-09-05 06:30:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 06:31:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:31:00', c: 1, z: 4, s: 1}
- {t: '2024-09-05 06:40:00', c: 1, z: 4, s: 0}
- {t: '2024-09-05 06:40:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 06:41:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:41:00', c: 1, z: 1, s: 1}
- {t: '2024-09-05 06:44:00', c: 1, z: 1, s: 0}
- {t: '2024-09-05 06:44:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 06:45:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:45:00', c: 1, z: 1, s: 1}
- {t: '2024-09-05 06:48:00', c: 1, z: 1, s: 0}
- {t: '2024-09-05 06:48:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 06:49:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:49:00', c: 1, z: 1, s: 1}
- {t: '2024-09-05 06:52:00', c: 1, z: 1, s: 0}
- {t: '2024-09-05 06:52:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 06:53:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:53:00', c: 1, z: 2, s: 1}
- {t: '2024-09-05 06:53:00', c: 1, z: 3, s: 1}
- {t: '2024-09-05 06:59:00', c: 1, z: 2, s: 0}
- {t: '2024-09-05 06:59:00', c: 1, z: 3, s: 0}
- {t: '2024-09-05 06:59:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 07:00:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 07:00:00', c: 1, z: 2, s: 1}
- {t: '2024-09-05 07:00:00', c: 1, z: 3, s: 1}
- {t: '2024-09-05 07:06:00', c: 1, z: 2, s: 0}
- {t: '2024-09-05 07:06:00', c: 1, z: 3, s: 0}
- {t: '2024-09-05 07:06:00', c: 1, z: 0, s: 0}
- {t: '2024-09-05 07:07:00', c: 1, z: 0, s: 1}
- {t: '2024-09-05 07:07:00', c: 1, z: 4, s: 1}
- {t: '2024-09-05 07:16:00', c: 1, z: 4, s: 0}
- {t: '2024-09-05 07:16:00', c: 1, z: 0, s: 0}
33 changes: 33 additions & 0 deletions tests/test_sequence_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,3 +1841,36 @@ async def test_sequence_run(hass: ha.HomeAssistant, skip_dependencies, skip_hist
await exam.finish_test()

exam.check_summary()


async def test_sequence_repeat(hass: ha.HomeAssistant, skip_dependencies, skip_history):
"""Test Sequence repeats."""
# pylint: disable=unused-argument
# pylint: disable=too-many-statements
async with IUExam(hass, "test_sequence_repeat.yaml") as exam:
await exam.begin_test(1)
await exam.run_until("2024-09-05 06:06")
exam.check_iu_entity(
"c1_s1",
STATE_ON,
{
"index": 0,
"time_remaining": "1:10:00",
"percent_complete": 1,
"repeat": "1/2",
},
)
await exam.run_until("2024-09-05 06:40:30")
exam.check_iu_entity(
"c1_s1",
STATE_ON,
{
"index": 0,
"time_remaining": "0:36:00",
"percent_complete": 49,
"repeat": "2/2",
},
)
await exam.finish_test()

exam.check_summary()

0 comments on commit c720a66

Please sign in to comment.