Skip to content

add virtual attribute StateVal.entity_id - #555

Merged
craigbarratt merged 2 commits into
custom-components:masterfrom
dmamelin:master
Jun 19, 2024
Merged

craigbarratt merged 2 commits into
custom-components:masterfrom
dmamelin:master

Conversation

@dmamelin

@dmamelin dmamelin commented Dec 5, 2023

Copy link
Copy Markdown
Contributor

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

ALERTua commented Jan 22, 2024

Copy link
Copy Markdown
Contributor

@craigbarratt, ping :)

@dmamelin

dmamelin commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

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.

@craigbarratt
craigbarratt merged commit 8302c13 into custom-components:master Jun 19, 2024
@craigbarratt

Copy link
Copy Markdown
Member

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

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.

3 participants