diff --git a/homeassistant/components/light/tradfri.py b/homeassistant/components/light/tradfri.py index bd432b5dedc..b62900b204c 100644 --- a/homeassistant/components/light/tradfri.py +++ b/homeassistant/components/light/tradfri.py @@ -13,7 +13,8 @@ from homeassistant.components.light import ( SUPPORT_COLOR, Light) from homeassistant.components.light import \ PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA -from homeassistant.components.tradfri import KEY_GATEWAY, KEY_API +from homeassistant.components.tradfri import ( + KEY_GATEWAY, KEY_API, DOMAIN as TRADFRI_DOMAIN) from homeassistant.components.tradfri.const import ( CONF_IMPORT_GROUPS, CONF_GATEWAY_ID) import homeassistant.util.color as color_util @@ -161,6 +162,7 @@ class TradfriLight(Light): self._hs_color = None self._features = SUPPORTED_FEATURES self._available = True + self._gateway_id = gateway_id self._refresh(light) @@ -169,6 +171,22 @@ class TradfriLight(Light): """Return unique ID for light.""" return self._unique_id + @property + def device_info(self): + """Return the device info.""" + info = self._light.device_info + + return { + 'identifiers': { + (TRADFRI_DOMAIN, self._light.id) + }, + 'name': self._name, + 'manufacturer': info.manufacturer, + 'model': info.model_number, + 'sw_version': info.firmware_version, + 'via_hub': (TRADFRI_DOMAIN, self._gateway_id), + } + @property def min_mireds(self): """Return the coldest color_temp that this light supports.""" diff --git a/homeassistant/components/nest/local_auth.py b/homeassistant/components/nest/local_auth.py index 5ab10cc2a5e..393a36e4a9c 100644 --- a/homeassistant/components/nest/local_auth.py +++ b/homeassistant/components/nest/local_auth.py @@ -11,7 +11,8 @@ from .const import DOMAIN def initialize(hass, client_id, client_secret): """Initialize a local auth provider.""" config_flow.register_flow_implementation( - hass, DOMAIN, 'local', partial(generate_auth_url, client_id), + hass, DOMAIN, 'configuration.yaml', + partial(generate_auth_url, client_id), partial(resolve_auth_code, hass, client_id, client_secret) ) diff --git a/homeassistant/components/tradfri/__init__.py b/homeassistant/components/tradfri/__init__.py index 771f2b44c3d..079381f8b45 100644 --- a/homeassistant/components/tradfri/__init__.py +++ b/homeassistant/components/tradfri/__init__.py @@ -12,7 +12,8 @@ from homeassistant import config_entries import homeassistant.helpers.config_validation as cv from homeassistant.util.json import load_json -from .const import CONF_IMPORT_GROUPS, CONF_IDENTITY, CONF_HOST, CONF_KEY +from .const import ( + CONF_IMPORT_GROUPS, CONF_IDENTITY, CONF_HOST, CONF_KEY, CONF_GATEWAY_ID) from . import config_flow # noqa pylint_disable=unused-import @@ -84,7 +85,7 @@ async def async_setup_entry(hass, entry): gateway = Gateway() try: - await api(gateway.get_gateway_info()) + gateway_info = await api(gateway.get_gateway_info()) except RequestError: _LOGGER.error("Tradfri setup failed.") return False @@ -92,6 +93,20 @@ async def async_setup_entry(hass, entry): hass.data.setdefault(KEY_API, {})[entry.entry_id] = api hass.data.setdefault(KEY_GATEWAY, {})[entry.entry_id] = gateway + dev_reg = await hass.helpers.device_registry.async_get_registry() + dev_reg.async_get_or_create( + config_entry_id=entry.entry_id, + connections=set(), + identifiers={ + (DOMAIN, entry.data[CONF_GATEWAY_ID]) + }, + manufacturer='IKEA', + name='Gateway', + # They just have 1 gateway model. Type is not exposed yet. + model='E1526', + sw_version=gateway_info.firmware_version, + ) + hass.async_create_task(hass.config_entries.async_forward_entry_setup( entry, 'light' )) diff --git a/tests/common.py b/tests/common.py index 56e86a4cd5c..287f1e24ee5 100644 --- a/tests/common.py +++ b/tests/common.py @@ -322,7 +322,7 @@ def mock_component(hass, component): def mock_registry(hass, mock_entries=None): """Mock the Entity Registry.""" registry = entity_registry.EntityRegistry(hass) - registry.entities = mock_entries or {} + registry.entities = mock_entries or OrderedDict() async def _get_reg(): return registry