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.
This commit is contained in:
parent
b2a2193ba3
commit
10f5e9744b
8 changed files with 27 additions and 15 deletions
|
@ -7,9 +7,9 @@ https://home-assistant.io/components/binary_sensor.vera/
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDevice)
|
BinarySensorDevice, ENTITY_ID_FORMAT)
|
||||||
from homeassistant.components.vera import (
|
from homeassistant.components.vera import (
|
||||||
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
|
||||||
|
|
||||||
DEPENDENCIES = ['vera']
|
DEPENDENCIES = ['vera']
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ class VeraBinarySensor(VeraDevice, BinarySensorDevice):
|
||||||
"""Initialize the binary_sensor."""
|
"""Initialize the binary_sensor."""
|
||||||
self._state = False
|
self._state = False
|
||||||
VeraDevice.__init__(self, vera_device, controller)
|
VeraDevice.__init__(self, vera_device, controller)
|
||||||
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
|
|
@ -7,14 +7,14 @@ https://home-assistant.io/components/switch.vera/
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.util import convert
|
from homeassistant.util import convert
|
||||||
from homeassistant.components.climate import ClimateDevice
|
from homeassistant.components.climate import ClimateDevice, ENTITY_ID_FORMAT
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
ATTR_TEMPERATURE)
|
ATTR_TEMPERATURE)
|
||||||
|
|
||||||
from homeassistant.components.vera import (
|
from homeassistant.components.vera import (
|
||||||
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
|
||||||
|
|
||||||
DEPENDENCIES = ['vera']
|
DEPENDENCIES = ['vera']
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ class VeraThermostat(VeraDevice, ClimateDevice):
|
||||||
def __init__(self, vera_device, controller):
|
def __init__(self, vera_device, controller):
|
||||||
"""Initialize the Vera device."""
|
"""Initialize the Vera device."""
|
||||||
VeraDevice.__init__(self, vera_device, controller)
|
VeraDevice.__init__(self, vera_device, controller)
|
||||||
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_operation(self):
|
def current_operation(self):
|
||||||
|
|
|
@ -6,9 +6,9 @@ https://home-assistant.io/components/cover.vera/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.cover import CoverDevice
|
from homeassistant.components.cover import CoverDevice, ENTITY_ID_FORMAT
|
||||||
from homeassistant.components.vera import (
|
from homeassistant.components.vera import (
|
||||||
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
|
||||||
|
|
||||||
DEPENDENCIES = ['vera']
|
DEPENDENCIES = ['vera']
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ class VeraCover(VeraDevice, CoverDevice):
|
||||||
def __init__(self, vera_device, controller):
|
def __init__(self, vera_device, controller):
|
||||||
"""Initialize the Vera device."""
|
"""Initialize the Vera device."""
|
||||||
VeraDevice.__init__(self, vera_device, controller)
|
VeraDevice.__init__(self, vera_device, controller)
|
||||||
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_cover_position(self):
|
def current_cover_position(self):
|
||||||
|
|
|
@ -7,10 +7,10 @@ https://home-assistant.io/components/light.vera/
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
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.const import (STATE_OFF, STATE_ON)
|
||||||
from homeassistant.components.vera import (
|
from homeassistant.components.vera import (
|
||||||
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ class VeraLight(VeraDevice, Light):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self._state = False
|
self._state = False
|
||||||
VeraDevice.__init__(self, vera_device, controller)
|
VeraDevice.__init__(self, vera_device, controller)
|
||||||
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
|
|
|
@ -6,10 +6,10 @@ https://home-assistant.io/components/lock.vera/
|
||||||
"""
|
"""
|
||||||
import logging
|
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.const import (STATE_LOCKED, STATE_UNLOCKED)
|
||||||
from homeassistant.components.vera import (
|
from homeassistant.components.vera import (
|
||||||
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ class VeraLock(VeraDevice, LockDevice):
|
||||||
"""Initialize the Vera device."""
|
"""Initialize the Vera device."""
|
||||||
self._state = None
|
self._state = None
|
||||||
VeraDevice.__init__(self, vera_device, controller)
|
VeraDevice.__init__(self, vera_device, controller)
|
||||||
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
def lock(self, **kwargs):
|
def lock(self, **kwargs):
|
||||||
"""Lock the device."""
|
"""Lock the device."""
|
||||||
|
|
|
@ -9,8 +9,9 @@ import logging
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
from homeassistant.components.sensor import ENTITY_ID_FORMAT
|
||||||
from homeassistant.components.vera import (
|
from homeassistant.components.vera import (
|
||||||
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
|
||||||
|
|
||||||
DEPENDENCIES = ['vera']
|
DEPENDENCIES = ['vera']
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ class VeraSensor(VeraDevice, Entity):
|
||||||
self.current_value = None
|
self.current_value = None
|
||||||
self._temperature_units = None
|
self._temperature_units = None
|
||||||
VeraDevice.__init__(self, vera_device, controller)
|
VeraDevice.__init__(self, vera_device, controller)
|
||||||
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
|
|
@ -7,10 +7,10 @@ https://home-assistant.io/components/switch.vera/
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.util import convert
|
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.const import (STATE_OFF, STATE_ON)
|
||||||
from homeassistant.components.vera import (
|
from homeassistant.components.vera import (
|
||||||
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
|
||||||
|
|
||||||
DEPENDENCIES = ['vera']
|
DEPENDENCIES = ['vera']
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ class VeraSwitch(VeraDevice, SwitchDevice):
|
||||||
"""Initialize the Vera device."""
|
"""Initialize the Vera device."""
|
||||||
self._state = False
|
self._state = False
|
||||||
VeraDevice.__init__(self, vera_device, controller)
|
VeraDevice.__init__(self, vera_device, controller)
|
||||||
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn device on."""
|
"""Turn device on."""
|
||||||
|
|
|
@ -12,7 +12,7 @@ import voluptuous as vol
|
||||||
from requests.exceptions import RequestException
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
from homeassistant.util.dt import utc_from_timestamp
|
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 discovery
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -32,6 +32,8 @@ CONF_CONTROLLER = 'vera_controller_url'
|
||||||
CONF_EXCLUDE = 'exclude'
|
CONF_EXCLUDE = 'exclude'
|
||||||
CONF_LIGHTS = 'lights'
|
CONF_LIGHTS = 'lights'
|
||||||
|
|
||||||
|
VERA_ID_FORMAT = '{}_{}'
|
||||||
|
|
||||||
ATTR_CURRENT_POWER_MWH = "current_power_mwh"
|
ATTR_CURRENT_POWER_MWH = "current_power_mwh"
|
||||||
|
|
||||||
VERA_DEVICES = defaultdict(list)
|
VERA_DEVICES = defaultdict(list)
|
||||||
|
@ -131,8 +133,10 @@ class VeraDevice(Entity):
|
||||||
self.vera_device = vera_device
|
self.vera_device = vera_device
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
|
|
||||||
|
self._name = self.vera_device.name
|
||||||
# Append device id to prevent name clashes in HA.
|
# 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.controller.register(vera_device, self._update_callback)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue