From 89cf59ae965a6c019bf411f76890da907f931a9f Mon Sep 17 00:00:00 2001 From: Ed Leckert Date: Mon, 16 Oct 2023 14:23:46 -0600 Subject: [PATCH] add exception --- pyopensprinkler/program.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pyopensprinkler/program.py b/pyopensprinkler/program.py index 938d6a3..ff5be0c 100644 --- a/pyopensprinkler/program.py +++ b/pyopensprinkler/program.py @@ -226,7 +226,7 @@ async def set_start_time_type(self, value): async def set_program_start_time(self, start_index, start_time): """Set program start time with encoded value for start0, 1, 2, or 3""" if not 0 <= start_index <= 3: - raise ValueError("start_index must be 0 and 3") + raise IndexError("start_index must be between 0 and 3") dlist = self._get_program_data().copy() dlist[3][start_index] = start_time params = self._format_program_data(dlist) @@ -242,11 +242,11 @@ async def set_program_start_times(self, start_times): async def set_program_start_time_offset(self, start_index, start_time_offset): """Set program start time offset in minutes without chaning current offset type""" if not 0 <= start_index <= 3: - raise ValueError("start_index must be 0 and 3") + raise IndexError("start_index must be between 0 and 3") # Only start0 has offset if repeating type if start_index > 0 and self.start_time_type == 0: - raise ValueError( + raise RuntimeError( f"cannot update start{start_index} with minutes when start time type is 'repeating'" ) @@ -267,7 +267,13 @@ async def set_program_start_time_offset_type( ): """Set program start time offset type ('disabled', 'midnight', 'sunset', or 'sunrise'). Resets minutes to 0.""" if not 0 <= start_index <= 3: - raise ValueError("start_index must be 0 and 3") + raise IndexError("start_index must be between 0 and 3") + + # Only start0 has offset if repeating type + if start_index > 0 and self.start_time_type == 0: + raise RuntimeError( + f"cannot update start{start_index} offset type when start time type is 'repeating'" + ) valid_options = ["disabled", "midnight", "sunset", "sunrise"] if start_time_offset_type not in valid_options: @@ -422,7 +428,7 @@ def program_start_times(self): def get_program_start_time_offset(self, start_index): """Retrieve program start time offset in minutes""" if not 0 <= start_index <= 3: - raise ValueError("start_index must be 0 and 3") + raise IndexError("start_index must be between 0 and 3") start_times = self._get_variable(3) return self._get_offset_minutes(start_times, start_index) @@ -440,7 +446,7 @@ def program_start_time_offsets(self): def get_program_start_time_offset_type(self, start_index): """Retrieve program start time offset type ('midnight', 'sunset', or 'sunrise')""" if not 0 <= start_index <= 3: - raise ValueError("start_index must be 0 and 3") + raise IndexError("start_index must be between 0 and 3") start_times = self._get_variable(3) return self._get_offset_type(start_times, start_index)