Skip to content

Commit

Permalink
Generate unique ID for sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotak authored Dec 28, 2020
2 parents 5b264c1 + 0883007 commit df7a967
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions custom_components/attributes/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from homeassistant.helpers.event import async_track_state_change
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers import template as template_helper
from homeassistant.util import slugify

__version__ = '1.1.0'

Expand Down Expand Up @@ -165,6 +166,7 @@ def __init__(self, hass, device_id, friendly_name, unit_of_measurement,
self.entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, device_id,
hass=hass)
self._name = friendly_name
self._unique_id = slugify(f"{entity_id}_{device_id}")
self._unit_of_measurement = unit_of_measurement
self._template = state_template
self._state = None
Expand Down Expand Up @@ -200,6 +202,11 @@ def name(self):
"""Return the name of the sensor."""
return self._name

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

@property
def state(self):
"""Return the state of the sensor."""
Expand Down

0 comments on commit df7a967

Please sign in to comment.