diff --git a/custom_components/irrigation_unlimited/irrigation_unlimited.py b/custom_components/irrigation_unlimited/irrigation_unlimited.py index 49b70f0..b4bddb1 100644 --- a/custom_components/irrigation_unlimited/irrigation_unlimited.py +++ b/custom_components/irrigation_unlimited/irrigation_unlimited.py @@ -2983,7 +2983,6 @@ 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: @@ -2991,9 +2990,23 @@ def next_sequence_zone( 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""" @@ -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 diff --git a/tests/configs/test_sequence_repeat_single.yaml b/tests/configs/test_sequence_repeat_single.yaml new file mode 100644 index 0000000..7acd0f4 --- /dev/null +++ b/tests/configs/test_sequence_repeat_single.yaml @@ -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} diff --git a/tests/test_sequence_entity.py b/tests/test_sequence_entity.py index d920f99..602c1c8 100644 --- a/tests/test_sequence_entity.py +++ b/tests/test_sequence_entity.py @@ -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()