From f268378f0fdf3cccab00d57c13104acfd2447755 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 9 Oct 2020 02:57:46 -0500 Subject: [PATCH] Fix plant doing IO in the event loop. (#41527) Co-authored-by: Paulus Schoutsen --- homeassistant/components/plant/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/plant/__init__.py b/homeassistant/components/plant/__init__.py index 1cb2416d12a..2d829187560 100644 --- a/homeassistant/components/plant/__init__.py +++ b/homeassistant/components/plant/__init__.py @@ -282,7 +282,8 @@ class Plant(Entity): """After being added to hass, load from history.""" if ENABLE_LOAD_HISTORY and "recorder" in self.hass.config.components: # only use the database if it's configured - self.hass.async_add_job(self._load_history_from_db) + await self.hass.async_add_executor_job(self._load_history_from_db) + self.async_write_ha_state() async_track_state_change_event( self.hass, list(self._sensormap), self._state_changed_event @@ -293,7 +294,7 @@ class Plant(Entity): if state is not None: self.state_changed(entity_id, state) - async def _load_history_from_db(self): + def _load_history_from_db(self): """Load the history of the brightness values from the database. This only needs to be done once during startup. @@ -330,7 +331,6 @@ class Plant(Entity): except ValueError: pass _LOGGER.debug("Initializing from database completed") - self.async_write_ha_state() @property def should_poll(self):