From 0c401bcab23123829dd4f5f6592c4d8ea916a222 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 29 Aug 2022 10:20:55 +0200 Subject: [PATCH] Use _attr_temperature_unit in climate entities (#77472) --- homeassistant/components/daikin/climate.py | 7 ++----- homeassistant/components/esphome/climate.py | 7 ++----- homeassistant/components/fritzbox/climate.py | 6 +----- homeassistant/components/homematic/climate.py | 6 +----- .../components/homematicip_cloud/climate.py | 6 +----- homeassistant/components/incomfort/climate.py | 6 +----- homeassistant/components/intesishome/climate.py | 6 +----- homeassistant/components/izone/climate.py | 12 ++---------- homeassistant/components/melissa/climate.py | 6 +----- homeassistant/components/oem/climate.py | 6 +----- homeassistant/components/opentherm_gw/climate.py | 6 +----- homeassistant/components/proliphix/climate.py | 6 +----- homeassistant/components/schluter/climate.py | 6 +----- homeassistant/components/smarttub/climate.py | 6 +----- homeassistant/components/spider/climate.py | 7 ++----- homeassistant/components/stiebel_eltron/climate.py | 5 +---- homeassistant/components/tado/climate.py | 7 ++----- homeassistant/components/tfiac/climate.py | 6 +----- homeassistant/components/touchline/climate.py | 6 +----- homeassistant/components/vicare/climate.py | 6 +----- homeassistant/components/zha/climate.py | 7 ++----- homeassistant/components/zhong_hong/climate.py | 6 +----- 22 files changed, 28 insertions(+), 114 deletions(-) diff --git a/homeassistant/components/daikin/climate.py b/homeassistant/components/daikin/climate.py index d7bfb8cf7a0..2f07c5a0bdc 100644 --- a/homeassistant/components/daikin/climate.py +++ b/homeassistant/components/daikin/climate.py @@ -115,6 +115,8 @@ def format_target_temperature(target_temperature): class DaikinClimate(ClimateEntity): """Representation of a Daikin HVAC.""" + _attr_temperature_unit = TEMP_CELSIUS + def __init__(self, api: DaikinApi) -> None: """Initialize the climate device.""" @@ -180,11 +182,6 @@ class DaikinClimate(ClimateEntity): """Return a unique ID.""" return self._api.device.mac - @property - def temperature_unit(self) -> str: - """Return the unit of measurement which this thermostat uses.""" - return TEMP_CELSIUS - @property def current_temperature(self): """Return the current temperature.""" diff --git a/homeassistant/components/esphome/climate.py b/homeassistant/components/esphome/climate.py index 1552bd3775b..aba51a47a9d 100644 --- a/homeassistant/components/esphome/climate.py +++ b/homeassistant/components/esphome/climate.py @@ -136,6 +136,8 @@ _PRESETS: EsphomeEnumMapper[ClimatePreset, str] = EsphomeEnumMapper( class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEntity): """A climate implementation for ESPHome.""" + _attr_temperature_unit = TEMP_CELSIUS + @property def precision(self) -> float: """Return the precision of the climate device.""" @@ -146,11 +148,6 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti # Fall back to highest precision, tenths return PRECISION_TENTHS - @property - def temperature_unit(self) -> str: - """Return the unit of measurement used by the platform.""" - return TEMP_CELSIUS - @property def hvac_modes(self) -> list[str]: """Return the list of available operation modes.""" diff --git a/homeassistant/components/fritzbox/climate.py b/homeassistant/components/fritzbox/climate.py index 5d96cb95c15..20331459c3e 100644 --- a/homeassistant/components/fritzbox/climate.py +++ b/homeassistant/components/fritzbox/climate.py @@ -67,11 +67,7 @@ class FritzboxThermostat(FritzBoxEntity, ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) - - @property - def temperature_unit(self) -> str: - """Return the unit of measurement that is used.""" - return TEMP_CELSIUS + _attr_temperature_unit = TEMP_CELSIUS @property def precision(self) -> float: diff --git a/homeassistant/components/homematic/climate.py b/homeassistant/components/homematic/climate.py index 67a36284c58..78a03a28a4a 100644 --- a/homeassistant/components/homematic/climate.py +++ b/homeassistant/components/homematic/climate.py @@ -56,11 +56,7 @@ class HMThermostat(HMDevice, ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) - - @property - def temperature_unit(self): - """Return the unit of measurement that is used.""" - return TEMP_CELSIUS + _attr_temperature_unit = TEMP_CELSIUS @property def hvac_mode(self) -> HVACMode: diff --git a/homeassistant/components/homematicip_cloud/climate.py b/homeassistant/components/homematicip_cloud/climate.py index 23da237331b..802cacb1d76 100644 --- a/homeassistant/components/homematicip_cloud/climate.py +++ b/homeassistant/components/homematicip_cloud/climate.py @@ -66,6 +66,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE ) + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, hap: HomematicipHAP, device: AsyncHeatingGroup) -> None: """Initialize heating group.""" @@ -86,11 +87,6 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity): via_device=(HMIPC_DOMAIN, self._device.homeId), ) - @property - def temperature_unit(self) -> str: - """Return the unit of measurement.""" - return TEMP_CELSIUS - @property def target_temperature(self) -> float: """Return the temperature we try to reach.""" diff --git a/homeassistant/components/incomfort/climate.py b/homeassistant/components/incomfort/climate.py index c76f16093ee..aaeab394f75 100644 --- a/homeassistant/components/incomfort/climate.py +++ b/homeassistant/components/incomfort/climate.py @@ -37,6 +37,7 @@ class InComfortClimate(IncomfortChild, ClimateEntity): _attr_hvac_mode = HVACMode.HEAT _attr_hvac_modes = [HVACMode.HEAT] _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, client, heater, room) -> None: """Initialize the climate device.""" @@ -54,11 +55,6 @@ class InComfortClimate(IncomfortChild, ClimateEntity): """Return the device state attributes.""" return {"status": self._room.status} - @property - def temperature_unit(self) -> str: - """Return the unit of measurement.""" - return TEMP_CELSIUS - @property def current_temperature(self) -> float | None: """Return the current temperature.""" diff --git a/homeassistant/components/intesishome/climate.py b/homeassistant/components/intesishome/climate.py index 61b171ea8cc..925147e82ad 100644 --- a/homeassistant/components/intesishome/climate.py +++ b/homeassistant/components/intesishome/climate.py @@ -144,6 +144,7 @@ class IntesisAC(ClimateEntity): """Represents an Intesishome air conditioning device.""" _attr_should_poll = False + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, ih_device_id, ih_device, controller): """Initialize the thermostat.""" @@ -218,11 +219,6 @@ class IntesisAC(ClimateEntity): """Return the name of the AC device.""" return self._device_name - @property - def temperature_unit(self): - """Intesishome API uses celsius on the backend.""" - return TEMP_CELSIUS - @property def extra_state_attributes(self): """Return the device specific state attributes.""" diff --git a/homeassistant/components/izone/climate.py b/homeassistant/components/izone/climate.py index df7b8af4fa3..8ff1593d5ff 100644 --- a/homeassistant/components/izone/climate.py +++ b/homeassistant/components/izone/climate.py @@ -127,6 +127,7 @@ class ControllerDevice(ClimateEntity): """Representation of iZone Controller.""" _attr_should_poll = False + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, controller: Controller) -> None: """Initialise ControllerDevice.""" @@ -252,11 +253,6 @@ class ControllerDevice(ClimateEntity): """Return the name of the entity.""" return f"iZone Controller {self._controller.device_uid}" - @property - def temperature_unit(self) -> str: - """Return the unit of measurement which this thermostat uses.""" - return TEMP_CELSIUS - @property def precision(self) -> float: """Return the precision of the system.""" @@ -443,6 +439,7 @@ class ZoneDevice(ClimateEntity): """Representation of iZone Zone.""" _attr_should_poll = False + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, controller: ControllerDevice, zone: Zone) -> None: """Initialise ZoneDevice.""" @@ -529,11 +526,6 @@ class ZoneDevice(ClimateEntity): return self._attr_supported_features return self._attr_supported_features & ~ClimateEntityFeature.TARGET_TEMPERATURE - @property - def temperature_unit(self): - """Return the unit of measurement which this thermostat uses.""" - return TEMP_CELSIUS - @property def precision(self): """Return the precision of the system.""" diff --git a/homeassistant/components/melissa/climate.py b/homeassistant/components/melissa/climate.py index 81ffd9a5d1e..7dae7c2dad6 100644 --- a/homeassistant/components/melissa/climate.py +++ b/homeassistant/components/melissa/climate.py @@ -58,6 +58,7 @@ class MelissaClimate(ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.TARGET_TEMPERATURE ) + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, api, serial_number, init_data): """Initialize the climate device.""" @@ -124,11 +125,6 @@ class MelissaClimate(ClimateEntity): return None return self._cur_settings[self._api.TEMP] - @property - def temperature_unit(self): - """Return the unit of measurement which this thermostat uses.""" - return TEMP_CELSIUS - @property def min_temp(self): """Return the minimum supported temperature for the thermostat.""" diff --git a/homeassistant/components/oem/climate.py b/homeassistant/components/oem/climate.py index 846113fb586..298ae965e17 100644 --- a/homeassistant/components/oem/climate.py +++ b/homeassistant/components/oem/climate.py @@ -64,6 +64,7 @@ class ThermostatDevice(ClimateEntity): _attr_hvac_modes = SUPPORT_HVAC _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, thermostat, name): """Initialize the device.""" @@ -93,11 +94,6 @@ class ThermostatDevice(ClimateEntity): """Return the name of this Thermostat.""" return self._name - @property - def temperature_unit(self): - """Return the unit of measurement used by the platform.""" - return TEMP_CELSIUS - @property def hvac_action(self) -> HVACAction: """Return current hvac i.e. heat, cool, idle.""" diff --git a/homeassistant/components/opentherm_gw/climate.py b/homeassistant/components/opentherm_gw/climate.py index fecc99a4cca..a805cbacba0 100644 --- a/homeassistant/components/opentherm_gw/climate.py +++ b/homeassistant/components/opentherm_gw/climate.py @@ -66,6 +66,7 @@ class OpenThermClimate(ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, gw_dev, options): """Initialize the device.""" @@ -202,11 +203,6 @@ class OpenThermClimate(ClimateEntity): return PRECISION_HALVES return PRECISION_WHOLE - @property - def temperature_unit(self): - """Return the unit of measurement used by the platform.""" - return TEMP_CELSIUS - @property def hvac_action(self) -> HVACAction | None: """Return current HVAC operation.""" diff --git a/homeassistant/components/proliphix/climate.py b/homeassistant/components/proliphix/climate.py index e47aa0fc8f0..52ed3bb8bcd 100644 --- a/homeassistant/components/proliphix/climate.py +++ b/homeassistant/components/proliphix/climate.py @@ -55,6 +55,7 @@ class ProliphixThermostat(ClimateEntity): """Representation a Proliphix thermostat.""" _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE + _attr_temperature_unit = TEMP_FAHRENHEIT def __init__(self, pdp): """Initialize the thermostat.""" @@ -85,11 +86,6 @@ class ProliphixThermostat(ClimateEntity): """Return the device specific state attributes.""" return {ATTR_FAN: self._pdp.fan_state} - @property - def temperature_unit(self): - """Return the unit of measurement.""" - return TEMP_FAHRENHEIT - @property def current_temperature(self): """Return the current temperature.""" diff --git a/homeassistant/components/schluter/climate.py b/homeassistant/components/schluter/climate.py index 5c848d7f7ea..3ccea458960 100644 --- a/homeassistant/components/schluter/climate.py +++ b/homeassistant/components/schluter/climate.py @@ -82,6 +82,7 @@ class SchluterThermostat(CoordinatorEntity, ClimateEntity): _attr_hvac_mode = HVACMode.HEAT _attr_hvac_modes = [HVACMode.HEAT] _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, coordinator, serial_number, api, session_id): """Initialize the thermostat.""" @@ -100,11 +101,6 @@ class SchluterThermostat(CoordinatorEntity, ClimateEntity): """Return the name of the thermostat.""" return self.coordinator.data[self._serial_number].name - @property - def temperature_unit(self): - """Schluter API always uses celsius.""" - return TEMP_CELSIUS - @property def current_temperature(self): """Return the current temperature.""" diff --git a/homeassistant/components/smarttub/climate.py b/homeassistant/components/smarttub/climate.py index 8789c33bc9a..78d1d7b2495 100644 --- a/homeassistant/components/smarttub/climate.py +++ b/homeassistant/components/smarttub/climate.py @@ -61,16 +61,12 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE ) + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, coordinator, spa): """Initialize the entity.""" super().__init__(coordinator, spa, "Thermostat") - @property - def temperature_unit(self): - """Return the unit of measurement used by the platform.""" - return TEMP_CELSIUS - @property def hvac_action(self) -> HVACAction | None: """Return the current running hvac operation.""" diff --git a/homeassistant/components/spider/climate.py b/homeassistant/components/spider/climate.py index e80ec77592b..fa04cbbe058 100644 --- a/homeassistant/components/spider/climate.py +++ b/homeassistant/components/spider/climate.py @@ -35,6 +35,8 @@ async def async_setup_entry( class SpiderThermostat(ClimateEntity): """Representation of a thermostat.""" + _attr_temperature_unit = TEMP_CELSIUS + def __init__(self, api, thermostat): """Initialize the thermostat.""" self.api = api @@ -75,11 +77,6 @@ class SpiderThermostat(ClimateEntity): """Return the name of the thermostat, if any.""" return self.thermostat.name - @property - def temperature_unit(self): - """Return the unit of measurement.""" - return TEMP_CELSIUS - @property def current_temperature(self): """Return the current temperature.""" diff --git a/homeassistant/components/stiebel_eltron/climate.py b/homeassistant/components/stiebel_eltron/climate.py index 1aab76813ee..4d63820899e 100644 --- a/homeassistant/components/stiebel_eltron/climate.py +++ b/homeassistant/components/stiebel_eltron/climate.py @@ -74,6 +74,7 @@ class StiebelEltron(ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, name, ste_data): """Initialize the unit.""" @@ -112,10 +113,6 @@ class StiebelEltron(ClimateEntity): return self._name # Handle ClimateEntityFeature.TARGET_TEMPERATURE - @property - def temperature_unit(self): - """Return the unit of measurement.""" - return TEMP_CELSIUS @property def current_temperature(self): diff --git a/homeassistant/components/tado/climate.py b/homeassistant/components/tado/climate.py index 87ca302f029..ae9c2097f75 100644 --- a/homeassistant/components/tado/climate.py +++ b/homeassistant/components/tado/climate.py @@ -213,6 +213,8 @@ def create_climate_entity(tado, name: str, zone_id: int, device_info: dict): class TadoClimate(TadoZoneEntity, ClimateEntity): """Representation of a Tado climate entity.""" + _attr_temperature_unit = TEMP_CELSIUS + def __init__( self, tado, @@ -367,11 +369,6 @@ class TadoClimate(TadoZoneEntity, ClimateEntity): """Set new preset mode.""" self._tado.set_presence(preset_mode) - @property - def temperature_unit(self): - """Return the unit of measurement used by the platform.""" - return TEMP_CELSIUS - @property def target_temperature_step(self): """Return the supported step of target temperature.""" diff --git a/homeassistant/components/tfiac/climate.py b/homeassistant/components/tfiac/climate.py index 937723440f5..58f16d1cc99 100644 --- a/homeassistant/components/tfiac/climate.py +++ b/homeassistant/components/tfiac/climate.py @@ -82,6 +82,7 @@ class TfiacClimate(ClimateEntity): | ClimateEntityFeature.SWING_MODE | ClimateEntityFeature.TARGET_TEMPERATURE ) + _attr_temperature_unit = TEMP_FAHRENHEIT def __init__(self, hass, client): """Init class.""" @@ -121,11 +122,6 @@ class TfiacClimate(ClimateEntity): """Return the temperature we try to reach.""" return self._client.status["target_temp"] - @property - def temperature_unit(self): - """Return the unit of measurement.""" - return TEMP_FAHRENHEIT - @property def current_temperature(self): """Return the current temperature.""" diff --git a/homeassistant/components/touchline/climate.py b/homeassistant/components/touchline/climate.py index 8c5eca09d3d..78fd00b734c 100644 --- a/homeassistant/components/touchline/climate.py +++ b/homeassistant/components/touchline/climate.py @@ -64,6 +64,7 @@ class Touchline(ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, touchline_thermostat): """Initialize the Touchline device.""" @@ -89,11 +90,6 @@ class Touchline(ClimateEntity): """Return the name of the climate device.""" return self._name - @property - def temperature_unit(self): - """Return the unit of measurement.""" - return TEMP_CELSIUS - @property def current_temperature(self): """Return the current temperature.""" diff --git a/homeassistant/components/vicare/climate.py b/homeassistant/components/vicare/climate.py index 8f00f9e6c3b..94f7b8d4e5d 100644 --- a/homeassistant/components/vicare/climate.py +++ b/homeassistant/components/vicare/climate.py @@ -145,6 +145,7 @@ class ViCareClimate(ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, name, api, circuit, device_config, heating_type): """Initialize the climate device.""" @@ -249,11 +250,6 @@ class ViCareClimate(ClimateEntity): """Return the name of the climate device.""" return self._name - @property - def temperature_unit(self): - """Return the unit of measurement.""" - return TEMP_CELSIUS - @property def current_temperature(self): """Return the current temperature.""" diff --git a/homeassistant/components/zha/climate.py b/homeassistant/components/zha/climate.py index d8b2f0db3af..416d0c81483 100644 --- a/homeassistant/components/zha/climate.py +++ b/homeassistant/components/zha/climate.py @@ -137,6 +137,8 @@ class Thermostat(ZhaEntity, ClimateEntity): DEFAULT_MAX_TEMP = 35 DEFAULT_MIN_TEMP = 7 + _attr_temperature_unit = TEMP_CELSIUS + def __init__(self, unique_id, zha_device, channels, **kwargs): """Initialize ZHA Thermostat instance.""" super().__init__(unique_id, zha_device, channels, **kwargs) @@ -334,11 +336,6 @@ class Thermostat(ZhaEntity, ClimateEntity): return temp return round(temp / ZCL_TEMP, 1) - @property - def temperature_unit(self): - """Return the unit of measurement used by the platform.""" - return TEMP_CELSIUS - @property def max_temp(self) -> float: """Return the maximum temperature.""" diff --git a/homeassistant/components/zhong_hong/climate.py b/homeassistant/components/zhong_hong/climate.py index 9ceae1fea72..0877e19834f 100644 --- a/homeassistant/components/zhong_hong/climate.py +++ b/homeassistant/components/zhong_hong/climate.py @@ -128,6 +128,7 @@ class ZhongHongClimate(ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE ) + _attr_temperature_unit = TEMP_CELSIUS def __init__(self, hub, addr_out, addr_in): """Set up the ZhongHong climate devices.""" @@ -171,11 +172,6 @@ class ZhongHongClimate(ClimateEntity): """Return the unique ID of the HVAC.""" return f"zhong_hong_hvac_{self._device.addr_out}_{self._device.addr_in}" - @property - def temperature_unit(self): - """Return the unit of measurement used by the platform.""" - return TEMP_CELSIUS - @property def hvac_mode(self) -> HVACMode: """Return current operation ie. heat, cool, idle."""