|
22 | 22 | _LOGGER = logging.getLogger(LOGGER_PATH + ".trigger") |
23 | 23 |
|
24 | 24 |
|
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*(\.\*)?$") |
26 | 26 |
|
27 | 27 |
|
28 | 28 | def dt_now(): |
@@ -739,7 +739,7 @@ async def trigger_watch(self): |
739 | 739 | elif notify_type == "state": |
740 | 740 | new_vars, func_args = notify_info |
741 | 741 |
|
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): |
743 | 743 | if self.state_trig_eval: |
744 | 744 | trig_ok = await self.state_trig_eval.eval(new_vars) |
745 | 745 | exc = self.state_trig_eval.get_exception_long() |
@@ -819,16 +819,29 @@ async def trigger_watch(self): |
819 | 819 | # if "value" not in func_args, then we are state_check_now |
820 | 820 | if "value" in func_args and notify_type == 'state': |
821 | 821 | 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) |
830 | 832 | if attrib_old_val != attrib_val: |
831 | 833 | 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 |
832 | 845 |
|
833 | 846 | if not trig_ident_change: |
834 | 847 | continue |
|
0 commit comments