Skip to content

Commit

Permalink
Fix issue #190
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Nov 16, 2024
1 parent a14bbec commit df57640
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 5 deletions.
23 changes: 18 additions & 5 deletions custom_components/irrigation_unlimited/irrigation_unlimited.py
Original file line number Diff line number Diff line change
Expand Up @@ -2983,17 +2983,30 @@ def next_sequence_zone(
self, sequence_zone_run: IUSequenceZoneRun
) -> IUSequenceZoneRun:
"""Return the next sequence zone run in the run queue"""
result: IUSequenceZoneRun = None
found = False
for szr in self.runs.values():
if szr is None:
continue
if not found and szr == sequence_zone_run:
found = True
if found and szr.sequence_zone != sequence_zone_run.sequence_zone:
result = szr
break
return result
return szr
return None

def next_sequence_run(
self, sequence_zone_run: IUSequenceZoneRun
) -> IUSequenceZoneRun:
"""Return the next sequence run in the queue"""
found = False
for szr in self.runs.values():
if szr is None:
continue
if not found and szr == sequence_zone_run:
found = True
continue
if found:
return szr
return None

def sequence_zone_runs(self, sequence_zone_run: IUSequenceZoneRun) -> list[IURun]:
"""Return all the run associated with the sequence zone"""
Expand Down Expand Up @@ -3311,7 +3324,7 @@ def sumarise(stime: datetime) -> dict[IUSequenceZoneRun, dict]:
self,
)
else:
self._current_zone = self.next_sequence_zone(szr)
self._current_zone = self.next_sequence_run(szr)
result |= True

return result
Expand Down
32 changes: 32 additions & 0 deletions tests/configs/test_sequence_repeat_single.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
irrigation_unlimited:
controllers:
- name: "Controleur 1"
zones:
- name: Zone 1
sequences:
- name: jour
duration: "00:05"
delay: "00:01"
repeat: 2
schedules:
- time: "12:00"
zones:
- zone_id: 1
testing:
enabled: true
output_events: false
show_log: false
autoplay: false
times:
- name: "1-Normal run"
start: "2024-11-11 11:55"
end: "2024-11-11 12:30"
results:
- {t: '2024-11-11 12:00:00', c: 1, z: 0, s: 1}
- {t: '2024-11-11 12:00:00', c: 1, z: 1, s: 1}
- {t: '2024-11-11 12:05:00', c: 1, z: 1, s: 0}
- {t: '2024-11-11 12:05:00', c: 1, z: 0, s: 0}
- {t: '2024-11-11 12:06:00', c: 1, z: 0, s: 1}
- {t: '2024-11-11 12:06:00', c: 1, z: 1, s: 1}
- {t: '2024-11-11 12:11:00', c: 1, z: 1, s: 0}
- {t: '2024-11-11 12:11:00', c: 1, z: 0, s: 0}
35 changes: 35 additions & 0 deletions tests/test_sequence_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,3 +1874,38 @@ async def test_sequence_repeat(hass: ha.HomeAssistant, skip_dependencies, skip_h
await exam.finish_test()

exam.check_summary()


async def test_sequence_repeat_single(
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_single.yaml") as exam:
await exam.begin_test(1)
await exam.run_until("2024-11-11 12:02:00")
exam.check_iu_entity(
"c1_s1",
STATE_ON,
{
"index": 0,
"time_remaining": "0:09:00",
"percent_complete": 18,
"repeat": "1/2",
},
)
await exam.run_until("2024-11-11 12:09:00")
exam.check_iu_entity(
"c1_s1",
STATE_ON,
{
"index": 0,
"time_remaining": "0:02:00",
"percent_complete": 81,
"repeat": "2/2",
},
)
await exam.finish_test()

exam.check_summary()

0 comments on commit df57640

Please sign in to comment.