Fix plant doing IO in the event loop. (#41527)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
J. Nick Koston 2020-10-09 02:57:46 -05:00 committed by GitHub
parent d3734aae9d
commit f268378f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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):