Skip to content

Commit

Permalink
Merge pull request #1534 from Odianosen25/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Odianosen25 authored Jun 28, 2022
2 parents 1a3b6c8 + 32c284b commit 42cf66c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
20 changes: 14 additions & 6 deletions appdaemon/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ async def get_pinned_apps(self, thread):
#

async def check_constraint(self, key, value, app):
"""Used to check Constraint"""

unconstrained = True
if key in app.list_constraints():
method = getattr(app, key)
Expand All @@ -592,6 +594,8 @@ async def check_constraint(self, key, value, app):
return unconstrained

async def check_time_constraint(self, args, name):
"""Used to check time Constraint"""

unconstrained = True
if "constrain_start_time" in args or "constrain_end_time" in args:
if "constrain_start_time" not in args:
Expand All @@ -607,7 +611,9 @@ async def check_time_constraint(self, args, name):

return unconstrained

async def check_days_constraint(self, args):
async def check_days_constraint(self, args, name):
"""Used to check days Constraint"""

unconstrained = True
if "constrain_days" in args:
days = args["constrain_days"]
Expand All @@ -621,10 +627,12 @@ async def check_days_constraint(self, args):

return unconstrained

async def check_state_constraint(self, args, new_state):
async def check_state_constraint(self, args, new_state, name):
"""Used to check state Constraint"""

unconstrained = True
if "constrain_state" in args:
unconstrained = utils.check_state(self.logger, new_state, args["constrain_state"])
unconstrained = utils.check_state(self.logger, new_state, args["constrain_state"], name)

return unconstrained

Expand Down Expand Up @@ -793,7 +801,7 @@ async def dispatch_worker(self, name, args):
unconstrained = False
if not await self.check_time_constraint(self.AD.app_management.app_config[name], name):
unconstrained = False
elif not await self.check_days_constraint(self.AD.app_management.app_config[name]):
elif not await self.check_days_constraint(self.AD.app_management.app_config[name], name):
unconstrained = False

#
Expand All @@ -811,14 +819,14 @@ async def dispatch_worker(self, name, args):
unconstrained = False
if not await self.check_time_constraint(myargs["kwargs"], name):
unconstrained = False
elif not await self.check_days_constraint(myargs["kwargs"]):
elif not await self.check_days_constraint(myargs["kwargs"], name):
unconstrained = False

#
# Lets determine the state constraint
#
if myargs["type"] == "state":
state_unconstrained = await self.check_state_constraint(myargs["kwargs"], myargs["new_state"])
state_unconstrained = await self.check_state_constraint(myargs["kwargs"], myargs["new_state"], name)
unconstrained = all((unconstrained, state_unconstrained))

if unconstrained:
Expand Down
4 changes: 2 additions & 2 deletions appdaemon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def __init__(self, dict):
self.__dict__ = AttrDict.from_nested_dict(dict)


def check_state(logger, new_state, callback_state) -> bool:
def check_state(logger, new_state, callback_state, name) -> bool:

passed = False

Expand All @@ -200,7 +200,7 @@ def check_state(logger, new_state, callback_state) -> bool:
passed = callback_state(new_state)

except Exception as e:
logger.warning("Could not evaluate state check due to %s", e)
logger.warning("Could not evaluate state check due to %s, from %s", e, name)
passed = False

return passed
Expand Down
36 changes: 19 additions & 17 deletions docs/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,10 @@ None

- Fixed issue when when using `timeout` in listen event api, after the event is ran one gets an error in log
- Fixed issue when an entity is deleted from HA, and it remains in AD

**Breaking Changes**

None

4.2.1 - (2022-01-17)
--------------------

**Features**

- Docker: Added MQTT vars to dockerStart.sh - contributed by `Xavi Moreno <https://github.com/xaviml>`__

**Fixes**

- Fixed issue whereby `turn_on`, `turn_off` and `toggle` for some HASS entities didn't work
- Fixed issue whereby `render_template` didn't work
- FIxed issues with setup file saying support "python3 3.0"
- Fixed issue with setup file saying support "python3 3.0"
- FIxed issue with the inability to know which app's callback failed `constrain_state` check
- Documentation fixes - contributed by `Rootie <https://github.com/Rootie>`__
- Documentation fixes - contributed by `Jakob Ruhe <https://github.com/jakeru>`__
- Bump black to 22.3.0 and run it on all files - contributed by `Jakob Ruhe <https://github.com/jakeru>`__
- Bumped websocket-client from 1.2.3 to 1.3.3
- Bumped azure-mgmt-storage from 19.0.0 to 20.0.0
Expand All @@ -50,6 +36,22 @@ None

None

4.2.1 - (2022-01-17)
--------------------

**Features**

- Docker: Added MQTT vars to dockerStart.sh - contributed by `Xavi Moreno <https://github.com/xaviml>`__

**Fixes**

- Fixed issue whereby `turn_on`, `turn_off` and `toggle` for some HASS entities didn't work
- Fixed issue whereby `render_template` didn't work

**Breaking Changes**

None

4.2.0 (2022-01-03)
------------------

Expand Down

0 comments on commit 42cf66c

Please sign in to comment.