Fix threading error in recorder tests (#62187)
This commit is contained in:
parent
f7f1d9b15d
commit
474ef54477
2 changed files with 20 additions and 9 deletions
|
@ -531,7 +531,7 @@ def test_saving_state_and_removing_entity(hass, hass_recorder):
|
||||||
entity_id = "lock.mine"
|
entity_id = "lock.mine"
|
||||||
hass.states.set(entity_id, STATE_LOCKED)
|
hass.states.set(entity_id, STATE_LOCKED)
|
||||||
hass.states.set(entity_id, STATE_UNLOCKED)
|
hass.states.set(entity_id, STATE_UNLOCKED)
|
||||||
hass.states.async_remove(entity_id)
|
hass.states.remove(entity_id)
|
||||||
|
|
||||||
wait_recording_done(hass)
|
wait_recording_done(hass)
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ from homeassistant.components.recorder.statistics import (
|
||||||
)
|
)
|
||||||
from homeassistant.components.recorder.util import session_scope
|
from homeassistant.components.recorder.util import session_scope
|
||||||
from homeassistant.const import TEMP_CELSIUS
|
from homeassistant.const import TEMP_CELSIUS
|
||||||
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
@ -230,6 +231,9 @@ def test_rename_entity(hass_recorder):
|
||||||
setup_component(hass, "sensor", {})
|
setup_component(hass, "sensor", {})
|
||||||
|
|
||||||
entity_reg = mock_registry(hass)
|
entity_reg = mock_registry(hass)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def add_entry():
|
||||||
reg_entry = entity_reg.async_get_or_create(
|
reg_entry = entity_reg.async_get_or_create(
|
||||||
"sensor",
|
"sensor",
|
||||||
"test",
|
"test",
|
||||||
|
@ -238,6 +242,9 @@ def test_rename_entity(hass_recorder):
|
||||||
)
|
)
|
||||||
assert reg_entry.entity_id == "sensor.test1"
|
assert reg_entry.entity_id == "sensor.test1"
|
||||||
|
|
||||||
|
hass.add_job(add_entry)
|
||||||
|
hass.block_till_done()
|
||||||
|
|
||||||
zero, four, states = record_states(hass)
|
zero, four, states = record_states(hass)
|
||||||
hist = history.get_significant_states(hass, zero, four)
|
hist = history.get_significant_states(hass, zero, four)
|
||||||
assert dict(states) == dict(hist)
|
assert dict(states) == dict(hist)
|
||||||
|
@ -274,7 +281,11 @@ def test_rename_entity(hass_recorder):
|
||||||
stats = statistics_during_period(hass, zero, period="5minute")
|
stats = statistics_during_period(hass, zero, period="5minute")
|
||||||
assert stats == {"sensor.test1": expected_stats1, "sensor.test2": expected_stats2}
|
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()
|
hass.block_till_done()
|
||||||
|
|
||||||
stats = statistics_during_period(hass, zero, period="5minute")
|
stats = statistics_during_period(hass, zero, period="5minute")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue