Add tradfri device info (#16768)
This commit is contained in:
parent
a0a54dfd5b
commit
3e59ffb33a
4 changed files with 39 additions and 5 deletions
|
@ -13,7 +13,8 @@ from homeassistant.components.light import (
|
||||||
SUPPORT_COLOR, Light)
|
SUPPORT_COLOR, Light)
|
||||||
from homeassistant.components.light import \
|
from homeassistant.components.light import \
|
||||||
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA
|
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 (
|
from homeassistant.components.tradfri.const import (
|
||||||
CONF_IMPORT_GROUPS, CONF_GATEWAY_ID)
|
CONF_IMPORT_GROUPS, CONF_GATEWAY_ID)
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
|
@ -161,6 +162,7 @@ class TradfriLight(Light):
|
||||||
self._hs_color = None
|
self._hs_color = None
|
||||||
self._features = SUPPORTED_FEATURES
|
self._features = SUPPORTED_FEATURES
|
||||||
self._available = True
|
self._available = True
|
||||||
|
self._gateway_id = gateway_id
|
||||||
|
|
||||||
self._refresh(light)
|
self._refresh(light)
|
||||||
|
|
||||||
|
@ -169,6 +171,22 @@ class TradfriLight(Light):
|
||||||
"""Return unique ID for light."""
|
"""Return unique ID for light."""
|
||||||
return self._unique_id
|
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
|
@property
|
||||||
def min_mireds(self):
|
def min_mireds(self):
|
||||||
"""Return the coldest color_temp that this light supports."""
|
"""Return the coldest color_temp that this light supports."""
|
||||||
|
|
|
@ -11,7 +11,8 @@ from .const import DOMAIN
|
||||||
def initialize(hass, client_id, client_secret):
|
def initialize(hass, client_id, client_secret):
|
||||||
"""Initialize a local auth provider."""
|
"""Initialize a local auth provider."""
|
||||||
config_flow.register_flow_implementation(
|
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)
|
partial(resolve_auth_code, hass, client_id, client_secret)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@ from homeassistant import config_entries
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util.json import load_json
|
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
|
from . import config_flow # noqa pylint_disable=unused-import
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ async def async_setup_entry(hass, entry):
|
||||||
gateway = Gateway()
|
gateway = Gateway()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await api(gateway.get_gateway_info())
|
gateway_info = await api(gateway.get_gateway_info())
|
||||||
except RequestError:
|
except RequestError:
|
||||||
_LOGGER.error("Tradfri setup failed.")
|
_LOGGER.error("Tradfri setup failed.")
|
||||||
return False
|
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_API, {})[entry.entry_id] = api
|
||||||
hass.data.setdefault(KEY_GATEWAY, {})[entry.entry_id] = gateway
|
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(
|
hass.async_create_task(hass.config_entries.async_forward_entry_setup(
|
||||||
entry, 'light'
|
entry, 'light'
|
||||||
))
|
))
|
||||||
|
|
|
@ -322,7 +322,7 @@ def mock_component(hass, component):
|
||||||
def mock_registry(hass, mock_entries=None):
|
def mock_registry(hass, mock_entries=None):
|
||||||
"""Mock the Entity Registry."""
|
"""Mock the Entity Registry."""
|
||||||
registry = entity_registry.EntityRegistry(hass)
|
registry = entity_registry.EntityRegistry(hass)
|
||||||
registry.entities = mock_entries or {}
|
registry.entities = mock_entries or OrderedDict()
|
||||||
|
|
||||||
async def _get_reg():
|
async def _get_reg():
|
||||||
return registry
|
return registry
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue