Migrate Venstar to has entity name (#99013)

pull/99019/head
Joost Lekkerkerker 2023-08-29 08:40:35 +02:00 committed by GitHub
parent 5ec645161d
commit 202b0b5300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 11 deletions

View File

@ -128,6 +128,8 @@ class VenstarDataUpdateCoordinator(update_coordinator.DataUpdateCoordinator[None
class VenstarEntity(CoordinatorEntity[VenstarDataUpdateCoordinator]):
"""Representation of a Venstar entity."""
_attr_has_entity_name = True
def __init__(
self,
venstar_data_coordinator: VenstarDataUpdateCoordinator,

View File

@ -37,7 +37,7 @@ class VenstarBinarySensor(VenstarEntity, BinarySensorEntity):
super().__init__(coordinator, config)
self.alert = alert
self._attr_unique_id = f"{config.entry_id}_{alert.replace(' ', '_')}"
self._attr_name = f"{self._client.name} {alert}"
self._attr_name = alert
@property
def is_on(self):

View File

@ -107,6 +107,7 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
_attr_fan_modes = [FAN_ON, FAN_AUTO]
_attr_hvac_modes = [HVACMode.HEAT, HVACMode.COOL, HVACMode.OFF, HVACMode.AUTO]
_attr_precision = PRECISION_HALVES
_attr_name = None
def __init__(
self,
@ -121,7 +122,6 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
HVACMode.AUTO: self._client.MODE_AUTO,
}
self._attr_unique_id = config.entry_id
self._attr_name = self._client.name
@property
def supported_features(self) -> ClimateEntityFeature:

View File

@ -70,7 +70,7 @@ class VenstarSensorTypeMixin:
"""Mixin for sensor required keys."""
value_fn: Callable[[VenstarDataUpdateCoordinator, str], Any]
name_fn: Callable[[VenstarDataUpdateCoordinator, str], str]
name_fn: Callable[[str], str]
uom_fn: Callable[[Any], str | None]
@ -156,7 +156,7 @@ class VenstarSensor(VenstarEntity, SensorEntity):
@property
def name(self):
"""Return the name of the device."""
return self.entity_description.name_fn(self.coordinator, self.sensor_name)
return self.entity_description.name_fn(self.sensor_name)
@property
def native_value(self) -> int:
@ -178,7 +178,7 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor(
sensor_name, "hum"
),
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {sensor_name} Humidity",
name_fn=lambda sensor_name: f"{sensor_name} Humidity",
),
VenstarSensorEntityDescription(
key="temp",
@ -188,7 +188,7 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
value_fn=lambda coordinator, sensor_name: round(
float(coordinator.client.get_sensor(sensor_name, "temp")), 1
),
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {sensor_name.replace(' Temp', '')} Temperature",
name_fn=lambda sensor_name: f"{sensor_name.replace(' Temp', '')} Temperature",
),
VenstarSensorEntityDescription(
key="co2",
@ -198,7 +198,7 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor(
sensor_name, "co2"
),
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {sensor_name} CO2",
name_fn=lambda sensor_name: f"{sensor_name} CO2",
),
VenstarSensorEntityDescription(
key="iaq",
@ -208,7 +208,7 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor(
sensor_name, "iaq"
),
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {sensor_name} IAQ",
name_fn=lambda sensor_name: f"{sensor_name} IAQ",
),
VenstarSensorEntityDescription(
key="battery",
@ -218,7 +218,7 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor(
sensor_name, "battery"
),
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {sensor_name} Battery",
name_fn=lambda sensor_name: f"{sensor_name} Battery",
),
)
@ -227,7 +227,7 @@ RUNTIME_ENTITY = VenstarSensorEntityDescription(
state_class=SensorStateClass.MEASUREMENT,
uom_fn=lambda _: UnitOfTime.MINUTES,
value_fn=lambda coordinator, sensor_name: coordinator.runtimes[-1][sensor_name],
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {RUNTIME_ATTRIBUTES[sensor_name]} Runtime",
name_fn=lambda sensor_name: f"{RUNTIME_ATTRIBUTES[sensor_name]} Runtime",
)
INFO_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
@ -240,6 +240,6 @@ INFO_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
value_fn=lambda coordinator, sensor_name: SCHEDULE_PARTS[
coordinator.client.get_info(sensor_name)
],
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} Schedule Part",
name_fn=lambda _: "Schedule Part",
),
)