Skip to content
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

kwargs are empty if state_hold is used #516

Closed
ALERTua opened this issue Aug 17, 2023 · 2 comments
Closed

kwargs are empty if state_hold is used #516

ALERTua opened this issue Aug 17, 2023 · 2 comments

Comments

@ALERTua
Copy link
Contributor

ALERTua commented Aug 17, 2023

After the recent master commit 7a81413, that was a fix for #512, kwargs of state_trigger are empty if state_hold argument is used.

@state_trigger(f"{constants.TEST_BOOLEAN}", kwargs=dict(my_kwarg=123))
def tryouts1(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    log.debug(kwargs)

This will output {'my_kwarg': 123}

@state_trigger(f"{constants.TEST_BOOLEAN}", kwargs=dict(my_kwarg=123), state_hold=1)
def tryouts2(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    log.debug(kwargs)

This will output {}

Rolling back to version 1.5.0 fixes the issue.

ALERTua referenced this issue Aug 17, 2023
craigbarratt added a commit that referenced this issue Aug 17, 2023
@craigbarratt
Copy link
Member

Ah - good catch. I pushed a new fix for #512 which hopefully doesn't break the hold kwargs. Still need to do more testing.

@ALERTua
Copy link
Contributor Author

ALERTua commented Aug 18, 2023

The fix seems to work. I've deployed basic scratch kwargs tests on my instance to detect such issues early on in the future.

from imports import *

try:
    _ = pyscript.test_1
    _ = pyscript.test_2
    _ = pyscript.test_3
    _ = pyscript.test_4
    _ = pyscript.test_5
    _ = pyscript.test_6
    _ = pyscript.test_7
    _ = pyscript.test_8
except:
    pyscript.test_1 = False
    pyscript.test_2 = False
    pyscript.test_3 = False
    pyscript.test_4 = False
    pyscript.test_5 = False
    pyscript.test_6 = False
    pyscript.test_7 = False
    pyscript.test_8 = False


TRIGGER = "sensor.datetime_full.hours"


@state_trigger(TRIGGER, kwargs=dict(my_kwarg=123))
def test1(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    if pyscript.test_1:
        return

    pyscript.test_1 = True

    if kwargs:
        log.debug(f"test1 succeeded")
        return

    tools.telegram_message(f'{__name__}.test1: kwargs are empty')


@state_trigger(TRIGGER, kwargs=dict(my_kwarg=123), state_hold=1)
def test2(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    if pyscript.test_2:
        return

    pyscript.test_2 = True

    if kwargs:
        log.debug(f"test2 succeeded")
        return

    tools.telegram_message(f'{__name__}.test2: kwargs are empty')


@state_trigger(TRIGGER, kwargs=dict(my_kwarg=123), state_hold_false=1)
def test3(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    if pyscript.test_3:
        return

    pyscript.test_3 = True

    if kwargs:
        log.debug(f"test3 succeeded")
        return

    tools.telegram_message(f'{__name__}.test3: kwargs are empty')


@state_trigger(TRIGGER, kwargs=dict(my_kwarg=123), state_check_now=True)
def test4(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    if pyscript.test_4:
        return

    pyscript.test_4 = True

    if kwargs:
        log.debug(f"test4 succeeded")
        return

    tools.telegram_message(f'{__name__}.test4: kwargs are empty')


@time_trigger("startup", kwargs=dict(my_kwarg=123))
def test5(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    if pyscript.test_5:
        return

    pyscript.test_5 = True

    if kwargs:
        log.debug(f"test5 succeeded")
        return

    tools.telegram_message(f'{__name__}.test5: kwargs are empty')

@ALERTua ALERTua closed this as completed Aug 18, 2023
craigbarratt added a commit that referenced this issue Aug 19, 2023
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

No branches or pull requests

2 participants