Attempt to set unique id of rfxtrx device (#37159)

This commit is contained in:
Joakim Plate 2020-06-28 06:59:42 +02:00 committed by GitHub
parent 10f296ba17
commit 201dab93ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -378,6 +378,7 @@ class RfxtrxDevice(Entity):
self._state = datas[ATTR_STATE]
self._should_fire_event = datas[ATTR_FIRE_EVENT]
self._brightness = 0
self._unique_id = f"{slugify(self._event.device.type_string.lower())}_{slugify(self._event.device.id_string.lower())}"
self.added_to_hass = False
async def async_added_to_hass(self):
@ -409,6 +410,11 @@ class RfxtrxDevice(Entity):
"""Return true if unable to access real state of entity."""
return True
@property
def unique_id(self):
"""Return unique identifier of remote device."""
return self._unique_id
def turn_off(self, **kwargs):
"""Turn the device off."""
self._send_command("turn_off")

View File

@ -197,6 +197,7 @@ class RfxtrxBinarySensor(BinarySensorEntity):
self._data_bits = data_bits
self._cmd_on = cmd_on
self._cmd_off = cmd_off
self._unique_id = f"{slugify(self.event.device.type_string.lower())}_{slugify(self.event.device.id_string.lower())}"
if data_bits is not None:
self._masked_id = get_pt2262_deviceid(
@ -255,6 +256,11 @@ class RfxtrxBinarySensor(BinarySensorEntity):
"""Return true if the sensor state is True."""
return self._state
@property
def unique_id(self):
"""Return unique identifier of remote device."""
return self._unique_id
def apply_cmd(self, cmd):
"""Apply a command for updating the state."""
if cmd == self.cmd_on:

View File

@ -127,6 +127,7 @@ class RfxtrxSensor(Entity):
self.should_fire_event = should_fire_event
self.data_type = data_type
self._unit_of_measurement = DATA_TYPES.get(data_type, "")
self._unique_id = f"{slugify(self.event.device.type_string.lower())}_{slugify(self.event.device.id_string.lower())}_{slugify(self.data_type)}"
def __str__(self):
"""Return the name of the sensor."""
@ -155,3 +156,8 @@ class RfxtrxSensor(Entity):
def unit_of_measurement(self):
"""Return the unit this state is expressed in."""
return self._unit_of_measurement
@property
def unique_id(self):
"""Return unique identifier of remote device."""
return self._unique_id