Skip to content

Commit

Permalink
Add volume limiting to sequence zones
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Dec 31, 2023
1 parent bc1ef53 commit 48e7d45
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion custom_components/irrigation_unlimited/irrigation_unlimited.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def sensor_state_change(event: HAEvent):
self._total_volume = value - self._start_volume

# Notifiy our trackers
for listener in self._listeners.values():
for listener in list(self._listeners.values()):
listener(
event.time_fired,
self._zone,
Expand Down Expand Up @@ -2357,6 +2357,7 @@ def __init__(
self._duration: timedelta = None
self._repeat: int = None
self._enabled: bool = True
self._volume: float = None
# Private variables
self._adjustment = IUAdjustment()
self._suspend_until: datetime = None
Expand Down Expand Up @@ -2386,6 +2387,11 @@ def repeat(self) -> int:
"""Returns the number of repeats for this sequence"""
return self._repeat

@property
def volume(self) -> float:
"""Return the volume limit for this sequence"""
return self._volume

@property
def is_enabled(self) -> bool:
"""Return true if this sequence_zone is enabled and not suspended"""
Expand Down Expand Up @@ -2471,6 +2477,7 @@ def build_zones() -> None:
self._duration = wash_td(config.get(CONF_DURATION))
self._repeat = config.get(CONF_REPEAT, 1)
self._enabled = config.get(CONF_ENABLED, self._enabled)
self._volume = config.get(CONF_VOLUME, self._volume)
build_zones()
return self

Expand Down Expand Up @@ -2881,6 +2888,12 @@ def _update_volume(
self._sequence.volume = sum(
sum(sta.values()) for sta in self._volume_stats.values()
)
if (limit := self._active_zone.sequence_zone.volume) is not None:
current_vol = sum(self._volume_stats[self._active_zone].values())
if current_vol >= limit:
self._coordinator.service_call(
SERVICE_SKIP, self._controller, None, self._sequence, {}
)

def update(self) -> bool:
"""Update the status of the sequence"""
Expand Down
1 change: 1 addition & 0 deletions custom_components/irrigation_unlimited/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def _parse_dd_mmm(value: str) -> date | None:
vol.Optional(CONF_DURATION): cv.positive_time_period,
vol.Optional(CONF_REPEAT): cv.positive_int,
vol.Optional(CONF_ENABLED): cv.boolean,
vol.Optional(CONF_VOLUME): cv.positive_float,
}
)

Expand Down

0 comments on commit 48e7d45

Please sign in to comment.