mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
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
This commit is contained in:
@@ -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. """
|
||||
|
||||
Reference in New Issue
Block a user