Skip to content

Commit

Permalink
Merge pull request #1623
Browse files Browse the repository at this point in the history
Support Multiple Input Constraints
  • Loading branch information
acockburn authored Feb 19, 2023
2 parents 1f8132d + 146ce03 commit c8fd62d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
30 changes: 17 additions & 13 deletions appdaemon/plugins/hass/hassapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,26 +310,30 @@ def constrain_input_boolean(self, value):
unconstrained = True
state = self.get_state()

values = value.split(",")
if len(values) == 2:
entity = values[0]
desired_state = values[1]
else:
entity = value
desired_state = "on"
if entity in state and state[entity]["state"] != desired_state:
unconstrained = False
constraints = [value] if isinstance(value, str) else value
for constraint in constraints:
values = constraint.split(",")
if len(values) == 2:
entity = values[0]
desired_state = values[1]
else:
entity = constraint
desired_state = "on"
if entity in state and state[entity]["state"] != desired_state:
unconstrained = False

return unconstrained

def constrain_input_select(self, value):
unconstrained = True
state = self.get_state()

values = value.split(",")
entity = values.pop(0)
if entity in state and state[entity]["state"] not in values:
unconstrained = False
constraints = [value] if isinstance(value, str) else value
for constraint in constraints:
values = constraint.split(",")
entity = values.pop(0)
if entity in state and state[entity]["state"] not in values:
unconstrained = False

return unconstrained

Expand Down
25 changes: 25 additions & 0 deletions docs/APPGUIDE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,18 @@ the input\_boolean is off, use the optional state parameter by appending,
class: SomeClass
constrain_input_boolean: input_boolean.enable_motion_detection,off
If you want to constrain on multiple input_boolean entities, you can provide
the constraints as a yaml list

.. code:: yaml
some_app:
module: some_module
class: SomeClass
constrain_input_boolean:
- input_boolean.enable_motion_detection
- binary_sensor.weekend,off
input\_select
^^^^^^^^^^^^^

Expand All @@ -740,6 +752,19 @@ according to some flag, e.g., a house mode flag.
# or multiple values
constrain_input_select: input_select.house_mode,Day,Evening,Night
If you want to constrain on multiple input_select entities, you can provide
the constraints as a yaml list

.. code:: yaml
some_app:
module: some_module
class: SomeClass
constrain_input_select:
- input_select.house_mode,Day
- sensor.day_of_week,Monday,Wednesday,Friday
presence
^^^^^^^^

Expand Down

0 comments on commit c8fd62d

Please sign in to comment.