pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

add virtual attribute StateVal.entity_id

Open dmamelin opened this issue 2 years ago • 2 comments

Modifying StateVal according to homeassistant.core.State. Useful in complex logic: no need to store and pass entity_id. Simplified example:

def func(state):
    num_seconds_ago = (dt.now(tz=timezone.utc) - state.last_changed).total_seconds()
    if num_seconds_ago > 10:
        light.toggle(entity_id=state.entity_id)
        log.info(f"toggle {state.entity_id}")

dmamelin avatar Dec 05 '23 21:12 dmamelin

@craigbarratt, ping :)

ALERTua avatar Jan 22 '24 14:01 ALERTua

ooops... I wanted to make a separate PR for #581, but forgot about this PR and when I pushed to my fork, the changes were added here.

dmamelin avatar Feb 01 '24 01:02 dmamelin

Thanks for the PR. Sorry about the delay in following up.

craigbarratt avatar Jun 19 '24 20:06 craigbarratt