Skip to content

Commit

Permalink
add exception
Browse files Browse the repository at this point in the history
  • Loading branch information
EdLeckert committed Oct 16, 2023
1 parent 95fd258 commit 89cf59a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pyopensprinkler/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'"
)

Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 89cf59a

Please sign in to comment.