From f6c6ec357813caed364c1de132ddad3a751c7267 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 15 Oct 2021 10:07:25 +0200 Subject: [PATCH] Centralize entity naming for Tuya entities (#57755) --- homeassistant/components/tuya/base.py | 5 +++++ homeassistant/components/tuya/binary_sensor.py | 7 ------- homeassistant/components/tuya/number.py | 7 ------- homeassistant/components/tuya/select.py | 7 ------- homeassistant/components/tuya/sensor.py | 7 ------- homeassistant/components/tuya/switch.py | 5 ----- 6 files changed, 5 insertions(+), 33 deletions(-) diff --git a/homeassistant/components/tuya/base.py b/homeassistant/components/tuya/base.py index 2be80f53776..0e8f8add2fa 100644 --- a/homeassistant/components/tuya/base.py +++ b/homeassistant/components/tuya/base.py @@ -58,6 +58,11 @@ class TuyaEntity(Entity): @property def name(self) -> str | None: """Return Tuya device name.""" + if ( + hasattr(self, "entity_description") + and self.entity_description.name is not None + ): + return f"{self.tuya_device.name} {self.entity_description.name}" return self.tuya_device.name @property diff --git a/homeassistant/components/tuya/binary_sensor.py b/homeassistant/components/tuya/binary_sensor.py index 4596b8638a4..a78e5362f36 100644 --- a/homeassistant/components/tuya/binary_sensor.py +++ b/homeassistant/components/tuya/binary_sensor.py @@ -85,13 +85,6 @@ class TuyaBinarySensorEntity(TuyaEntity, BinarySensorEntity): self.entity_description = description self._attr_unique_id = f"{super().unique_id}{description.key}" - @property - def name(self) -> str | None: - """Return Tuya device name.""" - if self.entity_description.name is not None: - return f"{self.tuya_device.name} {self.entity_description.name}" - return self.tuya_device.name - @property def is_on(self) -> bool: """Return true if sensor is on.""" diff --git a/homeassistant/components/tuya/number.py b/homeassistant/components/tuya/number.py index 977917f8b0c..f31929f8f69 100644 --- a/homeassistant/components/tuya/number.py +++ b/homeassistant/components/tuya/number.py @@ -113,13 +113,6 @@ class TuyaNumberEntity(TuyaEntity, NumberEntity): if description.unit_of_measurement is None: self._attr_unit_of_measurement = self._type_data.unit - @property - def name(self) -> str | None: - """Return Tuya device name.""" - if self.entity_description.name is not None: - return f"{self.tuya_device.name} {self.entity_description.name}" - return self.tuya_device.name - @property def value(self) -> float | None: """Return the entity value to represent the entity state.""" diff --git a/homeassistant/components/tuya/select.py b/homeassistant/components/tuya/select.py index c3b81787086..a71e3db5125 100644 --- a/homeassistant/components/tuya/select.py +++ b/homeassistant/components/tuya/select.py @@ -101,13 +101,6 @@ class TuyaSelectEntity(TuyaEntity, SelectEntity): type_data = EnumTypeData.from_json(self._status_range.values) self._attr_options = type_data.range - @property - def name(self) -> str | None: - """Return Tuya device name.""" - if self.entity_description.name is not None: - return f"{self.tuya_device.name} {self.entity_description.name}" - return self.tuya_device.name - @property def current_option(self) -> str | None: """Return the selected entity option to represent the entity state.""" diff --git a/homeassistant/components/tuya/sensor.py b/homeassistant/components/tuya/sensor.py index e1ab4867df9..54543ba984d 100644 --- a/homeassistant/components/tuya/sensor.py +++ b/homeassistant/components/tuya/sensor.py @@ -149,13 +149,6 @@ class TuyaSensorEntity(TuyaEntity, SensorEntity): elif self._status_range.type == "Enum": self._type_data = EnumTypeData.from_json(self._status_range.values) - @property - def name(self) -> str | None: - """Return Tuya device name.""" - if self.entity_description.name is not None: - return f"{self.tuya_device.name} {self.entity_description.name}" - return self.tuya_device.name - @property def native_value(self) -> StateType: """Return the value reported by the sensor.""" diff --git a/homeassistant/components/tuya/switch.py b/homeassistant/components/tuya/switch.py index c66674de715..b001da78f9f 100644 --- a/homeassistant/components/tuya/switch.py +++ b/homeassistant/components/tuya/switch.py @@ -309,11 +309,6 @@ class TuyaSwitchEntity(TuyaEntity, SwitchEntity): self.entity_description = description self._attr_unique_id = f"{super().unique_id}{description.key}" - @property - def name(self) -> str | None: - """Return Tuya device name.""" - return f"{self.tuya_device.name} {self.entity_description.name}" - @property def is_on(self) -> bool: """Return true if switch is on."""