Centralize entity naming for Tuya entities (#57755)

This commit is contained in:
Franck Nijhof 2021-10-15 10:07:25 +02:00 committed by GitHub
parent 8b422a7bd5
commit f6c6ec3578
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 5 additions and 33 deletions

View file

@ -58,6 +58,11 @@ class TuyaEntity(Entity):
@property @property
def name(self) -> str | None: def name(self) -> str | None:
"""Return Tuya device name.""" """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 return self.tuya_device.name
@property @property

View file

@ -85,13 +85,6 @@ class TuyaBinarySensorEntity(TuyaEntity, BinarySensorEntity):
self.entity_description = description self.entity_description = description
self._attr_unique_id = f"{super().unique_id}{description.key}" 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 @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if sensor is on.""" """Return true if sensor is on."""

View file

@ -113,13 +113,6 @@ class TuyaNumberEntity(TuyaEntity, NumberEntity):
if description.unit_of_measurement is None: if description.unit_of_measurement is None:
self._attr_unit_of_measurement = self._type_data.unit 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 @property
def value(self) -> float | None: def value(self) -> float | None:
"""Return the entity value to represent the entity state.""" """Return the entity value to represent the entity state."""

View file

@ -101,13 +101,6 @@ class TuyaSelectEntity(TuyaEntity, SelectEntity):
type_data = EnumTypeData.from_json(self._status_range.values) type_data = EnumTypeData.from_json(self._status_range.values)
self._attr_options = type_data.range 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 @property
def current_option(self) -> str | None: def current_option(self) -> str | None:
"""Return the selected entity option to represent the entity state.""" """Return the selected entity option to represent the entity state."""

View file

@ -149,13 +149,6 @@ class TuyaSensorEntity(TuyaEntity, SensorEntity):
elif self._status_range.type == "Enum": elif self._status_range.type == "Enum":
self._type_data = EnumTypeData.from_json(self._status_range.values) 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 @property
def native_value(self) -> StateType: def native_value(self) -> StateType:
"""Return the value reported by the sensor.""" """Return the value reported by the sensor."""

View file

@ -309,11 +309,6 @@ class TuyaSwitchEntity(TuyaEntity, SwitchEntity):
self.entity_description = description self.entity_description = description
self._attr_unique_id = f"{super().unique_id}{description.key}" 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 @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if switch is on.""" """Return true if switch is on."""