Skip to content

Commit

Permalink
Rework sequence muster and run queue; add repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed May 6, 2021
1 parent 889b6b2 commit 918cd01
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 151 deletions.
11 changes: 8 additions & 3 deletions custom_components/irrigation_unlimited/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
CONF_BEFORE,
CONF_ENTITY_ID,
CONF_NAME,
CONF_REPEAT,
CONF_WEEKDAY,
CONF_DELAY,
CONF_ID,
)
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.discovery import async_load_platform
Expand Down Expand Up @@ -136,9 +136,12 @@ def _list_is_not_empty(value):
SEQUENCE_ZONE_SCHEMA = vol.Schema(
{
vol.Required(CONF_ZONE_ID): cv.positive_int,
vol.Required(CONF_DURATION): cv.positive_time_period,
vol.Optional(CONF_DELAY): cv.positive_time_period,
vol.Optional(CONF_DURATION): cv.positive_time_period,
vol.Optional(CONF_REPEAT): cv.positive_int,
}
)

SEQUENCE_SCHEMA = vol.Schema(
{
vol.Required(CONF_SCHEDULES, default={}): vol.All(
Expand All @@ -147,8 +150,10 @@ def _list_is_not_empty(value):
vol.Required(CONF_ZONES, default={}): vol.All(
cv.ensure_list, [SEQUENCE_ZONE_SCHEMA], _list_is_not_empty
),
vol.Optional(CONF_DELAY): cv.positive_time_period,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_DELAY): cv.positive_time_period,
vol.Optional(CONF_DURATION): cv.positive_time_period,
vol.Optional(CONF_REPEAT): cv.positive_int,
}
)

Expand Down
22 changes: 10 additions & 12 deletions custom_components/irrigation_unlimited/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ def device_state_attributes(self):
attr["zones"] = ""
current = self._controller.runs.current_run
if current is not None:
if isinstance(current.parent, IUZone):
attr["current_zone"] = current.parent.index + 1
attr["current_name"] = current.parent.name
attr["current_zone"] = current.zone.index + 1
attr["current_name"] = current.zone.name
attr["current_start"] = dt.as_local(current.start_time)
attr["current_duration"] = str(current.duration)
attr["time_remaining"] = str(current.time_remaining)
Expand All @@ -157,9 +156,8 @@ def device_state_attributes(self):

next = self._controller.runs.next_run
if next is not None:
if isinstance(next.parent, IUZone):
attr["next_zone"] = next.parent.index + 1
attr["next_name"] = next.parent.name
attr["next_zone"] = next.zone.index + 1
attr["next_name"] = next.zone.name
attr["next_start"] = dt.as_local(next.start_time)
attr["next_duration"] = str(next.duration)
else:
Expand Down Expand Up @@ -217,9 +215,9 @@ def device_state_attributes(self):
attr["adjustment"] = self._zone.adjustment.as_string
current = self._zone.runs.current_run
if current is not None:
if isinstance(current.parent, IUSchedule):
attr["current_schedule"] = current.parent.index + 1
attr["current_name"] = current.parent.name
if current.schedule is not None:
attr["current_schedule"] = current.schedule.index + 1
attr["current_name"] = current.schedule.name
else:
attr["current_schedule"] = RES_MANUAL
attr["current_name"] = RES_MANUAL
Expand All @@ -233,9 +231,9 @@ def device_state_attributes(self):

next = self._zone.runs.next_run
if next is not None:
if isinstance(next.parent, IUSchedule):
attr["next_schedule"] = next.parent.index + 1
attr["next_name"] = next.parent.name
if next.schedule is not None:
attr["next_schedule"] = next.schedule.index + 1
attr["next_name"] = next.schedule.name
else:
attr["next_schedule"] = RES_MANUAL
attr["next_name"] = RES_MANUAL
Expand Down
Loading

0 comments on commit 918cd01

Please sign in to comment.