Allow disabling entities in the registry (#12360)

This commit is contained in:
Paulus Schoutsen authored and Pascal Vizeli committed 2018-02-13 13:33:15 +01:00
1 parent a4b88fc31b
commit d2cea84254
4 files changed
+64 -6

No files matched your search

+25 -5
View File
@@ -19,16 +19,17 @@ from tests.common import (
_LOGGER = logging.getLogger(__name__)
DOMAIN = "test_domain"
PLATFORM = 'test_platform'
class MockEntityPlatform(entity_platform.EntityPlatform):
"""Mock class with some mock defaults."""
def __init__(
self, *, hass,
self, hass,
logger=None,
domain='test',
platform_name='test_platform',
domain=DOMAIN,
platform_name=PLATFORM,
scan_interval=timedelta(seconds=15),
parallel_updates=0,
entity_namespace=None,
@@ -486,7 +487,26 @@ def test_overriding_name_from_registry(hass):
def test_registry_respect_entity_namespace(hass):
"""Test that the registry respects entity namespace."""
mock_registry(hass)
platform = MockEntityPlatform(hass=hass, entity_namespace='ns')
platform = MockEntityPlatform(hass, entity_namespace='ns')
entity = MockEntity(unique_id='1234', name='Device Name')
yield from platform.async_add_entities([entity])
assert entity.entity_id == 'test.ns_device_name'
assert entity.entity_id == 'test_domain.ns_device_name'
@asyncio.coroutine
def test_registry_respect_entity_disabled(hass):
"""Test that the registry respects entity disabled."""
mock_registry(hass, {
'test_domain.world': entity_registry.RegistryEntry(
entity_id='test_domain.world',
unique_id='1234',
# Using component.async_add_entities is equal to platform "domain"
platform='test_platform',
disabled_by=entity_registry.DISABLED_USER
)
})
platform = MockEntityPlatform(hass)
entity = MockEntity(unique_id='1234')
yield from platform.async_add_entities([entity])
assert entity.entity_id is None
assert hass.states.async_entity_ids() == []
+18
View File
@@ -148,6 +148,14 @@ test.named:
test.no_name:
platform: super_platform
unique_id: without-name
test.disabled_user:
platform: super_platform
unique_id: disabled-user
disabled_by: user
test.disabled_hass:
platform: super_platform
unique_id: disabled-hass
disabled_by: hass
"""
registry = entity_registry.EntityRegistry(hass)
@@ -162,3 +170,13 @@ test.no_name:
'test', 'super_platform', 'without-name')
assert entry_with_name.name == 'registry override'
assert entry_without_name.name is None
assert not entry_with_name.disabled
entry_disabled_hass = registry.async_get_or_create(
'test', 'super_platform', 'disabled-hass')
entry_disabled_user = registry.async_get_or_create(
'test', 'super_platform', 'disabled-user')
assert entry_disabled_hass.disabled
assert entry_disabled_hass.disabled_by == entity_registry.DISABLED_HASS
assert entry_disabled_user.disabled
assert entry_disabled_user.disabled_by == entity_registry.DISABLED_USER