Store config entry id in entity registry (#14851)

* Store config entry id in entity registry

* Lint
This commit is contained in:
Paulus Schoutsen 2018-06-07 14:23:09 -04:00 committed by Pascal Vizeli
parent bb4d1773d3
commit 67d137cfd5
4 changed files with 31 additions and 8 deletions

View file

@ -16,7 +16,7 @@ import homeassistant.util.dt as dt_util
from tests.common import (
get_test_home_assistant, MockPlatform, fire_time_changed, mock_registry,
MockEntity, MockEntityPlatform, MockConfigEntry, mock_coro)
MockEntity, MockEntityPlatform, MockConfigEntry)
_LOGGER = logging.getLogger(__name__)
DOMAIN = "test_domain"
@ -516,11 +516,19 @@ async def test_entity_registry_updates(hass):
async def test_setup_entry(hass):
"""Test we can setup an entry."""
async_setup_entry = Mock(return_value=mock_coro(True))
registry = mock_registry(hass)
async def async_setup_entry(hass, config_entry, async_add_devices):
"""Mock setup entry method."""
async_add_devices([
MockEntity(name='test1', unique_id='unique')
])
return True
platform = MockPlatform(
async_setup_entry=async_setup_entry
)
config_entry = MockConfigEntry()
config_entry = MockConfigEntry(entry_id='super-mock-id')
entity_platform = MockEntityPlatform(
hass,
platform_name=config_entry.domain,
@ -528,10 +536,13 @@ async def test_setup_entry(hass):
)
assert await entity_platform.async_setup_entry(config_entry)
await hass.async_block_till_done()
full_name = '{}.{}'.format(entity_platform.domain, config_entry.domain)
assert full_name in hass.config.components
assert len(async_setup_entry.mock_calls) == 1
assert len(hass.states.async_entity_ids()) == 1
assert len(registry.entities) == 1
assert registry.entities['test_domain.test1'].config_entry_id == \
'super-mock-id'
async def test_setup_entry_platform_not_ready(hass, caplog):