From 8b867d612ff7d1dbfd76b540932b6b1a24cf08d4 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 2 Dec 2022 19:56:18 +0100 Subject: [PATCH] Use UnitOfTemperature in climate entities [m-s] (#83131) --- homeassistant/components/maxcube/climate.py | 4 ++-- homeassistant/components/melcloud/climate.py | 4 ++-- homeassistant/components/melissa/climate.py | 4 ++-- homeassistant/components/mill/climate.py | 6 ++--- homeassistant/components/modbus/climate.py | 7 +++--- .../components/moehlenhoff_alpha2/climate.py | 4 ++-- homeassistant/components/mysensors/climate.py | 11 ++++----- homeassistant/components/netatmo/climate.py | 4 ++-- homeassistant/components/nexia/climate.py | 6 +++-- homeassistant/components/nobo_hub/climate.py | 4 ++-- homeassistant/components/nuheat/climate.py | 6 ++--- homeassistant/components/oem/climate.py | 4 ++-- .../components/opentherm_gw/climate.py | 8 +++---- homeassistant/components/plugwise/climate.py | 4 ++-- homeassistant/components/proliphix/climate.py | 4 ++-- .../components/radiotherm/climate.py | 4 ++-- homeassistant/components/schluter/climate.py | 5 ++-- .../components/screenlogic/climate.py | 6 ++--- homeassistant/components/sensibo/climate.py | 23 +++++++++++++------ homeassistant/components/senz/climate.py | 4 ++-- homeassistant/components/shelly/climate.py | 4 ++-- .../components/smartthings/climate.py | 4 ++-- homeassistant/components/smarttub/climate.py | 8 +++---- homeassistant/components/spider/climate.py | 4 ++-- .../components/stiebel_eltron/climate.py | 4 ++-- homeassistant/components/switchbee/climate.py | 6 ++--- .../components/switcher_kis/climate.py | 4 ++-- 27 files changed, 82 insertions(+), 74 deletions(-) diff --git a/homeassistant/components/maxcube/climate.py b/homeassistant/components/maxcube/climate.py index 733736606f6..828696a9ff0 100644 --- a/homeassistant/components/maxcube/climate.py +++ b/homeassistant/components/maxcube/climate.py @@ -23,7 +23,7 @@ from homeassistant.components.climate import ( HVACAction, HVACMode, ) -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -79,7 +79,7 @@ class MaxCubeClimate(ClimateEntity): self._device = device self._attr_should_poll = True self._attr_unique_id = self._device.serial - self._attr_temperature_unit = TEMP_CELSIUS + self._attr_temperature_unit = UnitOfTemperature.CELSIUS self._attr_preset_modes = [ PRESET_NONE, PRESET_BOOST, diff --git a/homeassistant/components/melcloud/climate.py b/homeassistant/components/melcloud/climate.py index 9fc455893f6..323108cd5c5 100644 --- a/homeassistant/components/melcloud/climate.py +++ b/homeassistant/components/melcloud/climate.py @@ -23,7 +23,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -98,7 +98,7 @@ async def async_setup_entry( class MelCloudClimate(ClimateEntity): """Base climate device.""" - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, device: MelCloudDevice) -> None: """Initialize the climate.""" diff --git a/homeassistant/components/melissa/climate.py b/homeassistant/components/melissa/climate.py index bfe1a4929d0..9facb18ed05 100644 --- a/homeassistant/components/melissa/climate.py +++ b/homeassistant/components/melissa/climate.py @@ -13,7 +13,7 @@ from homeassistant.components.climate import ( ClimateEntityFeature, HVACMode, ) -from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -59,7 +59,7 @@ class MelissaClimate(ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.TARGET_TEMPERATURE ) - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, api, serial_number, init_data): """Initialize the climate device.""" diff --git a/homeassistant/components/mill/climate.py b/homeassistant/components/mill/climate.py index 84f87e79a2d..912495d05e8 100644 --- a/homeassistant/components/mill/climate.py +++ b/homeassistant/components/mill/climate.py @@ -19,7 +19,7 @@ from homeassistant.const import ( CONF_USERNAME, PRECISION_HALVES, PRECISION_WHOLE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.helpers import config_validation as cv @@ -92,7 +92,7 @@ class MillHeater(CoordinatorEntity, ClimateEntity): _attr_fan_modes = [FAN_ON, FAN_OFF] _attr_max_temp = MAX_TEMP _attr_min_temp = MIN_TEMP - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, coordinator, heater): """Initialize the thermostat.""" @@ -205,7 +205,7 @@ class LocalMillHeater(CoordinatorEntity, ClimateEntity): _attr_min_temp = MIN_TEMP _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE _attr_target_temperature_step = PRECISION_HALVES - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, coordinator): """Initialize the thermostat.""" diff --git a/homeassistant/components/modbus/climate.py b/homeassistant/components/modbus/climate.py index 4e6fdf6cae7..5573ef0b7ec 100644 --- a/homeassistant/components/modbus/climate.py +++ b/homeassistant/components/modbus/climate.py @@ -17,8 +17,7 @@ from homeassistant.const import ( CONF_TEMPERATURE_UNIT, PRECISION_TENTHS, PRECISION_WHOLE, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -89,7 +88,9 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity): self._attr_current_temperature = None self._attr_target_temperature = None self._attr_temperature_unit = ( - TEMP_FAHRENHEIT if self._unit == "F" else TEMP_CELSIUS + UnitOfTemperature.FAHRENHEIT + if self._unit == "F" + else UnitOfTemperature.CELSIUS ) self._attr_precision = ( PRECISION_TENTHS if self._precision >= 1 else PRECISION_WHOLE diff --git a/homeassistant/components/moehlenhoff_alpha2/climate.py b/homeassistant/components/moehlenhoff_alpha2/climate.py index 5eac2095706..1868be11f67 100644 --- a/homeassistant/components/moehlenhoff_alpha2/climate.py +++ b/homeassistant/components/moehlenhoff_alpha2/climate.py @@ -9,7 +9,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -45,7 +45,7 @@ class Alpha2Climate(CoordinatorEntity[Alpha2BaseCoordinator], ClimateEntity): ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) _attr_hvac_modes = [HVACMode.HEAT, HVACMode.COOL] - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS _attr_preset_modes = [PRESET_AUTO, PRESET_DAY, PRESET_NIGHT] def __init__(self, coordinator: Alpha2BaseCoordinator, heat_area_id: str) -> None: diff --git a/homeassistant/components/mysensors/climate.py b/homeassistant/components/mysensors/climate.py index 38077768f2e..6d101c4f7a5 100644 --- a/homeassistant/components/mysensors/climate.py +++ b/homeassistant/components/mysensors/climate.py @@ -11,12 +11,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - ATTR_TEMPERATURE, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, - Platform, -) +from homeassistant.const import ATTR_TEMPERATURE, Platform, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -96,7 +91,9 @@ class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateEntity): def temperature_unit(self) -> str: """Return the unit of measurement.""" return ( - TEMP_CELSIUS if self.hass.config.units is METRIC_SYSTEM else TEMP_FAHRENHEIT + UnitOfTemperature.CELSIUS + if self.hass.config.units is METRIC_SYSTEM + else UnitOfTemperature.FAHRENHEIT ) @property diff --git a/homeassistant/components/netatmo/climate.py b/homeassistant/components/netatmo/climate.py index 15b3e35ce05..94844578d9d 100644 --- a/homeassistant/components/netatmo/climate.py +++ b/homeassistant/components/netatmo/climate.py @@ -23,7 +23,7 @@ from homeassistant.const import ( ATTR_TEMPERATURE, PRECISION_HALVES, STATE_OFF, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import config_validation as cv, entity_platform @@ -134,7 +134,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity): _attr_preset_modes = SUPPORT_PRESET _attr_supported_features = SUPPORT_FLAGS _attr_target_temperature_step = PRECISION_HALVES - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, netatmo_device: NetatmoRoom) -> None: """Initialize the sensor.""" diff --git a/homeassistant/components/nexia/climate.py b/homeassistant/components/nexia/climate.py index aa7c55df33f..fe31263a86c 100644 --- a/homeassistant/components/nexia/climate.py +++ b/homeassistant/components/nexia/climate.py @@ -31,7 +31,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_platform import homeassistant.helpers.config_validation as cv @@ -178,7 +178,9 @@ class NexiaZone(NexiaThermostatZoneEntity, ClimateEntity): self._attr_max_humidity = percent_conv(max_humidity) self._attr_min_temp = min_setpoint self._attr_max_temp = max_setpoint - self._attr_temperature_unit = TEMP_CELSIUS if unit == "C" else TEMP_FAHRENHEIT + self._attr_temperature_unit = ( + UnitOfTemperature.CELSIUS if unit == "C" else UnitOfTemperature.FAHRENHEIT + ) self._attr_target_temperature_step = 0.5 if unit == "C" else 1.0 @property diff --git a/homeassistant/components/nobo_hub/climate.py b/homeassistant/components/nobo_hub/climate.py index d138788fba0..f12d518a039 100644 --- a/homeassistant/components/nobo_hub/climate.py +++ b/homeassistant/components/nobo_hub/climate.py @@ -24,7 +24,7 @@ from homeassistant.const import ( ATTR_SUGGESTED_AREA, ATTR_VIA_DEVICE, PRECISION_TENTHS, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import DeviceInfo @@ -84,7 +84,7 @@ class NoboZone(ClimateEntity): _attr_precision = PRECISION_TENTHS _attr_preset_modes = PRESET_MODES _attr_supported_features = SUPPORT_FLAGS - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS _attr_target_temperature_step = 1 # Need to poll to get preset change when in HVACMode.AUTO, so can't set _attr_should_poll = False diff --git a/homeassistant/components/nuheat/climate.py b/homeassistant/components/nuheat/climate.py index 0c053a8c67f..aa692153215 100644 --- a/homeassistant/components/nuheat/climate.py +++ b/homeassistant/components/nuheat/climate.py @@ -18,7 +18,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import event as event_helper from homeassistant.helpers.entity import DeviceInfo @@ -93,9 +93,9 @@ class NuHeatThermostat(CoordinatorEntity, ClimateEntity): def temperature_unit(self) -> str: """Return the unit of measurement.""" if self._temperature_unit == "C": - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS - return TEMP_FAHRENHEIT + return UnitOfTemperature.FAHRENHEIT @property def current_temperature(self): diff --git a/homeassistant/components/oem/climate.py b/homeassistant/components/oem/climate.py index d6337807fc2..1b600b25d94 100644 --- a/homeassistant/components/oem/climate.py +++ b/homeassistant/components/oem/climate.py @@ -21,7 +21,7 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_PORT, CONF_USERNAME, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -67,7 +67,7 @@ class ThermostatDevice(ClimateEntity): _attr_hvac_modes = SUPPORT_HVAC _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, thermostat, name): """Initialize the device.""" diff --git a/homeassistant/components/opentherm_gw/climate.py b/homeassistant/components/opentherm_gw/climate.py index 08cfbf68ac8..66223996180 100644 --- a/homeassistant/components/opentherm_gw/climate.py +++ b/homeassistant/components/opentherm_gw/climate.py @@ -22,7 +22,7 @@ from homeassistant.const import ( PRECISION_HALVES, PRECISION_TENTHS, PRECISION_WHOLE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -68,7 +68,7 @@ class OpenThermClimate(ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, gw_dev, options): """Initialize the device.""" @@ -201,7 +201,7 @@ class OpenThermClimate(ClimateEntity): """Return the precision of the system.""" if self.temp_read_precision: return self.temp_read_precision - if self.hass.config.units.temperature_unit == TEMP_CELSIUS: + if self.hass.config.units.temperature_unit == UnitOfTemperature.CELSIUS: return PRECISION_HALVES return PRECISION_WHOLE @@ -247,7 +247,7 @@ class OpenThermClimate(ClimateEntity): """Return the supported step of target temperature.""" if self.temp_set_precision: return self.temp_set_precision - if self.hass.config.units.temperature_unit == TEMP_CELSIUS: + if self.hass.config.units.temperature_unit == UnitOfTemperature.CELSIUS: return PRECISION_HALVES return PRECISION_WHOLE diff --git a/homeassistant/components/plugwise/climate.py b/homeassistant/components/plugwise/climate.py index 8d0d3578c2c..83a38477975 100644 --- a/homeassistant/components/plugwise/climate.py +++ b/homeassistant/components/plugwise/climate.py @@ -13,7 +13,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -41,7 +41,7 @@ async def async_setup_entry( class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity): """Representation of an Plugwise thermostat.""" - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS _attr_has_entity_name = True def __init__( diff --git a/homeassistant/components/proliphix/climate.py b/homeassistant/components/proliphix/climate.py index 4ff1ff0906c..5f841441d59 100644 --- a/homeassistant/components/proliphix/climate.py +++ b/homeassistant/components/proliphix/climate.py @@ -19,7 +19,7 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_USERNAME, PRECISION_TENTHS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -59,7 +59,7 @@ class ProliphixThermostat(ClimateEntity): _attr_precision = PRECISION_TENTHS _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE - _attr_temperature_unit = TEMP_FAHRENHEIT + _attr_temperature_unit = UnitOfTemperature.FAHRENHEIT def __init__(self, pdp): """Initialize the thermostat.""" diff --git a/homeassistant/components/radiotherm/climate.py b/homeassistant/components/radiotherm/climate.py index f8ccf068f69..3de56a3c4a4 100644 --- a/homeassistant/components/radiotherm/climate.py +++ b/homeassistant/components/radiotherm/climate.py @@ -24,7 +24,7 @@ from homeassistant.const import ( ATTR_TEMPERATURE, CONF_HOST, PRECISION_HALVES, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv @@ -169,7 +169,7 @@ class RadioThermostat(RadioThermostatEntity, ClimateEntity): """Representation of a Radio Thermostat.""" _attr_hvac_modes = OPERATION_LIST - _attr_temperature_unit = TEMP_FAHRENHEIT + _attr_temperature_unit = UnitOfTemperature.FAHRENHEIT _attr_precision = PRECISION_HALVES def __init__(self, coordinator: RadioThermUpdateCoordinator) -> None: diff --git a/homeassistant/components/schluter/climate.py b/homeassistant/components/schluter/climate.py index 24a09437d4b..c8c0d76690d 100644 --- a/homeassistant/components/schluter/climate.py +++ b/homeassistant/components/schluter/climate.py @@ -10,13 +10,12 @@ import voluptuous as vol from homeassistant.components.climate import ( PLATFORM_SCHEMA, SCAN_INTERVAL, - TEMP_CELSIUS, ClimateEntity, ClimateEntityFeature, HVACAction, HVACMode, ) -from homeassistant.const import ATTR_TEMPERATURE, CONF_SCAN_INTERVAL +from homeassistant.const import ATTR_TEMPERATURE, CONF_SCAN_INTERVAL, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -81,7 +80,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 + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, coordinator, serial_number, api, session_id): """Initialize the thermostat.""" diff --git a/homeassistant/components/screenlogic/climate.py b/homeassistant/components/screenlogic/climate.py index 4b28eea7208..5b7a4f591b3 100644 --- a/homeassistant/components/screenlogic/climate.py +++ b/homeassistant/components/screenlogic/climate.py @@ -12,7 +12,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -98,8 +98,8 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity): def temperature_unit(self) -> str: """Return the unit of measurement.""" if self.config_data["is_celsius"]["value"] == 1: - return TEMP_CELSIUS - return TEMP_FAHRENHEIT + return UnitOfTemperature.CELSIUS + return UnitOfTemperature.FAHRENHEIT @property def hvac_mode(self) -> HVACMode: diff --git a/homeassistant/components/sensibo/climate.py b/homeassistant/components/sensibo/climate.py index b1980b5e595..583d25112b4 100644 --- a/homeassistant/components/sensibo/climate.py +++ b/homeassistant/components/sensibo/climate.py @@ -19,8 +19,7 @@ from homeassistant.const import ( ATTR_STATE, ATTR_TEMPERATURE, PRECISION_TENTHS, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -171,7 +170,9 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity): super().__init__(coordinator, device_id) self._attr_unique_id = device_id self._attr_temperature_unit = ( - TEMP_CELSIUS if self.device_data.temp_unit == "C" else TEMP_FAHRENHEIT + UnitOfTemperature.CELSIUS + if self.device_data.temp_unit == "C" + else UnitOfTemperature.FAHRENHEIT ) self._attr_supported_features = self.get_features() self._attr_precision = PRECISION_TENTHS @@ -212,7 +213,7 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity): if self.device_data.temp: return TemperatureConverter.convert( self.device_data.temp, - TEMP_CELSIUS, + UnitOfTemperature.CELSIUS, self.temperature_unit, ) return None @@ -220,7 +221,11 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity): @property def temperature_unit(self) -> str: """Return temperature unit.""" - return TEMP_CELSIUS if self.device_data.temp_unit == "C" else TEMP_FAHRENHEIT + return ( + UnitOfTemperature.CELSIUS + if self.device_data.temp_unit == "C" + else UnitOfTemperature.FAHRENHEIT + ) @property def target_temperature(self) -> float | None: @@ -464,10 +469,14 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity): if high_temperature_state.get("temperatureUnit") == "F": high_temp = TemperatureConverter.convert( - high_temperature_threshold, TEMP_FAHRENHEIT, TEMP_CELSIUS + high_temperature_threshold, + UnitOfTemperature.FAHRENHEIT, + UnitOfTemperature.CELSIUS, ) low_temp = TemperatureConverter.convert( - low_temperature_threshold, TEMP_FAHRENHEIT, TEMP_CELSIUS + low_temperature_threshold, + UnitOfTemperature.FAHRENHEIT, + UnitOfTemperature.CELSIUS, ) params: dict[str, str | bool | float | dict] = { diff --git a/homeassistant/components/senz/climate.py b/homeassistant/components/senz/climate.py index 2e023e13491..f52a94d2c9a 100644 --- a/homeassistant/components/senz/climate.py +++ b/homeassistant/components/senz/climate.py @@ -12,7 +12,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -37,7 +37,7 @@ async def async_setup_entry( class SENZClimate(CoordinatorEntity, ClimateEntity): """Representation of a SENZ climate entity.""" - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS _attr_precision = PRECISION_TENTHS _attr_hvac_modes = [HVACMode.HEAT, HVACMode.AUTO] _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE diff --git a/homeassistant/components/shelly/climate.py b/homeassistant/components/shelly/climate.py index cc831c10ee0..28ecf0f231c 100644 --- a/homeassistant/components/shelly/climate.py +++ b/homeassistant/components/shelly/climate.py @@ -16,7 +16,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant, State, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import device_registry, entity_registry @@ -108,7 +108,7 @@ class BlockSleepingClimate( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) _attr_target_temperature_step = SHTRV_01_TEMPERATURE_SETTINGS["step"] - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__( self, diff --git a/homeassistant/components/smartthings/climate.py b/homeassistant/components/smartthings/climate.py index 8a516dfc356..e49ecd7abf9 100644 --- a/homeassistant/components/smartthings/climate.py +++ b/homeassistant/components/smartthings/climate.py @@ -19,7 +19,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -71,7 +71,7 @@ STATE_TO_AC_MODE = { HVACMode.FAN_ONLY: "fanOnly", } -UNIT_MAP = {"C": TEMP_CELSIUS, "F": TEMP_FAHRENHEIT} +UNIT_MAP = {"C": UnitOfTemperature.CELSIUS, "F": UnitOfTemperature.FAHRENHEIT} _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/smarttub/climate.py b/homeassistant/components/smarttub/climate.py index 0afebbd6433..a938bde6fd1 100644 --- a/homeassistant/components/smarttub/climate.py +++ b/homeassistant/components/smarttub/climate.py @@ -14,7 +14,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.util.unit_conversion import TemperatureConverter @@ -63,7 +63,7 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE ) - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, coordinator, spa): """Initialize the entity.""" @@ -88,7 +88,7 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity): """Return the minimum temperature.""" min_temp = DEFAULT_MIN_TEMP return TemperatureConverter.convert( - min_temp, TEMP_CELSIUS, self.temperature_unit + min_temp, UnitOfTemperature.CELSIUS, self.temperature_unit ) @property @@ -96,7 +96,7 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity): """Return the maximum temperature.""" max_temp = DEFAULT_MAX_TEMP return TemperatureConverter.convert( - max_temp, TEMP_CELSIUS, self.temperature_unit + max_temp, UnitOfTemperature.CELSIUS, self.temperature_unit ) @property diff --git a/homeassistant/components/spider/climate.py b/homeassistant/components/spider/climate.py index 111c1e377cf..261d1565160 100644 --- a/homeassistant/components/spider/climate.py +++ b/homeassistant/components/spider/climate.py @@ -7,7 +7,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -40,7 +40,7 @@ async def async_setup_entry( class SpiderThermostat(ClimateEntity): """Representation of a thermostat.""" - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, api, thermostat): """Initialize the thermostat.""" diff --git a/homeassistant/components/stiebel_eltron/climate.py b/homeassistant/components/stiebel_eltron/climate.py index 25c24c50ece..88cce6c52d7 100644 --- a/homeassistant/components/stiebel_eltron/climate.py +++ b/homeassistant/components/stiebel_eltron/climate.py @@ -10,7 +10,7 @@ from homeassistant.components.climate import ( ClimateEntityFeature, HVACMode, ) -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -75,7 +75,7 @@ class StiebelEltron(ClimateEntity): _attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) - _attr_temperature_unit = TEMP_CELSIUS + _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, name, ste_data): """Initialize the unit.""" diff --git a/homeassistant/components/switchbee/climate.py b/homeassistant/components/switchbee/climate.py index 8d0024b75ed..6cdf7d700a5 100644 --- a/homeassistant/components/switchbee/climate.py +++ b/homeassistant/components/switchbee/climate.py @@ -23,7 +23,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -65,8 +65,8 @@ HVAC_ACTION_SB_TO_HASS = { } HVAC_UNIT_SB_TO_HASS = { - ThermostatTemperatureUnit.CELSIUS: TEMP_CELSIUS, - ThermostatTemperatureUnit.FAHRENHEIT: TEMP_FAHRENHEIT, + ThermostatTemperatureUnit.CELSIUS: UnitOfTemperature.CELSIUS, + ThermostatTemperatureUnit.FAHRENHEIT: UnitOfTemperature.FAHRENHEIT, } SUPPORTED_FAN_MODES = [FAN_AUTO, FAN_HIGH, FAN_MEDIUM, FAN_LOW] diff --git a/homeassistant/components/switcher_kis/climate.py b/homeassistant/components/switcher_kis/climate.py index 01f4c80da31..57d4d9977f2 100644 --- a/homeassistant/components/switcher_kis/climate.py +++ b/homeassistant/components/switcher_kis/climate.py @@ -26,7 +26,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import device_registry @@ -102,7 +102,7 @@ class SwitcherClimateEntity( self._attr_min_temp = remote.min_temperature self._attr_max_temp = remote.max_temperature self._attr_target_temperature_step = 1 - self._attr_temperature_unit = TEMP_CELSIUS + self._attr_temperature_unit = UnitOfTemperature.CELSIUS self._attr_hvac_modes = [HVACMode.OFF] for mode in remote.modes_features: