Store capabilities and supported features in entity registry, restore registered entities on startup (#30094)
* Store capabilities and supported features in entity registry * Restore states at startup * Restore non-disabled entities on HA start * Fix test * Pass device class from entity platform * Clean up restored entities from state machine * Fix Z-Wave test?
This commit is contained in:
1 parent
2c1a7a54cd
commit
bb14a083f0
8 files changed
+293
-18
No files matched your search
@@ -793,3 +793,44 @@ async def test_entity_disabled_by_integration(hass):
|
||||
assert entry_default.disabled_by is None
|
||||
entry_disabled = registry.async_get_or_create(DOMAIN, DOMAIN, "disabled")
|
||||
assert entry_disabled.disabled_by == "integration"
|
||||
|
||||
|
||||
async def test_entity_info_added_to_entity_registry(hass):
|
||||
"""Test entity info is written to entity registry."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass, timedelta(seconds=20))
|
||||
|
||||
entity_default = MockEntity(
|
||||
unique_id="default",
|
||||
capability_attributes={"max": 100},
|
||||
supported_features=5,
|
||||
device_class="mock-device-class",
|
||||
)
|
||||
|
||||
await component.async_add_entities([entity_default])
|
||||
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
entry_default = registry.async_get_or_create(DOMAIN, DOMAIN, "default")
|
||||
print(entry_default)
|
||||
assert entry_default.capabilities == {"max": 100}
|
||||
assert entry_default.supported_features == 5
|
||||
assert entry_default.device_class == "mock-device-class"
|
||||
|
||||
|
||||
async def test_override_restored_entities(hass):
|
||||
"""Test that we allow overriding restored entities."""
|
||||
registry = mock_registry(hass)
|
||||
registry.async_get_or_create(
|
||||
"test_domain", "test_domain", "1234", suggested_object_id="world"
|
||||
)
|
||||
|
||||
hass.states.async_set("test_domain.world", "unavailable", {"restored": True})
|
||||
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
|
||||
await component.async_add_entities(
|
||||
[MockEntity(unique_id="1234", state="on", entity_id="test_domain.world")], True
|
||||
)
|
||||
|
||||
state = hass.states.get("test_domain.world")
|
||||
assert state.state == "on"
|
||||
Reference in new issue
Block a user