From 3777fa52f0b64677c8582567dc4f146fa4fee946 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 24 Mar 2022 09:48:09 -1000 Subject: [PATCH] Ensure recorder statistics process registry updates in the db executor (#68633) --- homeassistant/components/recorder/statistics.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/recorder/statistics.py b/homeassistant/components/recorder/statistics.py index 67b2568fc53..f01190097df 100644 --- a/homeassistant/components/recorder/statistics.py +++ b/homeassistant/components/recorder/statistics.py @@ -190,7 +190,7 @@ def async_setup(hass: HomeAssistant) -> None: hass.data[STATISTICS_META_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.""" old_entity_id = event.data["old_entity_id"] entity_id = event.data["entity_id"] @@ -200,6 +200,9 @@ def async_setup(hass: HomeAssistant) -> None: & (StatisticsMeta.source == DOMAIN) ).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 def entity_registry_changed_filter(event: Event) -> bool: """Handle entity_id changed filter.""" @@ -211,7 +214,7 @@ def async_setup(hass: HomeAssistant) -> None: if hass.is_running: hass.bus.async_listen( entity_registry.EVENT_ENTITY_REGISTRY_UPDATED, - entity_id_changed, + _async_entity_id_changed, event_filter=entity_registry_changed_filter, )