Allow disabling entities in the registry (#12360)
This commit is contained in:
committed by
Pascal Vizeli
parent
a4b88fc31b
commit
d2cea84254
@@ -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() == []
|
||||
|
||||
Reference in New Issue
Block a user