Skip to content

Decorator Manager#818

Merged
craigbarratt merged 1 commit intocustom-components:masterfrom
dmamelin:decorator-manager
Apr 13, 2026
Merged

Decorator Manager#818
craigbarratt merged 1 commit intocustom-components:masterfrom
dmamelin:decorator-manager

Conversation

@dmamelin
Copy link
Copy Markdown
Contributor

Clean PR with a single commit. Full description, discussion, and commit history are in #795.

@craigbarratt craigbarratt merged commit 71309dc into custom-components:master Apr 13, 2026
6 checks passed
@craigbarratt
Copy link
Copy Markdown
Member

Thanks for all your work on this!

I've merged the PR.

Let's target the release of 2.0 in May. It would be great if some users can try it out before we do the release.

@ALERTua
Copy link
Copy Markdown
Contributor

ALERTua commented Apr 13, 2026

I will try this out, but I also want to test the documentation. Will there be any changes to the documentation? Any usage changes? Code structures changed for the end-user?

@dmamelin
Copy link
Copy Markdown
Contributor Author

@ALERTua no changes are needed in user code.
I added a note to the documentation about the new subsystem in the upcoming release, along with the option to fall back to the legacy one if any issues arise.

@ALERTua
Copy link
Copy Markdown
Contributor

ALERTua commented Apr 13, 2026

I will post my observations here.

first one:

TypeError: function 'cat_toilet_someone_pooping' defined in file.cat_toilet: decorator @time_active keyword 'hold_off' expected float for dictionary value @ data['hold_off']
@time_active("range(9:00, 23:00)", hold_off=None)
def cat_toilet_someone_pooping(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    ...

documentation:

image

stubs: def time_active(*time_spec: str, hold_off: int | float | None = None) -> Callable[..., Any]:

@ALERTua
Copy link
Copy Markdown
Contributor

ALERTua commented Apr 13, 2026

second one:

TypeError: function 'fnc' defined in apps.device_availability: decorator @state_trigger keyword 'watch' should be type list or set for dictionary value @ data['watch']

this was about a call of @state_trigger with watch=None

documentation:

image

stubs:

def state_trigger(
    *str_expr: str | list[str] | set[str],
    state_hold: int | float | None = None,
    state_hold_false: int | float | None = None,
    state_check_now: bool = False,
    kwargs: dict | None = None,
    watch: list[str] | set[str] | None = None,
) -> Callable[..., Any]:

It would be nice to be able to provide watch=None for the @state_trigger to get the list of the watched entity_ids from the trigger strings, as it would be with no watch kwarg provided at all.

@ALERTua
Copy link
Copy Markdown
Contributor

ALERTua commented Apr 13, 2026

one more:

2026-04-13 12:45:22.569 ERROR (MainThread) [custom_components.pyscript.file.xiaomi_wireless_buttons] 
  File "/config/custom_components/pyscript/decorators/base.py", line 56, in check_expression_vars
    return await self._ast_expression.eval(state_vars)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/pyscript/xiaomi_wireless_buttons.py", line 1, in file.xiaomi_wireless_buttons.button_2_single @mqtt_trigger()
    payload_obj['action'] == 'single'
    ~~~~~~~~~~~^^^^^^^^^^
KeyError: 'action'

triggered for

@mqtt_trigger('zigbee2mqtt_slzb/xiaomi_wireless_button_2', "payload_obj['action'] == 'single'")
def button_2_single(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    log.debug(f"button_2_single")

I cannot reproduce this 100% of the presses. Maybe the button randomly sends malformed payloads. Disregard until an issue is raised, I guess.
I changed it to payload_obj.get('action', None).

@ALERTua
Copy link
Copy Markdown
Contributor

ALERTua commented Apr 13, 2026

Also, the logs are littered with debug trigger prints for eeevery trigger triggered and skipped. While I like this, it would be nice to have the default logging level as INFO instead of DEBUG and the documented way to change it.

2026-04-13 12:52:11.835 DEBUG (MainThread) [custom_components.pyscript.file.sun_autowindow] Trigger not active due to @time_active(range(13:30, 20:15))
2026-04-13 12:48:41.586 DEBUG (MainThread) [custom_components.pyscript.file.xiaomi_wireless_buttons] trigger file.xiaomi_wireless_buttons.button_2_double got @mqtt_trigger(zigbee2mqtt_slzb/xiaomi_wireless_button_2,payload_obj['action'] == 'double') trigger, running action (kwargs = {'trigger_type': 'mqtt', 'topic': 'zigbee2mqtt_slzb/xiaomi_wireless_button_2', 'payload': '{"action":"double","battery":100,"device":

I can post my observations as separate issues if you want.

@dmamelin
Copy link
Copy Markdown
Contributor Author

dmamelin commented Apr 13, 2026

@ALERTua thanks for testing and for the feedback!

I'd appreciate it if each issue could be reported separately. In any case, this is now in master, so feel free to open any issues.

PS The first and second issues are the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants