Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Recalculate the auto on/off time fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rccoleman committed Jan 24, 2021
1 parent 33396b7 commit 629ccf3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
24 changes: 8 additions & 16 deletions lmdirect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ async def set_auto_on_off_times(
state[self._get_key((day_of_week, OFF, HOUR))] = hour_off
state[self._get_key((day_of_week, OFF, MIN))] = minute_off

self.calculate_auto_sched_times(day_of_week)

self._call_callbacks(entity_type=TYPE_MAIN)

async def set_dose(self, key=None, pulses=None):
Expand All @@ -293,11 +295,8 @@ async def set_dose(self, key=None, pulses=None):
f"set_dose: Some parameters not specified {key=} {pulses=}"
)

if isinstance(pulses, str):
pulses = int(pulses)

if isinstance(key, str):
key = int(key)
isinstance(pulses, str) and (pulses := int(pulses))
isinstance(key, str) and (key := int(key))

"""Validate input."""
if not (1 <= pulses <= 1000 and 1 <= key <= 5):
Expand All @@ -320,8 +319,7 @@ async def set_dose_hot_water(self, seconds=None):
if seconds is None:
raise InvalidInput("set_dose_hot_water: Seconds not specified")

if isinstance(seconds, str):
seconds = int(seconds)
isinstance(seconds, str) and (seconds := int(seconds))

"""Validate input."""
if not (1 <= seconds <= 30):
Expand All @@ -346,9 +344,7 @@ async def set_prebrew_times(self, key=None, seconds_on=None, seconds_off=None):
)

seconds_on, seconds_off = [float(x) for x in [seconds_on, seconds_off]]

if isinstance(key, str):
key = int(key)
isinstance(key, str) and (key := int(key))

"""Validate input."""
if not (
Expand Down Expand Up @@ -386,9 +382,7 @@ async def set_coffee_temp(self, temp=None):
if temp is None:
raise InvalidInput("set_coffee__temp: Temperature not specified")

if isinstance(temp, str):
temp = float(temp)

isinstance(temp, str) and (temp := float(temp))
temp = round(temp, 1)

data = self._convert_to_ascii(int(temp * 10), size=2)
Expand All @@ -407,9 +401,7 @@ async def set_steam_temp(self, temp=None):
if temp is None:
raise InvalidInput("set_steam_temp: Temperature not specified")

if isinstance(temp, str):
temp = float(temp)

isinstance(temp, str) and (temp := float(temp))
temp = round(temp, 1)

data = self._convert_to_ascii(int(temp * 10), size=2)
Expand Down
35 changes: 19 additions & 16 deletions lmdirect/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,24 @@ async def process_data(self, plaintext):

return retval

def calculate_auto_sched_times(self, key):
time_on_key = self._get_key((key, ON, TIME))
hour_on_key = self._get_key((key, ON, HOUR))
min_on_key = self._get_key((key, ON, MIN))
time_off_key = self._get_key((key, OFF, TIME))
hour_off_key = self._get_key((key, OFF, HOUR))
min_off_key = self._get_key((key, OFF, MIN))

"""Set human-readable "on" time"""
self._current_status[
time_on_key
] = f"{'%02d' % self._current_status[hour_on_key]}:{'%02d' % self._current_status[min_on_key]}"

"""Set human-readable "off" time"""
self._current_status[
time_off_key
] = f"{'%02d' % self._current_status[hour_off_key]}:{'%02d' % self._current_status[min_off_key]}"

async def _populate_items(self, data, cur_msg):
def handle_cached_value(element, value):
"""See if we've stored a temporary value that may take a while to update on the machine"""
Expand Down Expand Up @@ -443,22 +461,7 @@ def handle_cached_value(element, value):
) # turn \xff into a solid block (heating element on)
)
elif key in AUTO_SCHED_MAP.values() and elem.index == CALCULATED_VALUE:
time_on_key = self._get_key((key, ON, TIME))
hour_on_key = self._get_key((key, ON, HOUR))
min_on_key = self._get_key((key, ON, MIN))
time_off_key = self._get_key((key, OFF, TIME))
hour_off_key = self._get_key((key, OFF, HOUR))
min_off_key = self._get_key((key, OFF, MIN))

"""Set human-readable "on" time"""
self._current_status[
time_on_key
] = f"{'%02d' % self._current_status[hour_on_key]}:{'%02d' % self._current_status[min_on_key]}"

"""Set human-readable "off" time"""
self._current_status[
time_off_key
] = f"{'%02d' % self._current_status[hour_off_key]}:{'%02d' % self._current_status[min_off_key]}"
self.calculate_auto_sched_times(key)
continue

self._current_status[key] = handle_cached_value(key, value)
Expand Down

0 comments on commit 629ccf3

Please sign in to comment.