Allow entities to indicate they should be disabled by default (#26011)
This commit is contained in:
1 parent
b5893a8a6e
commit
6c292846be
6 files changed
+55
-1
No files matched your search
@@ -908,6 +908,11 @@ class MockEntity(entity.Entity):
|
||||
"""Info how it links to a device."""
|
||||
return self._handle("device_info")
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self):
|
||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||
return self._handle("entity_registry_enabled_default")
|
||||
|
||||
def _handle(self, attr):
|
||||
"""Return attribute value."""
|
||||
if attr in self._values:
|
||||
|
||||
@@ -775,3 +775,22 @@ async def test_device_info_not_overrides(hass):
|
||||
assert device.id == device2.id
|
||||
assert device2.manufacturer == "test-manufacturer"
|
||||
assert device2.model == "test-model"
|
||||
|
||||
|
||||
async def test_entity_disabled_by_integration(hass):
|
||||
"""Test entity disabled by integration."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass, timedelta(seconds=20))
|
||||
|
||||
entity_default = MockEntity(unique_id="default")
|
||||
entity_disabled = MockEntity(
|
||||
unique_id="disabled", entity_registry_enabled_default=False
|
||||
)
|
||||
|
||||
await component.async_add_entities([entity_default, entity_disabled])
|
||||
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
entry_default = registry.async_get_or_create(DOMAIN, DOMAIN, "default")
|
||||
assert entry_default.disabled_by is None
|
||||
entry_disabled = registry.async_get_or_create(DOMAIN, DOMAIN, "disabled")
|
||||
assert entry_disabled.disabled_by == "integration"
|
||||
@@ -352,3 +352,17 @@ async def test_update_entity_unique_id_conflict(registry):
|
||||
) as mock_schedule_save, pytest.raises(ValueError):
|
||||
registry.async_update_entity(entry.entity_id, new_unique_id=entry2.unique_id)
|
||||
assert mock_schedule_save.call_count == 0
|
||||
|
||||
|
||||
async def test_disabled_by(registry):
|
||||
"""Test that we can disable an entry when we create it."""
|
||||
entry = registry.async_get_or_create("light", "hue", "5678", disabled_by="hass")
|
||||
assert entry.disabled_by == "hass"
|
||||
|
||||
entry = registry.async_get_or_create(
|
||||
"light", "hue", "5678", disabled_by="integration"
|
||||
)
|
||||
assert entry.disabled_by == "hass"
|
||||
|
||||
entry2 = registry.async_get_or_create("light", "hue", "1234")
|
||||
assert entry2.disabled_by is None
|
||||
Reference in new issue
Block a user