Skip to content

Commit

Permalink
Support device registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 committed Aug 21, 2018
1 parent 7ed8ed8 commit b10417f
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 3 deletions.
18 changes: 18 additions & 0 deletions homeassistant/components/binary_sensor/deconz.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,21 @@ def device_state_attributes(self):
if self._sensor.type in PRESENCE and self._sensor.dark is not None:
attr[ATTR_DARK] = self._sensor.dark
return attr

@property
def device(self):
"""Description for device registry."""
if (self._sensor.uniqueid is not None and
self._sensor.uniqueid.count(':') == 7):
serial = self._sensor.uniqueid.split('-', 1)[0]
else:
return None
dev = {
'identifiers': [['serial', serial]],
'manufacturer': self._sensor.manufacturer,
'model': self._sensor.modelid,
'connection': [['Zigbee', serial]],
'name': self._sensor.name,
'sw_version': self._sensor.swversion,
}
return dev
9 changes: 8 additions & 1 deletion homeassistant/components/deconz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
CONF_ALLOW_CLIP_SENSOR, CONFIG_FILE, DATA_DECONZ_EVENT,
DATA_DECONZ_ID, DATA_DECONZ_UNSUB, DOMAIN, _LOGGER)

REQUIREMENTS = ['pydeconz==43']
REQUIREMENTS = ['pydeconz==44']

CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
Expand Down Expand Up @@ -119,6 +119,13 @@ def async_add_remote(sensors):

deconz.start()

device_registry = await \
hass.helpers.device_registry.async_get_registry()
device_registry.async_get_or_create(
[['bridgeid', deconz.config.bridgeid]], 'Dresden Elektronik',
deconz.config.modelid, [['Ethernet', deconz.config.mac]],
name=deconz.config.name, sw_version=deconz.config.swversion)

async def async_configure(call):
"""Set attribute of device in deCONZ.
Expand Down
18 changes: 18 additions & 0 deletions homeassistant/components/light/deconz.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,21 @@ def device_state_attributes(self):
if self._light.type == 'LightGroup':
attributes['all_on'] = self._light.all_on
return attributes

@property
def device(self):
"""Description for device registry."""
if (self._light.uniqueid is not None and
self._light.uniqueid.count(':') == 7):
serial = self._light.uniqueid.split('-', 1)[0]
else:
return None
dev = {
'identifiers': [['serial', serial]],
'manufacturer': self._light.manufacturer,
'model': self._light.modelid,
'connection': [['Zigbee', serial]],
'name': self._light.name,
'sw_version': self._light.swversion,
}
return dev
36 changes: 36 additions & 0 deletions homeassistant/components/sensor/deconz.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ def device_state_attributes(self):
attr[ATTR_DAYLIGHT] = self._sensor.daylight
return attr

@property
def device(self):
""""""
if (self._sensor.uniqueid is not None and
self._sensor.uniqueid.count(':') == 7):
serial = self._sensor.uniqueid.split('-', 1)[0]
else:
return None
dev = {
'identifiers': [['serial', serial]],
'manufacturer': self._sensor.manufacturer,
'model': self._sensor.modelid,
'connection': [['Zigbee', serial]],
'name': self._sensor.name,
'sw_version': self._sensor.swversion,
}
return dev


class DeconzBattery(Entity):
"""Battery class for when a device is only represented as an event."""
Expand Down Expand Up @@ -192,3 +210,21 @@ def device_state_attributes(self):
ATTR_EVENT_ID: slugify(self._device.name),
}
return attr

@property
def device(self):
"""Description for device registry."""
if (self._device.uniqueid is not None and
self._device.uniqueid.count(':') == 7):
serial = self._device.uniqueid.split('-', 1)[0]
else:
return None
dev = {
'identifiers': [['serial', serial]],
'manufacturer': self._device.manufacturer,
'model': self._device.modelid,
'connection': [['Zigbee', serial]],
'name': self._device.name,
'sw_version': self._device.swversion,
}
return dev
18 changes: 18 additions & 0 deletions homeassistant/components/switch/deconz.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ def should_poll(self):
"""No polling needed."""
return False

@property
def device(self):
"""Description for device registry."""
if (self._switch.uniqueid is not None and
self._switch.uniqueid.count(':') == 7):
serial = self._switch.uniqueid.split('-', 1)[0]
else:
return None
dev = {
'identifiers': [['serial', serial]],
'manufacturer': self._switch.manufacturer,
'model': self._switch.modelid,
'connection': [['Zigbee', serial]],
'name': self._switch.name,
'sw_version': self._switch.swversion,
}
return dev


class DeconzPowerPlug(DeconzSwitch):
"""Representation of power plugs from deCONZ."""
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ pycsspeechtts==1.0.2
pydaikin==0.4

# homeassistant.components.deconz
pydeconz==43
pydeconz==44

# homeassistant.components.zwave
pydispatcher==2.0.5
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ py-canary==0.5.0
pyblackbird==0.5

# homeassistant.components.deconz
pydeconz==43
pydeconz==44

# homeassistant.components.zwave
pydispatcher==2.0.5
Expand Down

0 comments on commit b10417f

Please sign in to comment.