From f4c9540a1bd4536cb38415e2f7969a8df92e8d68 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Tue, 26 Jan 2016 09:33:26 +0100 Subject: [PATCH] Updated teh entity_id generation Entity ids will now look like this: sensor.philio_technology_corporation_psm021_slim_multisensor_doorwindow_sensor_7 sensor.philio_technology_corporation_psm021_slim_multisensor_luminance_7 sensor.philio_technology_corporation_psm021_slim_multisensor_motion_sensor_7 sensor.philio_technology_corporation_psm021_slim_multisensor_tamper_sensor_7 sensor.philio_technology_corporation_psm021_slim_multisensor_temperature_7 sensor.philio_technology_corporation_psm021_slim_multisensor_doorwindow_sensor_8 sensor.philio_technology_corporation_psm021_slim_multisensor_luminance_8 sensor.philio_technology_corporation_psm021_slim_multisensor_motion_sensor_8 sensor.philio_technology_corporation_psm021_slim_multisensor_tamper_sensor_8 sensor.philio_technology_corporation_psm021_slim_multisensor_temperature_8 And if there is several values of the same type in a node the instance id will be appended like this (three switches in the same device): switch.fibaro_system_unknown_type0202_id1002_switch_9 switch.fibaro_system_unknown_type0202_id1002_switch_9_2 switch.fibaro_system_unknown_type0202_id1002_switch_9_3 --- homeassistant/components/light/zwave.py | 30 ++++++++++++++++++++---- homeassistant/components/sensor/zwave.py | 16 +++++++++++++ homeassistant/components/switch/zwave.py | 30 ++++++++++++++++++++---- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/light/zwave.py b/homeassistant/components/light/zwave.py index 02664ed896c..07dbd0f26fc 100644 --- a/homeassistant/components/light/zwave.py +++ b/homeassistant/components/light/zwave.py @@ -12,6 +12,7 @@ from threading import Timer from homeassistant.const import STATE_ON, STATE_OFF from homeassistant.components.light import (Light, ATTR_BRIGHTNESS) +from homeassistant.util import slugify import homeassistant.components.zwave as zwave @@ -92,11 +93,32 @@ class ZwaveDimmer(Light): return False @property - def name(self): - """ Returns the name of the device if any. """ - name = self._node.name or "{}".format(self._node.product_name) + def unique_id(self): + """ Returns a unique id. """ + return "ZWAVE-{}-{}".format(self._node.node_id, self._value.object_id) - return "{}".format(name or self._value.label) + @property + def name(self): + """ Returns the name of the device. """ + name = self._node.name or "{} {}".format( + self._node.manufacturer_name, self._node.product_name) + + return "{} {}".format(name, self._value.label) + + @property + def entity_id(self): + """ Returns the entity_id of the device if any. + The entity_id contains node_id and value instance id + to not collide with other entity_ids""" + + entity_id = "light.{}_{}".format(slugify(self.name), + self._node.node_id) + + # Add the instance id if there is more than one instance for the value + if self._value.instance > 1: + return "{}_{}".format(entity_id, self._value.instance) + + return entity_id @property def brightness(self): diff --git a/homeassistant/components/sensor/zwave.py b/homeassistant/components/sensor/zwave.py index 869f4dbe810..64cbd1953ab 100644 --- a/homeassistant/components/sensor/zwave.py +++ b/homeassistant/components/sensor/zwave.py @@ -14,6 +14,7 @@ from homeassistant.helpers.event import track_point_in_time import homeassistant.util.dt as dt_util import homeassistant.components.zwave as zwave from homeassistant.helpers.entity import Entity +from homeassistant.util import slugify from homeassistant.const import ( ATTR_BATTERY_LEVEL, STATE_ON, STATE_OFF, TEMP_CELCIUS, TEMP_FAHRENHEIT, ATTR_LOCATION) @@ -109,6 +110,21 @@ class ZWaveSensor(Entity): return "{} {}".format(name, self._value.label) + @property + def entity_id(self): + """ Returns the entity_id of the device if any. + The entity_id contains node_id and value instance id + to not collide with other entity_ids""" + + entity_id = "sensor.{}_{}".format(slugify(self.name), + self._node.node_id) + + # Add the instance id if there is more than one instance for the value + if self._value.instance > 1: + return "{}_{}".format(entity_id, self._value.instance) + + return entity_id + @property def state(self): """ Returns the state of the sensor. """ diff --git a/homeassistant/components/switch/zwave.py b/homeassistant/components/switch/zwave.py index f4777340445..e3229af5314 100644 --- a/homeassistant/components/switch/zwave.py +++ b/homeassistant/components/switch/zwave.py @@ -9,6 +9,7 @@ Zwave platform that handles simple binary switches. import homeassistant.components.zwave as zwave from homeassistant.components.switch import SwitchDevice +from homeassistant.util import slugify # pylint: disable=unused-argument @@ -56,11 +57,32 @@ class ZwaveSwitch(SwitchDevice): return False @property - def name(self): - """ Returns the name of the device if any. """ - name = self._node.name or "{}".format(self._node.product_name) + def unique_id(self): + """ Returns a unique id. """ + return "ZWAVE-{}-{}".format(self._node.node_id, self._value.object_id) - return "{}".format(name or self._value.label) + @property + def name(self): + """ Returns the name of the device. """ + name = self._node.name or "{} {}".format( + self._node.manufacturer_name, self._node.product_name) + + return "{} {}".format(name, self._value.label) + + @property + def entity_id(self): + """ Returns the entity_id of the device if any. + The entity_id contains node_id and value instance id + to not collide with other entity_ids""" + + entity_id = "switch.{}_{}".format(slugify(self.name), + self._node.node_id) + + # Add the instance id if there is more than one instance for the value + if self._value.instance > 1: + return "{}_{}".format(entity_id, self._value.instance) + + return entity_id @property def is_on(self):