mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Ensure recorder statistics process registry updates in the db executor (#68633)
This commit is contained in:
parent
9f079a22d5
commit
3777fa52f0
@ -190,7 +190,7 @@ def async_setup(hass: HomeAssistant) -> None:
|
|||||||
hass.data[STATISTICS_META_BAKERY] = baked.bakery()
|
hass.data[STATISTICS_META_BAKERY] = baked.bakery()
|
||||||
hass.data[STATISTICS_SHORT_TERM_BAKERY] = baked.bakery()
|
hass.data[STATISTICS_SHORT_TERM_BAKERY] = baked.bakery()
|
||||||
|
|
||||||
def entity_id_changed(event: Event) -> None:
|
def _entity_id_changed(event: Event) -> None:
|
||||||
"""Handle entity_id changed."""
|
"""Handle entity_id changed."""
|
||||||
old_entity_id = event.data["old_entity_id"]
|
old_entity_id = event.data["old_entity_id"]
|
||||||
entity_id = event.data["entity_id"]
|
entity_id = event.data["entity_id"]
|
||||||
@ -200,6 +200,9 @@ def async_setup(hass: HomeAssistant) -> None:
|
|||||||
& (StatisticsMeta.source == DOMAIN)
|
& (StatisticsMeta.source == DOMAIN)
|
||||||
).update({StatisticsMeta.statistic_id: entity_id})
|
).update({StatisticsMeta.statistic_id: entity_id})
|
||||||
|
|
||||||
|
async def _async_entity_id_changed(event: Event) -> None:
|
||||||
|
await hass.data[DATA_INSTANCE].async_add_executor_job(_entity_id_changed, event)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def entity_registry_changed_filter(event: Event) -> bool:
|
def entity_registry_changed_filter(event: Event) -> bool:
|
||||||
"""Handle entity_id changed filter."""
|
"""Handle entity_id changed filter."""
|
||||||
@ -211,7 +214,7 @@ def async_setup(hass: HomeAssistant) -> None:
|
|||||||
if hass.is_running:
|
if hass.is_running:
|
||||||
hass.bus.async_listen(
|
hass.bus.async_listen(
|
||||||
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
|
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
|
||||||
entity_id_changed,
|
_async_entity_id_changed,
|
||||||
event_filter=entity_registry_changed_filter,
|
event_filter=entity_registry_changed_filter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user