mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Fix restore state crashing invalid entity ID (#20367)
This commit is contained in:
@@ -6,7 +6,8 @@ from homeassistant.core import CoreState, State
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.restore_state import (
|
||||
RestoreStateData, RestoreEntity, StoredState, DATA_RESTORE_STATE_TASK)
|
||||
RestoreStateData, RestoreEntity, StoredState, DATA_RESTORE_STATE_TASK,
|
||||
STORAGE_KEY)
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from asynctest import patch
|
||||
@@ -218,3 +219,34 @@ async def test_state_saved_on_remove(hass):
|
||||
|
||||
# We should store the input boolean state when it is removed
|
||||
assert data.last_states['input_boolean.b0'].state.state == 'on'
|
||||
|
||||
|
||||
async def test_restoring_invalid_entity_id(hass, hass_storage):
|
||||
"""Test restoring invalid entity IDs."""
|
||||
entity = RestoreEntity()
|
||||
entity.hass = hass
|
||||
entity.entity_id = 'test.invalid__entity_id'
|
||||
now = dt_util.utcnow().isoformat()
|
||||
hass_storage[STORAGE_KEY] = {
|
||||
'version': 1,
|
||||
'key': STORAGE_KEY,
|
||||
'data': [
|
||||
{
|
||||
'state': {
|
||||
'entity_id': 'test.invalid__entity_id',
|
||||
'state': 'off',
|
||||
'attributes': {},
|
||||
'last_changed': now,
|
||||
'last_updated': now,
|
||||
'context': {
|
||||
'id': '3c2243ff5f30447eb12e7348cfd5b8ff',
|
||||
'user_id': None
|
||||
}
|
||||
},
|
||||
'last_seen': dt_util.utcnow().isoformat()
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
state = await entity.async_get_last_state()
|
||||
assert state is None
|
||||
|
||||
Reference in New Issue
Block a user