Skip to content

Commit

Permalink
Add entity translations to ecobee (#95281)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Jun 26, 2023
1 parent 320003b commit cb9cbdf
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 57 deletions.
16 changes: 4 additions & 12 deletions homeassistant/components/ecobee/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 4 additions & 12 deletions homeassistant/components/ecobee/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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."""
Expand All @@ -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
Expand Down
16 changes: 4 additions & 12 deletions homeassistant/components/ecobee/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/ecobee/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ 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
),
),
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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions homeassistant/components/ecobee/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,34 @@ 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,
runtime_key=None,
),
EcobeeSensorEntityDescription(
key="humidity",
name="Humidity",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
runtime_key=None,
),
EcobeeSensorEntityDescription(
key="co2PPM",
name="CO2",
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
device_class=SensorDeviceClass.CO2,
state_class=SensorStateClass.MEASUREMENT,
runtime_key="actualCO2",
),
EcobeeSensorEntityDescription(
key="vocPPM",
name="VOC",
device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
runtime_key="actualVOC",
),
EcobeeSensorEntityDescription(
key="airQuality",
name="Air Quality Index",
device_class=SensorDeviceClass.AQI,
state_class=SensorStateClass.MEASUREMENT,
runtime_key="actualAQScore",
Expand Down Expand Up @@ -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__(
Expand All @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions homeassistant/components/ecobee/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
15 changes: 4 additions & 11 deletions homeassistant/components/ecobee/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ 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."""
self.data = data
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."""
Expand All @@ -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."""
Expand All @@ -98,7 +91,7 @@ def device_info(self) -> DeviceInfo:
identifiers={(DOMAIN, thermostat["identifier"])},
manufacturer=MANUFACTURER,
model=model,
name=self.name,
name=self._name,
)

@property
Expand Down
3 changes: 2 additions & 1 deletion tests/components/ecobee/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def ecobee_fixture():
vals = {
"name": "Ecobee",
"modelNumber": "athenaSmart",
"identifier": "abc",
"program": {
"climates": [
{"name": "Climate1", "climateRef": "c1"},
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit cb9cbdf

Please sign in to comment.