Skip to content

Commit

Permalink
Entity registry (#11979)
Browse files Browse the repository at this point in the history
* Entity#unique_id defaults to None

* Initial commit entity registry

* Clean up unique_id property

* Lint

* Add tests to entity component

* Lint

* Restore some unique ids

* Spelling

* Remove use of IP address for unique ID

* Add tests

* Add tests

* Fix tests

* Add some docs

* Add one more test

* Fix new test…
  • Loading branch information
balloob authored and pvizeli committed Jan 30, 2018
1 parent 8e441ba commit e51427b
Show file tree
Hide file tree
Showing 47 changed files with 471 additions and 230 deletions.
6 changes: 0 additions & 6 deletions homeassistant/components/binary_sensor/bloomsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,13 @@ def __init__(self, bs, device, sensor_name):
self._device_id = device['DeviceID']
self._sensor_name = sensor_name
self._name = '{} {}'.format(device['DeviceName'], sensor_name)
self._unique_id = 'bloomsky_binary_sensor {}'.format(self._name)
self._state = None

@property
def name(self):
"""Return the name of the BloomSky device and this sensor."""
return self._name

@property
def unique_id(self):
"""Return the unique ID for this sensor."""
return self._unique_id

@property
def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/binary_sensor/ecobee.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ def is_on(self):
"""Return the status of the sensor."""
return self._state == 'true'

@property
def unique_id(self):
"""Return the unique ID of this sensor."""
return "binary_sensor_ecobee_{}_{}".format(self._name, self.index)

@property
def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/hikvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def name(self):
@property
def unique_id(self):
"""Return an unique ID."""
return '{}.{}'.format(self.__class__, self._id)
return self._id

@property
def is_on(self):
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/binary_sensor/netatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ def __init__(self, data, camera_name, module_name, home,
self._name += ' / ' + module_name
self._sensor_name = sensor
self._name += ' ' + sensor
camera_id = data.camera_data.cameraByName(
self._unique_id = data.camera_data.cameraByName(
camera=camera_name, home=home)['id']
self._unique_id = "Netatmo_binary_sensor {0} - {1}".format(
self._name, camera_id)
self._cameratype = camera_type
self._state = None

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/wemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def should_poll(self):
@property
def unique_id(self):
"""Return the id of this WeMo device."""
return '{}.{}'.format(self.__class__, self.wemo.serialnumber)
return self.wemo.serialnumber

@property
def name(self):
Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/camera/netatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ def __init__(self, data, camera_name, home, camera_type, verify_ssl):
self._name = home + ' / ' + camera_name
else:
self._name = camera_name
camera_id = data.camera_data.cameraByName(
camera=camera_name, home=home)['id']
self._unique_id = "Welcome_camera {0} - {1}".format(
self._name, camera_id)
self._vpnurl, self._localurl = self._data.camera_data.cameraUrls(
camera=camera_name
)
self._unique_id = data.camera_data.cameraByName(
camera=camera_name, home=home)['id']
self._cameratype = camera_type

def camera_image(self):
Expand Down Expand Up @@ -117,5 +115,5 @@ def model(self):

@property
def unique_id(self):
"""Return the unique ID for this sensor."""
"""Return the unique ID for this camera."""
return self._unique_id
5 changes: 0 additions & 5 deletions homeassistant/components/climate/daikin.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ def set(self, settings):
self._force_refresh = True
self._api.device.set(values)

@property
def unique_id(self):
"""Return the ID of this AC."""
return "{}.{}".format(self.__class__, self._api.ip_address)

@property
def supported_features(self):
"""Return the list of supported features."""
Expand Down
5 changes: 5 additions & 0 deletions homeassistant/components/climate/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS

@property
def unique_id(self):
"""Unique ID for this device."""
return self.device.serial

@property
def name(self):
"""Return the name of the nest, if any."""
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/cover/rpi_gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ def __init__(self, name, relay_pin, state_pin, state_pull_mode,
rpi_gpio.setup_input(self._state_pin, self._state_pull_mode)
rpi_gpio.write_output(self._relay_pin, not self._invert_relay)

@property
def unique_id(self):
"""Return the ID of this cover."""
return '{}.{}'.format(self.__class__, self._name)

@property
def name(self):
"""Return the name of the cover if any."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/fan/insteon_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def name(self):
@property
def unique_id(self):
"""Return the ID of this Insteon node."""
return 'insteon_local_{}_fan'.format(self.node.device_id)
return self.node.device_id

@property
def speed(self) -> str:
Expand Down
7 changes: 1 addition & 6 deletions homeassistant/components/group/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ def visibility_service_handler(service):
@asyncio.coroutine
def _async_process_config(hass, config, component):
"""Process group configuration."""
groups = []
for object_id, conf in config.get(DOMAIN, {}).items():
name = conf.get(CONF_NAME, object_id)
entity_ids = conf.get(CONF_ENTITIES) or []
Expand All @@ -381,13 +380,9 @@ def _async_process_config(hass, config, component):

# Don't create tasks and await them all. The order is important as
# groups get a number based on creation order.
group = yield from Group.async_create_group(
yield from Group.async_create_group(
hass, name, entity_ids, icon=icon, view=view,
control=control, object_id=object_id)
groups.append(group)

if groups:
yield from component.async_add_entities(groups)


class Group(Entity):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/light/avion.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, device):
@property
def unique_id(self):
"""Return the ID of this light."""
return "{}.{}".format(self.__class__, self._address)
return self._address

@property
def name(self):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/light/decora.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self, device):
@property
def unique_id(self):
"""Return the ID of this light."""
return "{}.{}".format(self.__class__, self._address)
return self._address

@property
def name(self):
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/light/flux_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ def available(self) -> bool:
"""Return True if entity is available."""
return self._bulb is not None

@property
def unique_id(self):
"""Return the ID of this light."""
return '{}.{}'.format(self.__class__, self._ipaddr)

@property
def name(self):
"""Return the name of the device if any."""
Expand Down
9 changes: 1 addition & 8 deletions homeassistant/components/light/hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,7 @@ def __init__(self, light_id, info, bridge, update_lights_cb,
@property
def unique_id(self):
"""Return the ID of this Hue light."""
lid = self.info.get('uniqueid')

if lid is None:
default_type = 'Group' if self.is_group else 'Light'
ltype = self.info.get('type', default_type)
lid = '{}.{}.{}'.format(self.name, ltype, self.light_id)

return '{}.{}'.format(self.__class__, lid)
return self.info.get('uniqueid')

@property
def name(self):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/light/insteon_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def name(self):
@property
def unique_id(self):
"""Return the ID of this Insteon node."""
return 'insteon_local_{}'.format(self.node.device_id)
return self.node.device_id

@property
def brightness(self):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/light/tikteck.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, device):
@property
def unique_id(self):
"""Return the ID of this light."""
return "{}.{}".format(self.__class__, self._address)
return self._address

@property
def name(self):
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/light/wemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def __init__(self, device, update_lights):
@property
def unique_id(self):
"""Return the ID of this light."""
deviceid = self.device.uniqueID
return '{}.{}'.format(self.__class__, deviceid)
return self.device.uniqueID

@property
def name(self):
Expand Down Expand Up @@ -176,7 +175,7 @@ def _update_callback(self, _device, _type, _params):
@property
def unique_id(self):
"""Return the ID of this WeMo dimmer."""
return "{}.{}".format(self.__class__, self.wemo.serialnumber)
return self.wemo.serialnumber

@property
def name(self):
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/light/yeelight.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ def effect_list(self):
"""Return the list of supported effects."""
return YEELIGHT_EFFECT_LIST

@property
def unique_id(self) -> str:
"""Return the ID of this light."""
return "{}.{}".format(self.__class__, self._ipaddr)

@property
def color_temp(self) -> int:
"""Return the color temperature."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/light/zengge.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, device):
@property
def unique_id(self):
"""Return the ID of this light."""
return "{}.{}".format(self.__class__, self._address)
return self._address

@property
def name(self):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/media_player/emby.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def set_available(self, value):
@property
def unique_id(self):
"""Return the id of this emby client."""
return '{}.{}'.format(self.__class__, self.device_id)
return self.device_id

@property
def supports_remote_control(self):
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/media_player/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ def force_idle(self):
@property
def unique_id(self):
"""Return the id of this plex client."""
return '{}.{}'.format(self.__class__, self.machine_identifier or
self.name)
return self.machine_identifier

@property
def name(self):
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/media_player/yamaha.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ def __init__(self, name, receiver, source_ignore,
self._name = name
self._zone = receiver.zone

@property
def unique_id(self):
"""Return an unique ID."""
return '{0}:{1}'.format(self.receiver.ctrl_url, self._zone)

def update(self):
"""Get the latest details from the device."""
self._play_status = self.receiver.play_status()
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/sensor/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ def state(self):
"""Return the camera's current state."""
return self._state

@property
def unique_id(self):
"""Return the unique camera sensor identifier."""
return "sensor_{}_{}".format(self._name, self.index)

@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
Expand Down
6 changes: 0 additions & 6 deletions homeassistant/components/sensor/bloomsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,13 @@ def __init__(self, bs, device, sensor_name):
self._device_id = device['DeviceID']
self._sensor_name = sensor_name
self._name = '{} {}'.format(device['DeviceName'], sensor_name)
self._unique_id = 'bloomsky_sensor {}'.format(self._name)
self._state = None

@property
def name(self):
"""Return the name of the BloomSky device and this sensor."""
return self._name

@property
def unique_id(self):
"""Return the unique ID for this sensor."""
return self._unique_id

@property
def state(self):
"""Return the current state, eg. value, of this sensor."""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/sensor/canary.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def state(self):
@property
def unique_id(self):
"""Return the unique ID of this sensor."""
return "sensor_canary_{}_{}".format(self._device_id,
self._sensor_type[0])
return "{}_{}".format(self._device_id, self._sensor_type[0])

@property
def unit_of_measurement(self):
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/sensor/daikin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ def get(self, key):

return value

@property
def unique_id(self):
"""Return the ID of this AC."""
return "{}.{}".format(self.__class__, self._api.ip_address)

@property
def icon(self):
"""Icon to use in the frontend, if any."""
Expand Down
7 changes: 1 addition & 6 deletions homeassistant/components/sensor/ecobee.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,13 @@ def __init__(self, sensor_name, sensor_type, sensor_index):
@property
def name(self):
"""Return the name of the Ecobee sensor."""
return self._name.rstrip()
return self._name

@property
def state(self):
"""Return the state of the sensor."""
return self._state

@property
def unique_id(self):
"""Return the unique ID of this sensor."""
return "sensor_ecobee_{}_{}".format(self._name, self.index)

@property
def unit_of_measurement(self):
"""Return the unit of measurement this sensor expresses itself in."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def state(self):
def unique_id(self):
"""Return the unique ID of this sensor."""
device_id = self._device[ios.ATTR_DEVICE_ID]
return "sensor_ios_battery_{}_{}".format(self.type, device_id)
return "{}_{}".format(self.type, device_id)

@property
def unit_of_measurement(self):
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/sensor/isy994.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,6 @@ def __init__(self, node) -> None:
"""Initialize the ISY994 weather device."""
super().__init__(node)

@property
def unique_id(self) -> str:
"""Return the unique identifier for the node."""
return self._node.name

@property
def raw_units(self) -> str:
"""Return the raw unit of measurement."""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/sensor/netatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ def __init__(self, netatmo_data, module_name, sensor_type):
module_id = self.netatmo_data.\
station_data.moduleByName(module=module_name)['_id']
self.module_id = module_id[1]
self._unique_id = "Netatmo Sensor {0} - {1} ({2})".format(
self._name, module_id, self.type)
self._unique_id = '{}-{}'.format(self.module_id, self.type)

@property
def name(self):
Expand Down
Loading

0 comments on commit e51427b

Please sign in to comment.