Switch filter to use the database executor (#68594)

This commit is contained in:
J. Nick Koston 2022-03-23 13:20:43 -10:00 committed by GitHub
parent dbef90654f
commit e5f424a280
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,7 @@ import voluptuous as vol
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.components.input_number import DOMAIN as INPUT_NUMBER_DOMAIN
from homeassistant.components.recorder import history
from homeassistant.components.recorder import get_instance, history
from homeassistant.components.sensor import (
ATTR_STATE_CLASS,
DEVICE_CLASSES as SENSOR_DEVICE_CLASSES,
@ -296,7 +296,7 @@ class SensorFilter(SensorEntity):
# Retrieve the largest window_size of each type
if largest_window_items > 0:
filter_history = await self.hass.async_add_executor_job(
filter_history = await get_instance(self.hass).async_add_executor_job(
partial(
history.get_last_state_changes,
self.hass,
@ -308,7 +308,7 @@ class SensorFilter(SensorEntity):
history_list.extend(filter_history[self._entity])
if largest_window_time > timedelta(seconds=0):
start = dt_util.utcnow() - largest_window_time
filter_history = await self.hass.async_add_executor_job(
filter_history = await get_instance(self.hass).async_add_executor_job(
partial(
history.state_changes_during_period,
self.hass,