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
Simplify emulated_hue exposed entities cache #109890
Conversation
Also avoids holding stale States in memory which can prevent garbage collection of linked contexts
Hey there @Tho85, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
return [ | ||
entity_id | ||
for entity_id in self.entities | ||
if (state := state_machine.get(entity_id)) and self.is_state_exposed(state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're caching something here that relies on he state machine. I know that's existing code but that seems weird ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache gets cleared in the function below it when needed. We watch when new states are being added and removed to/from the state machine in async_setup and clear the cache when they are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only use the cache to figure out what is exposed. The state machine still gets polled every api request unfortunately
def create_list_of_entities(config: Config, request: web.Request) -> dict[str, Any]:
"""Create a list of all entities."""
hass: core.HomeAssistant = request.app["hass"]
return {
config.entity_id_to_number(entity_id): state_to_json(config, state)
for entity_id in config.get_exposed_entity_ids()
if (state := hass.states.get(entity_id))
}
That could watch states and only do state_to_json
when they actually change.. but thats something for the future, and now I'm a bit off topic
Proposed change
Also avoids holding stale States in memory which can prevent garbage collection of linked contexts
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: