-
Notifications
You must be signed in to change notification settings - Fork 55
WIP: Alternate implementation to only trigger on changes #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1a5a7cd
337889b
4981144
8aa1230
8ceeeec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,15 @@ async def state_changed(event): | |
"old_value": old_val, | ||
"context": event.context, | ||
} | ||
|
||
if new_val is not None: | ||
for attribute in event.data["new_state"].attributes: | ||
new_vars[f"{var_name}.{attribute}"] = event.data["new_state"].attributes[attribute] | ||
|
||
if old_val is not None: | ||
for attribute in event.data["old_state"].attributes: | ||
new_vars[f"{var_name}.{attribute}.old"] = event.data["old_state"].attributes[attribute] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines shouldn't be necessary now, since the |
||
await State.update(new_vars, func_args) | ||
|
||
async def hass_started(event): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,12 +115,12 @@ async def update(cls, new_vars, func_args): | |
@classmethod | ||
def notify_var_get(cls, var_names, new_vars): | ||
"""Return the most recent value of a state variable change.""" | ||
notify_vars = {} | ||
notify_vars = new_vars | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a good simplification. One small change: it's probably better to do
so that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I honestly don't know why this wasn't working the way it was. I made this change just to be SURE it was what I expected it to be, and it fixed the whole thing. I guess cls.notify had something in it I didn't expect. But I'm not sure how. |
||
for var_name in var_names if var_names is not None else []: | ||
if var_name in cls.notify_var_last: | ||
notify_vars[var_name] = cls.notify_var_last[var_name] | ||
elif var_name in new_vars: | ||
notify_vars[var_name] = new_vars[var_name] | ||
# elif var_name in new_vars: | ||
# notify_vars[var_name] = new_vars[var_name] | ||
elif 1 <= var_name.count(".") <= 2 and not cls.exist(var_name): | ||
notify_vars[var_name] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is going to need some modifications. I still haven't fully though this through. The motivation is to avoid exceptions due to undefined variables (eg: undefined state variable or attribute) by setting all variables that are not found in Not sure if that makes sense. I'm happy to deal with this after merge. |
||
return notify_vars | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -812,6 +812,19 @@ async def trigger_watch(self): | |
if self.task_unique is not None: | ||
task_unique_func = Function.task_unique_factory(action_ast_ctx) | ||
|
||
|
||
# | ||
# for state notify, check that changes occurred in state_trig_ident variables | ||
# | ||
if notify_type == 'state': | ||
trig_ident_changed = False | ||
for var in self.state_trig_ident: | ||
if new_vars.get(var) != new_vars.get(f"{var}.old"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll need to check if |
||
trig_ident_changed = True | ||
|
||
if not trig_ident_changed: | ||
continue | ||
|
||
# | ||
# check for @task_unique with kill_me=True | ||
# | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With f7169ac,
"value"
can beStateVar(event.data.get('new_state'))
, orNone
ifnew_state
is not provided (eg, when state variable is deleted. Same for"old_value"
.