From 10f5e9744b8c39e39ef7b8246d1a513b03218cd6 Mon Sep 17 00:00:00 2001 From: Greg Dowling Date: Sat, 11 Mar 2017 18:06:46 +0000 Subject: [PATCH] Append vera device id to entity id - but not name. (#6523) * Append vera device id to entity id - but not name. * Tidy. * Tidy. * Tidy after review. * Re-order. --- homeassistant/components/binary_sensor/vera.py | 5 +++-- homeassistant/components/climate/vera.py | 5 +++-- homeassistant/components/cover/vera.py | 5 +++-- homeassistant/components/light/vera.py | 5 +++-- homeassistant/components/lock/vera.py | 5 +++-- homeassistant/components/sensor/vera.py | 4 +++- homeassistant/components/switch/vera.py | 5 +++-- homeassistant/components/vera.py | 8 ++++++-- 8 files changed, 27 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/binary_sensor/vera.py b/homeassistant/components/binary_sensor/vera.py index ce2b8b715bd..e16f4e17fa0 100644 --- a/homeassistant/components/binary_sensor/vera.py +++ b/homeassistant/components/binary_sensor/vera.py @@ -7,9 +7,9 @@ https://home-assistant.io/components/binary_sensor.vera/ import logging from homeassistant.components.binary_sensor import ( - BinarySensorDevice) + BinarySensorDevice, ENTITY_ID_FORMAT) from homeassistant.components.vera import ( - VeraDevice, VERA_DEVICES, VERA_CONTROLLER) + VERA_CONTROLLER, VERA_DEVICES, VeraDevice) DEPENDENCIES = ['vera'] @@ -30,6 +30,7 @@ class VeraBinarySensor(VeraDevice, BinarySensorDevice): """Initialize the binary_sensor.""" self._state = False VeraDevice.__init__(self, vera_device, controller) + self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) @property def is_on(self): diff --git a/homeassistant/components/climate/vera.py b/homeassistant/components/climate/vera.py index fa4244497e6..ffedcb82602 100644 --- a/homeassistant/components/climate/vera.py +++ b/homeassistant/components/climate/vera.py @@ -7,14 +7,14 @@ https://home-assistant.io/components/switch.vera/ import logging from homeassistant.util import convert -from homeassistant.components.climate import ClimateDevice +from homeassistant.components.climate import ClimateDevice, ENTITY_ID_FORMAT from homeassistant.const import ( TEMP_FAHRENHEIT, TEMP_CELSIUS, ATTR_TEMPERATURE) from homeassistant.components.vera import ( - VeraDevice, VERA_DEVICES, VERA_CONTROLLER) + VERA_CONTROLLER, VERA_DEVICES, VeraDevice) DEPENDENCIES = ['vera'] @@ -37,6 +37,7 @@ class VeraThermostat(VeraDevice, ClimateDevice): def __init__(self, vera_device, controller): """Initialize the Vera device.""" VeraDevice.__init__(self, vera_device, controller) + self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) @property def current_operation(self): diff --git a/homeassistant/components/cover/vera.py b/homeassistant/components/cover/vera.py index 2c26fbf1723..48abe373eac 100644 --- a/homeassistant/components/cover/vera.py +++ b/homeassistant/components/cover/vera.py @@ -6,9 +6,9 @@ https://home-assistant.io/components/cover.vera/ """ import logging -from homeassistant.components.cover import CoverDevice +from homeassistant.components.cover import CoverDevice, ENTITY_ID_FORMAT from homeassistant.components.vera import ( - VeraDevice, VERA_DEVICES, VERA_CONTROLLER) + VERA_CONTROLLER, VERA_DEVICES, VeraDevice) DEPENDENCIES = ['vera'] @@ -28,6 +28,7 @@ class VeraCover(VeraDevice, CoverDevice): def __init__(self, vera_device, controller): """Initialize the Vera device.""" VeraDevice.__init__(self, vera_device, controller) + self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) @property def current_cover_position(self): diff --git a/homeassistant/components/light/vera.py b/homeassistant/components/light/vera.py index 0508e654f43..ac459ce38ff 100644 --- a/homeassistant/components/light/vera.py +++ b/homeassistant/components/light/vera.py @@ -7,10 +7,10 @@ https://home-assistant.io/components/light.vera/ import logging from homeassistant.components.light import ( - ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light) + ATTR_BRIGHTNESS, ENTITY_ID_FORMAT, Light, SUPPORT_BRIGHTNESS) from homeassistant.const import (STATE_OFF, STATE_ON) from homeassistant.components.vera import ( - VeraDevice, VERA_DEVICES, VERA_CONTROLLER) + VERA_CONTROLLER, VERA_DEVICES, VeraDevice) _LOGGER = logging.getLogger(__name__) @@ -33,6 +33,7 @@ class VeraLight(VeraDevice, Light): """Initialize the light.""" self._state = False VeraDevice.__init__(self, vera_device, controller) + self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) @property def brightness(self): diff --git a/homeassistant/components/lock/vera.py b/homeassistant/components/lock/vera.py index 14606c0853c..da2a465d570 100644 --- a/homeassistant/components/lock/vera.py +++ b/homeassistant/components/lock/vera.py @@ -6,10 +6,10 @@ https://home-assistant.io/components/lock.vera/ """ import logging -from homeassistant.components.lock import LockDevice +from homeassistant.components.lock import ENTITY_ID_FORMAT, LockDevice from homeassistant.const import (STATE_LOCKED, STATE_UNLOCKED) from homeassistant.components.vera import ( - VeraDevice, VERA_DEVICES, VERA_CONTROLLER) + VERA_CONTROLLER, VERA_DEVICES, VeraDevice) _LOGGER = logging.getLogger(__name__) @@ -30,6 +30,7 @@ class VeraLock(VeraDevice, LockDevice): """Initialize the Vera device.""" self._state = None VeraDevice.__init__(self, vera_device, controller) + self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) def lock(self, **kwargs): """Lock the device.""" diff --git a/homeassistant/components/sensor/vera.py b/homeassistant/components/sensor/vera.py index eeec43bfb40..81f69001f82 100644 --- a/homeassistant/components/sensor/vera.py +++ b/homeassistant/components/sensor/vera.py @@ -9,8 +9,9 @@ import logging from homeassistant.const import ( TEMP_CELSIUS, TEMP_FAHRENHEIT) from homeassistant.helpers.entity import Entity +from homeassistant.components.sensor import ENTITY_ID_FORMAT from homeassistant.components.vera import ( - VeraDevice, VERA_DEVICES, VERA_CONTROLLER) + VERA_CONTROLLER, VERA_DEVICES, VeraDevice) DEPENDENCIES = ['vera'] @@ -32,6 +33,7 @@ class VeraSensor(VeraDevice, Entity): self.current_value = None self._temperature_units = None VeraDevice.__init__(self, vera_device, controller) + self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) @property def state(self): diff --git a/homeassistant/components/switch/vera.py b/homeassistant/components/switch/vera.py index 8ab66b75fff..a5b90e3eba2 100644 --- a/homeassistant/components/switch/vera.py +++ b/homeassistant/components/switch/vera.py @@ -7,10 +7,10 @@ https://home-assistant.io/components/switch.vera/ import logging from homeassistant.util import convert -from homeassistant.components.switch import SwitchDevice +from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchDevice from homeassistant.const import (STATE_OFF, STATE_ON) from homeassistant.components.vera import ( - VeraDevice, VERA_DEVICES, VERA_CONTROLLER) + VERA_CONTROLLER, VERA_DEVICES, VeraDevice) DEPENDENCIES = ['vera'] @@ -31,6 +31,7 @@ class VeraSwitch(VeraDevice, SwitchDevice): """Initialize the Vera device.""" self._state = False VeraDevice.__init__(self, vera_device, controller) + self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) def turn_on(self, **kwargs): """Turn device on.""" diff --git a/homeassistant/components/vera.py b/homeassistant/components/vera.py index 7c2c7b744f9..d596db0d25b 100644 --- a/homeassistant/components/vera.py +++ b/homeassistant/components/vera.py @@ -12,7 +12,7 @@ import voluptuous as vol from requests.exceptions import RequestException from homeassistant.util.dt import utc_from_timestamp -from homeassistant.util import convert +from homeassistant.util import (convert, slugify) from homeassistant.helpers import discovery from homeassistant.helpers import config_validation as cv from homeassistant.const import ( @@ -32,6 +32,8 @@ CONF_CONTROLLER = 'vera_controller_url' CONF_EXCLUDE = 'exclude' CONF_LIGHTS = 'lights' +VERA_ID_FORMAT = '{}_{}' + ATTR_CURRENT_POWER_MWH = "current_power_mwh" VERA_DEVICES = defaultdict(list) @@ -131,8 +133,10 @@ class VeraDevice(Entity): self.vera_device = vera_device self.controller = controller + self._name = self.vera_device.name # Append device id to prevent name clashes in HA. - self._name = self.vera_device.name + ' ' + str(vera_device.device_id) + self.vera_id = VERA_ID_FORMAT.format( + slugify(vera_device.name), vera_device.device_id) self.controller.register(vera_device, self._update_callback) self.update()