Change devolo Home Control entity naming (#38275)

* adding suffix after the entity name just in case the device class is not known

* remove if else
This commit is contained in:
Markus Bong 2020-07-27 10:17:45 +02:00 committed by GitHub
parent b226a7183f
commit 569caf9e40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 14 deletions

View File

@ -50,10 +50,21 @@ class DevoloBinaryDeviceEntity(DevoloDeviceEntity, BinarySensorEntity):
def __init__(self, homecontrol, device_instance, element_uid):
"""Initialize a devolo binary sensor."""
if device_instance.binary_sensor_property.get(element_uid).sub_type != "":
name = f"{device_instance.itemName} {device_instance.binary_sensor_property.get(element_uid).sub_type}"
else:
name = f"{device_instance.itemName} {device_instance.binary_sensor_property.get(element_uid).sensor_type}"
self._binary_sensor_property = device_instance.binary_sensor_property.get(
element_uid
)
self._device_class = DEVICE_CLASS_MAPPING.get(
self._binary_sensor_property.sub_type
or self._binary_sensor_property.sensor_type
)
name = device_instance.itemName
if self._device_class is None:
if device_instance.binary_sensor_property.get(element_uid).sub_type != "":
name += f" {device_instance.binary_sensor_property.get(element_uid).sub_type}"
else:
name += f" {device_instance.binary_sensor_property.get(element_uid).sensor_type}"
super().__init__(
homecontrol=homecontrol,
@ -63,15 +74,6 @@ class DevoloBinaryDeviceEntity(DevoloDeviceEntity, BinarySensorEntity):
sync=self._sync,
)
self._binary_sensor_property = self._device_instance.binary_sensor_property.get(
self._unique_id
)
self._device_class = DEVICE_CLASS_MAPPING.get(
self._binary_sensor_property.sub_type
or self._binary_sensor_property.sensor_type
)
self._state = self._binary_sensor_property.state
self._subscriber = None

View File

@ -53,13 +53,19 @@ class DevoloMultiLevelDeviceEntity(DevoloDeviceEntity):
self._device_class = DEVICE_CLASS_MAPPING.get(
self._multi_level_sensor_property.sensor_type
)
name = device_instance.itemName
if self._device_class is None:
name += f" {self._multi_level_sensor_property.sensor_type}"
self._unit = self._multi_level_sensor_property.unit
super().__init__(
homecontrol=homecontrol,
device_instance=device_instance,
element_uid=element_uid,
name=f"{device_instance.itemName} {self._multi_level_sensor_property.sensor_type}",
name=name,
sync=self._sync,
)