pyscript
pyscript copied to clipboard
add virtual attribute StateVal.entity_id
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}")
@craigbarratt, ping :)
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.
Thanks for the PR. Sorry about the delay in following up.