Add Hue device info (#16267)
* Add Hue device info * Set with tuples * Fix tests
This commit is contained in:
1 parent
7751dd7535
commit
867d17b03d
3 files changed
+77
-6
No files matched your search
@@ -11,7 +11,8 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_FILENAME, CONF_HOST
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||
from homeassistant.helpers import (
|
||||
aiohttp_client, config_validation as cv, device_registry as dr)
|
||||
|
||||
from .const import DOMAIN, API_NUPNP
|
||||
from .bridge import HueBridge
|
||||
@@ -132,7 +133,28 @@ async def async_setup_entry(hass, entry):
|
||||
|
||||
bridge = HueBridge(hass, entry, allow_unreachable, allow_groups)
|
||||
hass.data[DOMAIN][host] = bridge
|
||||
return await bridge.async_setup()
|
||||
|
||||
if not await bridge.async_setup():
|
||||
return False
|
||||
|
||||
config = bridge.api.config
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry.async_get_or_create(
|
||||
config_entry=entry.entry_id,
|
||||
connections={
|
||||
(dr.CONNECTION_NETWORK_MAC, config.mac)
|
||||
},
|
||||
identifiers={
|
||||
(DOMAIN, config.bridgeid)
|
||||
},
|
||||
manufacturer='Signify',
|
||||
name=config.name,
|
||||
# Not yet exposed as properties in aiohue
|
||||
model=config.raw['modelid'],
|
||||
sw_version=config.raw['swversion'],
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, entry):
|
||||
|
||||
@@ -285,6 +285,25 @@ class HueLight(Light):
|
||||
"""Return the list of supported effects."""
|
||||
return [EFFECT_COLORLOOP, EFFECT_RANDOM]
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
if self.light.type in ('LightGroup', 'Room'):
|
||||
return None
|
||||
|
||||
return {
|
||||
'identifiers': {
|
||||
(hue.DOMAIN, self.unique_id)
|
||||
},
|
||||
'name': self.name,
|
||||
'manufacturer': self.light.manufacturername,
|
||||
# productname added in Hue Bridge API 1.24
|
||||
# (published 03/05/2018)
|
||||
'model': self.light.productname or self.light.modelid,
|
||||
# Not yet exposed as properties in aiohue
|
||||
'sw_version': self.light.raw['swversion'],
|
||||
}
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the specified or all lights on."""
|
||||
command = {'on': True}
|
||||
|
||||
Reference in new issue
Block a user