Use config entry to setup platforms (#13752)

* Use config entry to setup platforms

* Rename to async_forward_entry

* Add tests

* Catch if platform not exists for entry
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2018-04-09 10:09:08 -04:00
1 parent cb51553c2d
commit 73de749411
12 files changed
+271 -45

No files matched your search

+3 -4
View File
@@ -18,10 +18,9 @@ async def test_bridge_setup():
assert await hue_bridge.async_setup() is True
assert hue_bridge.api is api
assert len(hass.helpers.discovery.async_load_platform.mock_calls) == 1
assert hass.helpers.discovery.async_load_platform.mock_calls[0][1][2] == {
'host': '1.2.3.4'
}
assert len(hass.config_entries.async_forward_entry.mock_calls) == 1
assert hass.config_entries.async_forward_entry.mock_calls[0][1] == \
(entry, 'light')
async def test_bridge_setup_invalid_username():
+5 -2
View File
@@ -9,6 +9,7 @@ from aiohue.lights import Lights
from aiohue.groups import Groups
import pytest
from homeassistant import config_entries
from homeassistant.components import hue
import homeassistant.components.light.hue as hue_light
from homeassistant.util import color
@@ -196,9 +197,11 @@ async def setup_bridge(hass, mock_bridge):
"""Load the Hue light platform with the provided bridge."""
hass.config.components.add(hue.DOMAIN)
hass.data[hue.DOMAIN] = {'mock-host': mock_bridge}
await hass.helpers.discovery.async_load_platform('light', 'hue', {
config_entry = config_entries.ConfigEntry(1, hue.DOMAIN, 'Mock Title', {
'host': 'mock-host'
})
}, 'test')
await hass.config_entries.async_forward_entry(config_entry, 'light')
# To flush out the service call to update the group
await hass.async_block_till_done()