Skip to content

kwargs are empty if state_hold is used #516

Closed

Description

@ALERTua

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.

Activity

  1. added a commit that references this issue on Aug 17, 2023
  2. craigbarratt commented on Aug 17, 2023

    @craigbarratt
    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.

  3. ALERTua commented on Aug 18, 2023

    @ALERTua
    ContributorAuthor

    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')
    
    
  4. added a commit that references this issue on Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions