Skip to content

Commit

Permalink
Update next_watering script to account for move in attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr committed Jun 24, 2020
1 parent c031858 commit 3d4b1e0
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions python_scripts/bhyve_next_watering.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,41 @@
else:
hass.states.set(rain_delay_finishing_entity, None, rain_delay_finishing_attrs)

for timestamp in (zone.attributes.get('watering_program', []) or []):
watering_time = dt_util.parse_datetime(str(timestamp))
if watering_time > now and (delay_finishes_at is None or watering_time > delay_finishes_at):
next_watering = watering_time
break
for program_id in ['a', 'b', 'c', 'e']:
program = zone.attributes.get(f"program_{program_id}")
logger.info("program: %s", program)
if program is None or program.get("enabled", False) is False:
continue

if program.get("is_smart_program"):
for timestamp in program.get('watering_program', []):
watering_time = dt_util.parse_datetime(str(timestamp))
if watering_time > now and (delay_finishes_at is None or watering_time > delay_finishes_at):
next_watering = watering_time
break
else:
""" find the next manual watering time """
"""
Orbit day: `0` is Sunday, `1` is Monday
Python day: `0` is Monday, `2` is Tuesday
"""

"""
************
TODO
************
"""

logger.info("Checking manual program: %s", program)
configured_days = program.get("frequency", {}).get("days")
start_times = program.get("start_times")
if configured_days is None:
continue

# now_weekday = now.weekday()

# next_watering_day = (
# filter(lambda day: (day > now_weekday), configured_days)
# )[0]# else configured_days[0]

hass.states.set(next_watering_entity, next_watering, next_watering_attrs)

0 comments on commit 3d4b1e0

Please sign in to comment.