Fix threading error in recorder tests (#62187)

This commit is contained in:
Erik Montnemery 2021-12-17 13:17:48 +01:00 committed by GitHub
parent f7f1d9b15d
commit 474ef54477
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 9 deletions

View file

@ -531,7 +531,7 @@ def test_saving_state_and_removing_entity(hass, hass_recorder):
entity_id = "lock.mine"
hass.states.set(entity_id, STATE_LOCKED)
hass.states.set(entity_id, STATE_UNLOCKED)
hass.states.async_remove(entity_id)
hass.states.remove(entity_id)
wait_recording_done(hass)

View file

@ -29,6 +29,7 @@ from homeassistant.components.recorder.statistics import (
)
from homeassistant.components.recorder.util import session_scope
from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.setup import setup_component
import homeassistant.util.dt as dt_util
@ -230,13 +231,19 @@ def test_rename_entity(hass_recorder):
setup_component(hass, "sensor", {})
entity_reg = mock_registry(hass)
reg_entry = entity_reg.async_get_or_create(
"sensor",
"test",
"unique_0000",
suggested_object_id="test1",
)
assert reg_entry.entity_id == "sensor.test1"
@callback
def add_entry():
reg_entry = entity_reg.async_get_or_create(
"sensor",
"test",
"unique_0000",
suggested_object_id="test1",
)
assert reg_entry.entity_id == "sensor.test1"
hass.add_job(add_entry)
hass.block_till_done()
zero, four, states = record_states(hass)
hist = history.get_significant_states(hass, zero, four)
@ -274,7 +281,11 @@ def test_rename_entity(hass_recorder):
stats = statistics_during_period(hass, zero, period="5minute")
assert stats == {"sensor.test1": expected_stats1, "sensor.test2": expected_stats2}
entity_reg.async_update_entity(reg_entry.entity_id, new_entity_id="sensor.test99")
@callback
def rename_entry():
entity_reg.async_update_entity("sensor.test1", new_entity_id="sensor.test99")
hass.add_job(rename_entry)
hass.block_till_done()
stats = statistics_during_period(hass, zero, period="5minute")