Skip to content

Commit c49310d

Browse files
committed
add domain.entity.* tracking
1 parent f06c0c4 commit c49310d

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

custom_components/pyscript/trigger.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
_LOGGER = logging.getLogger(LOGGER_PATH + ".trigger")
2323

2424

25-
STATE_RE = re.compile(r"[a-zA-Z]\w*\.[a-zA-Z]\w*$")
25+
STATE_RE = re.compile(r"[a-zA-Z]\w*\.[a-zA-Z]\w*(\.\*)?$")
2626

2727

2828
def dt_now():
@@ -739,7 +739,7 @@ async def trigger_watch(self):
739739
elif notify_type == "state":
740740
new_vars, func_args = notify_info
741741

742-
if "var_name" not in func_args or func_args["var_name"] not in self.state_trig_ident_any:
742+
if "var_name" not in func_args or (func_args["var_name"] not in self.state_trig_ident_any and f"{func_args['var_name']}.*" not in self.state_trig_ident_any):
743743
if self.state_trig_eval:
744744
trig_ok = await self.state_trig_eval.eval(new_vars)
745745
exc = self.state_trig_eval.get_exception_long()
@@ -819,16 +819,29 @@ async def trigger_watch(self):
819819
# if "value" not in func_args, then we are state_check_now
820820
if "value" in func_args and notify_type == 'state':
821821
trig_ident_change = False
822-
for var in self.state_trig_ident:
823-
var_pieces = var.split('.')
824-
if len(var_pieces) == 2 and var == func_args['var_name']:
825-
if func_args['value'] != func_args['old_value']:
826-
trig_ident_change = True
827-
elif len(var_pieces) == 3 and f"{var_pieces[0]}.{var_pieces[1]}" == func_args['var_name']:
828-
attrib_val = getattr(func_args['value'], var_pieces[2], None)
829-
attrib_old_val = getattr(func_args['old_value'], var_pieces[2], None)
822+
823+
# determine if the catchall has been requested in state_trig_ident_any
824+
catch_all_entity = f"{func_args['var_name']}.*"
825+
if catch_all_entity in self.state_trig_ident_any:
826+
# catch all has been requested, check all attributes for change
827+
for attribute in func_args['value'].__dict__:
828+
if attribute in ['last_updated', 'last_changed']:
829+
continue
830+
attrib_val = getattr(func_args['value'], attribute, None)
831+
attrib_old_val = getattr(func_args['old_value'], attribute, None)
830832
if attrib_old_val != attrib_val:
831833
trig_ident_change = True
834+
else:
835+
for var in self.state_trig_ident:
836+
var_pieces = var.split('.')
837+
if len(var_pieces) == 2 and var == func_args['var_name']:
838+
if func_args['value'] != func_args['old_value']:
839+
trig_ident_change = True
840+
elif len(var_pieces) == 3 and f"{var_pieces[0]}.{var_pieces[1]}" == func_args['var_name']:
841+
attrib_val = getattr(func_args['value'], var_pieces[2], None)
842+
attrib_old_val = getattr(func_args['old_value'], var_pieces[2], None)
843+
if attrib_old_val != attrib_val:
844+
trig_ident_change = True
832845

833846
if not trig_ident_change:
834847
continue

0 commit comments

Comments
 (0)