Skip to content

Commit

Permalink
add disabled type
Browse files Browse the repository at this point in the history
  • Loading branch information
EdLeckert committed Oct 15, 2023
1 parent aeaeea9 commit ccd04c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions pyopensprinkler/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
SCHEDULE_START_TIME_FIXED = "fixed_time"
SCHEDULE_START_TIME_REPEATING = "repeating"

SCHEDULE_START_TIME_OFFSET_DISABLED = "disabled"
SCHEDULE_START_TIME_OFFSET_MIDNIGHT = "midnight"
SCHEDULE_START_TIME_OFFSET_SUNSET = "sunset"
SCHEDULE_START_TIME_OFFSET_SUNRISE = "sunrise"
Expand Down
15 changes: 10 additions & 5 deletions pyopensprinkler/program.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Program module handling /program/ API calls."""

import json
from tkinter import OFF

from pyopensprinkler.const import (
SCHEDULE_START_TIME_FIXED,
SCHEDULE_START_TIME_OFFSET_DISABLED,
SCHEDULE_START_TIME_OFFSET_MIDNIGHT,
SCHEDULE_START_TIME_OFFSET_SUNRISE,
SCHEDULE_START_TIME_OFFSET_SUNSET,
Expand Down Expand Up @@ -92,7 +94,10 @@ def _get_offset_minutes(self, start_times, start_index):
def _encode_offset_minutes(self, offset_type, start_time_offset):
"""Encode start time with offset minutes, sign bit, and sunset/sunrise bit"""
new_sign_bit = 1 if start_time_offset < 0 else 0
if offset_type == SCHEDULE_START_TIME_OFFSET_SUNSET:

if offset_type == SCHEDULE_START_TIME_OFFSET_DISABLED:
return -1
elif offset_type == SCHEDULE_START_TIME_OFFSET_SUNSET:
return (
abs(int(start_time_offset))
| (new_sign_bit << START_TIME_SIGN_BIT)
Expand All @@ -114,8 +119,8 @@ def _get_offset_type(self, start_times, start_index):
self._is_set(start_times[start_index], START_TIME_SUNRISE_BIT)
)

if start_times[start_index] == -1: # disabled
return None
if start_times[start_index] == -1:
return SCHEDULE_START_TIME_OFFSET_DISABLED
# Only start0 has offset if repeating type
elif start_index > 0 and self.start_time_type == 0:
return None
Expand Down Expand Up @@ -256,11 +261,11 @@ async def set_program_start_time_offset(self, start_index, start_time_offset):
async def set_program_start_time_offset_type(
self, start_index, start_time_offset_type
):
"""Set program start time offset type ('midnight', 'sunset', or 'sunrise'). Resets minutes to 0."""
"""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")

valid_options = ["midnight", "sunset", "sunrise"]
valid_options = ["disabled", "midnight", "sunset", "sunrise"]
if start_time_offset_type not in valid_options:
raise ValueError(
"start_time_offset_type must be one of {}".format(valid_options)
Expand Down

0 comments on commit ccd04c6

Please sign in to comment.