From cb9cbdfb288fae2b7915cb8bfbd18352bec7c319 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 26 Jun 2023 23:12:48 +0200 Subject: [PATCH] Add entity translations to ecobee (#95281) --- homeassistant/components/ecobee/binary_sensor.py | 16 ++++------------ homeassistant/components/ecobee/climate.py | 16 ++++------------ homeassistant/components/ecobee/humidifier.py | 16 ++++------------ homeassistant/components/ecobee/number.py | 5 ++--- homeassistant/components/ecobee/sensor.py | 8 ++------ homeassistant/components/ecobee/strings.json | 10 ++++++++++ homeassistant/components/ecobee/weather.py | 15 ++++----------- tests/components/ecobee/test_climate.py | 3 ++- 8 files changed, 32 insertions(+), 57 deletions(-) diff --git a/homeassistant/components/ecobee/binary_sensor.py b/homeassistant/components/ecobee/binary_sensor.py index 2266d70e0ad82..e65dc221a9fb1 100644 --- a/homeassistant/components/ecobee/binary_sensor.py +++ b/homeassistant/components/ecobee/binary_sensor.py @@ -35,19 +35,16 @@ async def async_setup_entry( class EcobeeBinarySensor(BinarySensorEntity): """Representation of an Ecobee sensor.""" + _attr_device_class = BinarySensorDeviceClass.OCCUPANCY + _attr_has_entity_name = True + def __init__(self, data, sensor_name, sensor_index): """Initialize the Ecobee sensor.""" self.data = data - self._name = f"{sensor_name} Occupancy" - self.sensor_name = sensor_name + self.sensor_name = sensor_name.rstrip() self.index = sensor_index self._state = None - @property - def name(self): - """Return the name of the Ecobee sensor.""" - return self._name.rstrip() - @property def unique_id(self): """Return a unique identifier for this sensor.""" @@ -101,11 +98,6 @@ def is_on(self): """Return the status of the sensor.""" return self._state == "true" - @property - def device_class(self): - """Return the class of this sensor, from DEVICE_CLASSES.""" - return BinarySensorDeviceClass.OCCUPANCY - async def async_update(self) -> None: """Get the latest state of the sensor.""" await self.data.update() diff --git a/homeassistant/components/ecobee/climate.py b/homeassistant/components/ecobee/climate.py index 7925832953baa..8c0b77b913dd2 100644 --- a/homeassistant/components/ecobee/climate.py +++ b/homeassistant/components/ecobee/climate.py @@ -310,6 +310,8 @@ class Thermostat(ClimateEntity): _attr_precision = PRECISION_TENTHS _attr_temperature_unit = UnitOfTemperature.FAHRENHEIT + _attr_name = None + _attr_has_entity_name = True def __init__( self, data: EcobeeData, thermostat_index: int, thermostat: dict @@ -318,7 +320,7 @@ def __init__( self.data = data self.thermostat_index = thermostat_index self.thermostat = thermostat - self._name = self.thermostat["name"] + self._attr_unique_id = self.thermostat["identifier"] self.vacation = None self._last_active_hvac_mode = HVACMode.HEAT_COOL @@ -364,16 +366,6 @@ def supported_features(self) -> ClimateEntityFeature: supported = supported | ClimateEntityFeature.AUX_HEAT return supported - @property - def name(self): - """Return the name of the Ecobee Thermostat.""" - return self.thermostat["name"] - - @property - def unique_id(self): - """Return a unique identifier for this ecobee thermostat.""" - return self.thermostat["identifier"] - @property def device_info(self) -> DeviceInfo: """Return device information for this ecobee thermostat.""" @@ -388,7 +380,7 @@ def device_info(self) -> DeviceInfo: identifiers={(DOMAIN, self.thermostat["identifier"])}, manufacturer=MANUFACTURER, model=model, - name=self.name, + name=self.thermostat["name"], ) @property diff --git a/homeassistant/components/ecobee/humidifier.py b/homeassistant/components/ecobee/humidifier.py index f4c4dad6527a3..fb5533adf07a2 100644 --- a/homeassistant/components/ecobee/humidifier.py +++ b/homeassistant/components/ecobee/humidifier.py @@ -44,27 +44,19 @@ class EcobeeHumidifier(HumidifierEntity): """A humidifier class for an ecobee thermostat with humidifier attached.""" _attr_supported_features = HumidifierEntityFeature.MODES + _attr_has_entity_name = True + _attr_name = None def __init__(self, data, thermostat_index): """Initialize ecobee humidifier platform.""" self.data = data self.thermostat_index = thermostat_index self.thermostat = self.data.ecobee.get_thermostat(self.thermostat_index) - self._name = self.thermostat["name"] + self._attr_unique_id = self.thermostat["identifier"] self._last_humidifier_on_mode = MODE_MANUAL self.update_without_throttle = False - @property - def name(self): - """Return the name of the humidifier.""" - return self._name - - @property - def unique_id(self): - """Return unique_id for humidifier.""" - return f"{self.thermostat['identifier']}" - @property def device_info(self) -> DeviceInfo: """Return device information for the ecobee humidifier.""" @@ -79,7 +71,7 @@ def device_info(self) -> DeviceInfo: identifiers={(DOMAIN, self.thermostat["identifier"])}, manufacturer=MANUFACTURER, model=model, - name=self.name, + name=self.thermostat["name"], ) @property diff --git a/homeassistant/components/ecobee/number.py b/homeassistant/components/ecobee/number.py index 15ad17b0e3990..67c975010ab9a 100644 --- a/homeassistant/components/ecobee/number.py +++ b/homeassistant/components/ecobee/number.py @@ -36,7 +36,7 @@ class EcobeeNumberEntityDescription( VENTILATOR_NUMBERS = ( EcobeeNumberEntityDescription( key="home", - name="home", + translation_key="ventilator_min_type_home", ecobee_setting_key="ventilatorMinOnTimeHome", set_fn=lambda data, id, min_time: data.ecobee.set_ventilator_min_on_time_home( id, min_time @@ -44,7 +44,7 @@ class EcobeeNumberEntityDescription( ), EcobeeNumberEntityDescription( key="away", - name="away", + translation_key="ventilator_min_type_away", ecobee_setting_key="ventilatorMinOnTimeAway", set_fn=lambda data, id, min_time: data.ecobee.set_ventilator_min_on_time_away( id, min_time @@ -92,7 +92,6 @@ def __init__( """Initialize ecobee ventilator platform.""" super().__init__(data, thermostat_index) self.entity_description = description - self._attr_name = f"Ventilator min time {description.name}" self._attr_unique_id = f"{self.base_unique_id}_ventilator_{description.key}" async def async_update(self) -> None: diff --git a/homeassistant/components/ecobee/sensor.py b/homeassistant/components/ecobee/sensor.py index 90d4ba4202e25..3996ec6fd3503 100644 --- a/homeassistant/components/ecobee/sensor.py +++ b/homeassistant/components/ecobee/sensor.py @@ -42,7 +42,6 @@ class EcobeeSensorEntityDescription( SENSOR_TYPES: tuple[EcobeeSensorEntityDescription, ...] = ( EcobeeSensorEntityDescription( key="temperature", - name="Temperature", native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, @@ -50,7 +49,6 @@ class EcobeeSensorEntityDescription( ), EcobeeSensorEntityDescription( key="humidity", - name="Humidity", native_unit_of_measurement=PERCENTAGE, device_class=SensorDeviceClass.HUMIDITY, state_class=SensorStateClass.MEASUREMENT, @@ -58,7 +56,6 @@ class EcobeeSensorEntityDescription( ), EcobeeSensorEntityDescription( key="co2PPM", - name="CO2", native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION, device_class=SensorDeviceClass.CO2, state_class=SensorStateClass.MEASUREMENT, @@ -66,7 +63,6 @@ class EcobeeSensorEntityDescription( ), EcobeeSensorEntityDescription( key="vocPPM", - name="VOC", device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS, native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, state_class=SensorStateClass.MEASUREMENT, @@ -74,7 +70,6 @@ class EcobeeSensorEntityDescription( ), EcobeeSensorEntityDescription( key="airQuality", - name="Air Quality Index", device_class=SensorDeviceClass.AQI, state_class=SensorStateClass.MEASUREMENT, runtime_key="actualAQScore", @@ -104,6 +99,8 @@ async def async_setup_entry( class EcobeeSensor(SensorEntity): """Representation of an Ecobee sensor.""" + _attr_has_entity_name = True + entity_description: EcobeeSensorEntityDescription def __init__( @@ -119,7 +116,6 @@ def __init__( self.sensor_name = sensor_name self.index = sensor_index self._state = None - self._attr_name = f"{sensor_name} {description.name}" @property def unique_id(self): diff --git a/homeassistant/components/ecobee/strings.json b/homeassistant/components/ecobee/strings.json index 19f379de7d953..af44845887bba 100644 --- a/homeassistant/components/ecobee/strings.json +++ b/homeassistant/components/ecobee/strings.json @@ -20,5 +20,15 @@ "abort": { "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" } + }, + "entity": { + "number": { + "ventilator_min_type_home": { + "name": "Ventilator min time home" + }, + "ventilator_min_type_away": { + "name": "Ventilator min time away" + } + } } } diff --git a/homeassistant/components/ecobee/weather.py b/homeassistant/components/ecobee/weather.py index 5610cdb2a9c1d..d38bc82c6f2d0 100644 --- a/homeassistant/components/ecobee/weather.py +++ b/homeassistant/components/ecobee/weather.py @@ -57,6 +57,8 @@ class EcobeeWeather(WeatherEntity): _attr_native_temperature_unit = UnitOfTemperature.FAHRENHEIT _attr_native_visibility_unit = UnitOfLength.METERS _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND + _attr_has_entity_name = True + _attr_name = None def __init__(self, data, name, index): """Initialize the Ecobee weather platform.""" @@ -64,6 +66,7 @@ def __init__(self, data, name, index): self._name = name self._index = index self.weather = None + self._attr_unique_id = data.ecobee.get_thermostat(self._index)["identifier"] def get_forecast(self, index, param): """Retrieve forecast parameter.""" @@ -73,16 +76,6 @@ def get_forecast(self, index, param): except (IndexError, KeyError) as err: raise ValueError from err - @property - def name(self): - """Return the name of the sensor.""" - return self._name - - @property - def unique_id(self): - """Return a unique identifier for the weather platform.""" - return self.data.ecobee.get_thermostat(self._index)["identifier"] - @property def device_info(self) -> DeviceInfo: """Return device information for the ecobee weather platform.""" @@ -98,7 +91,7 @@ def device_info(self) -> DeviceInfo: identifiers={(DOMAIN, thermostat["identifier"])}, manufacturer=MANUFACTURER, model=model, - name=self.name, + name=self._name, ) @property diff --git a/tests/components/ecobee/test_climate.py b/tests/components/ecobee/test_climate.py index 09b127432db41..8572764ce4dd1 100644 --- a/tests/components/ecobee/test_climate.py +++ b/tests/components/ecobee/test_climate.py @@ -25,6 +25,7 @@ def ecobee_fixture(): vals = { "name": "Ecobee", "modelNumber": "athenaSmart", + "identifier": "abc", "program": { "climates": [ {"name": "Climate1", "climateRef": "c1"}, @@ -83,7 +84,7 @@ def thermostat_fixture(data): async def test_name(thermostat) -> None: """Test name property.""" - assert thermostat.name == "Ecobee" + assert thermostat.device_info["name"] == "Ecobee" async def test_aux_heat_not_supported_by_default(hass: HomeAssistant) -> None: