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

add virtual attribute StateVal.entity_id #555

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dmamelin
Copy link

@dmamelin dmamelin commented Dec 5, 2023

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 dmamelin closed this Jan 6, 2024
@dmamelin dmamelin reopened this Jan 6, 2024
@ALERTua
Copy link
Contributor

ALERTua commented Jan 22, 2024

@craigbarratt, ping :)

@dmamelin
Copy link
Author

dmamelin commented Feb 1, 2024

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.

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.

None yet

2 participants