Skip to content

Commit

Permalink
Fix granularity
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Mar 16, 2021
1 parent 35c15db commit c00c6a4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions custom_components/irrigation_unlimited/irrigation_unlimited.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,35 @@ def granularity_time() -> timedelta:
return timedelta(seconds=SYSTEM_GRANULARITY)


def wash_td(delta: timedelta, granularity=SYSTEM_GRANULARITY) -> timedelta:
def wash_td(delta: timedelta, granularity: int = None) -> timedelta:
"""Truncate the supplied timedelta to internal boundaries"""
if delta is not None:
if granularity is None:
granularity = SYSTEM_GRANULARITY
whole_seconds = int(delta.total_seconds())
rounded_seconds = int(whole_seconds / granularity) * granularity
return timedelta(seconds=rounded_seconds)
else:
return None


def wash_dt(date: datetime, granularity=SYSTEM_GRANULARITY) -> datetime:
def wash_dt(date: datetime, granularity: int = None) -> datetime:
"""Truncate the supplied datetime to internal boundaries"""
if date is not None:
if granularity is None:
granularity = SYSTEM_GRANULARITY
rounded_seconds = int(date.second / granularity) * granularity
d = date.replace(second=rounded_seconds, microsecond=0)
return d
else:
return None


def wash_t(time: time, granularity=SYSTEM_GRANULARITY) -> time:
def wash_t(time: time, granularity: int = None) -> time:
"""Truncate the supplied time to internal boundaries"""
if time is not None:
if granularity is None:
granularity = SYSTEM_GRANULARITY
utc = dt.utcnow()
d = utc.combine(utc.date(), time)
rounded_seconds = int(d.second / granularity) * granularity
Expand Down Expand Up @@ -1492,7 +1498,7 @@ def write_status_to_log(time: datetime, controller: IUController, zone: IUZone)
status = f"{STATE_ON if controller._is_on else STATE_OFF}"
_LOGGER.debug(
"[%s] Controller %d %s is %s",
datetime.strftime(dt.as_local(time), "%Y-%m-%d %H:%M"),
datetime.strftime(dt.as_local(time), "%Y-%m-%d %H:%M:%S"),
controller._controller_index + 1,
zm,
status,
Expand Down

0 comments on commit c00c6a4

Please sign in to comment.