diff --git a/homeassistant/components/ecoal_boiler/sensor.py b/homeassistant/components/ecoal_boiler/sensor.py index 5c8bf926fce..06dfec9ff01 100644 --- a/homeassistant/components/ecoal_boiler/sensor.py +++ b/homeassistant/components/ecoal_boiler/sensor.py @@ -2,7 +2,7 @@ from __future__ import annotations from homeassistant.components.sensor import SensorDeviceClass, SensorEntity -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -31,7 +31,7 @@ class EcoalTempSensor(SensorEntity): """Representation of a temperature sensor using ecoal status data.""" _attr_device_class = SensorDeviceClass.TEMPERATURE - _attr_native_unit_of_measurement = TEMP_CELSIUS + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS def __init__(self, ecoal_contr, name, status_attr): """Initialize the sensor.""" diff --git a/homeassistant/components/ecobee/sensor.py b/homeassistant/components/ecobee/sensor.py index 30949e36f8e..b9d61742838 100644 --- a/homeassistant/components/ecobee/sensor.py +++ b/homeassistant/components/ecobee/sensor.py @@ -16,7 +16,7 @@ from homeassistant.const import ( CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONCENTRATION_PARTS_PER_MILLION, PERCENTAGE, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo @@ -43,7 +43,7 @@ SENSOR_TYPES: tuple[EcobeeSensorEntityDescription, ...] = ( EcobeeSensorEntityDescription( key="temperature", name="Temperature", - native_unit_of_measurement=TEMP_FAHRENHEIT, + native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, runtime_key=None, diff --git a/homeassistant/components/econet/__init__.py b/homeassistant/components/econet/__init__.py index 6b312de8b0a..ee8db43baf2 100644 --- a/homeassistant/components/econet/__init__.py +++ b/homeassistant/components/econet/__init__.py @@ -13,7 +13,7 @@ from pyeconet.errors import ( ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, TEMP_FAHRENHEIT, Platform +from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send @@ -156,4 +156,4 @@ class EcoNetEntity(Entity): @property def temperature_unit(self): """Return the unit of measurement.""" - return TEMP_FAHRENHEIT + return UnitOfTemperature.FAHRENHEIT diff --git a/homeassistant/components/eddystone_temperature/sensor.py b/homeassistant/components/eddystone_temperature/sensor.py index d0bf4a87cc2..8e5e7ce48da 100644 --- a/homeassistant/components/eddystone_temperature/sensor.py +++ b/homeassistant/components/eddystone_temperature/sensor.py @@ -22,7 +22,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, STATE_UNKNOWN, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import Event, HomeAssistant import homeassistant.helpers.config_validation as cv @@ -114,7 +114,7 @@ class EddystoneTemp(SensorEntity): """Representation of a temperature sensor.""" _attr_device_class = SensorDeviceClass.TEMPERATURE - _attr_native_unit_of_measurement = TEMP_CELSIUS + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS _attr_should_poll = False def __init__(self, name: str, namespace: str, instance: str) -> None: diff --git a/homeassistant/components/enocean/sensor.py b/homeassistant/components/enocean/sensor.py index 3a070a57671..702b721ab09 100644 --- a/homeassistant/components/enocean/sensor.py +++ b/homeassistant/components/enocean/sensor.py @@ -21,8 +21,8 @@ from homeassistant.const import ( PERCENTAGE, STATE_CLOSED, STATE_OPEN, - TEMP_CELSIUS, UnitOfPower, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -62,7 +62,7 @@ class EnOceanSensorEntityDescription( SENSOR_DESC_TEMPERATURE = EnOceanSensorEntityDescription( key=SENSOR_TYPE_TEMPERATURE, name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, icon="mdi:thermometer", device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, diff --git a/homeassistant/components/flo/sensor.py b/homeassistant/components/flo/sensor.py index 68c9adc8c9f..2c89123dac1 100644 --- a/homeassistant/components/flo/sensor.py +++ b/homeassistant/components/flo/sensor.py @@ -9,8 +9,8 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, - TEMP_FAHRENHEIT, UnitOfPressure, + UnitOfTemperature, UnitOfVolume, ) from homeassistant.core import HomeAssistant @@ -125,7 +125,7 @@ class FloTemperatureSensor(FloEntity, SensorEntity): """Monitors the temperature.""" _attr_device_class = SensorDeviceClass.TEMPERATURE - _attr_native_unit_of_measurement = TEMP_FAHRENHEIT + _attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT _attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT def __init__(self, name, device): diff --git a/homeassistant/components/foobot/sensor.py b/homeassistant/components/foobot/sensor.py index 82a48c810c3..a865dd33053 100644 --- a/homeassistant/components/foobot/sensor.py +++ b/homeassistant/components/foobot/sensor.py @@ -23,7 +23,7 @@ from homeassistant.const import ( CONF_TOKEN, CONF_USERNAME, PERCENTAGE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady @@ -52,7 +52,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="tmp", name=ATTR_TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, ), SensorEntityDescription( diff --git a/homeassistant/components/freedompro/sensor.py b/homeassistant/components/freedompro/sensor.py index c5dc2a26bd0..286a528013a 100644 --- a/homeassistant/components/freedompro/sensor.py +++ b/homeassistant/components/freedompro/sensor.py @@ -7,7 +7,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import LIGHT_LUX, PERCENTAGE, TEMP_CELSIUS +from homeassistant.const import LIGHT_LUX, PERCENTAGE, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -27,7 +27,7 @@ STATE_CLASS_MAP = { "lightSensor": None, } UNIT_MAP = { - "temperatureSensor": TEMP_CELSIUS, + "temperatureSensor": UnitOfTemperature.CELSIUS, "humiditySensor": PERCENTAGE, "lightSensor": LIGHT_LUX, } diff --git a/homeassistant/components/fritzbox/__init__.py b/homeassistant/components/fritzbox/__init__.py index 43bd0bfeeb0..fc65ed96459 100644 --- a/homeassistant/components/fritzbox/__init__.py +++ b/homeassistant/components/fritzbox/__init__.py @@ -14,7 +14,7 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import Event, HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed @@ -62,7 +62,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: def _update_unique_id(entry: RegistryEntry) -> dict[str, str] | None: """Update unique ID of entity entry.""" if ( - entry.unit_of_measurement == TEMP_CELSIUS + entry.unit_of_measurement == UnitOfTemperature.CELSIUS and "_temperature" not in entry.unique_id ): new_unique_id = f"{entry.unique_id}_temperature" diff --git a/homeassistant/components/fritzbox/sensor.py b/homeassistant/components/fritzbox/sensor.py index 9ba0b0be48f..ef068e3af2a 100644 --- a/homeassistant/components/fritzbox/sensor.py +++ b/homeassistant/components/fritzbox/sensor.py @@ -18,11 +18,11 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, - TEMP_CELSIUS, UnitOfElectricCurrent, UnitOfElectricPotential, UnitOfEnergy, UnitOfPower, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -103,7 +103,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = ( FritzSensorEntityDescription( key="temperature", name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, entity_category=EntityCategory.DIAGNOSTIC, @@ -168,7 +168,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = ( FritzSensorEntityDescription( key="comfort_temperature", name="Comfort Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, suitable=suitable_comfort_temperature, native_value=lambda device: device.comfort_temperature, # type: ignore[no-any-return] @@ -176,7 +176,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = ( FritzSensorEntityDescription( key="eco_temperature", name="Eco Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, suitable=suitable_eco_temperature, native_value=lambda device: device.eco_temperature, # type: ignore[no-any-return] @@ -184,7 +184,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = ( FritzSensorEntityDescription( key="nextchange_temperature", name="Next Scheduled Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, suitable=suitable_nextchange_temperature, native_value=lambda device: device.nextchange_temperature, # type: ignore[no-any-return] diff --git a/homeassistant/components/geniushub/__init__.py b/homeassistant/components/geniushub/__init__.py index fc04f314812..32a15285d6c 100644 --- a/homeassistant/components/geniushub/__init__.py +++ b/homeassistant/components/geniushub/__init__.py @@ -17,8 +17,8 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME, - TEMP_CELSIUS, Platform, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.helpers import config_validation as cv, entity_registry as er @@ -356,7 +356,7 @@ class GeniusHeatingZone(GeniusZone): @property def temperature_unit(self) -> str: """Return the unit of measurement.""" - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS async def async_set_temperature(self, **kwargs) -> None: """Set a new target temperature for this zone.""" diff --git a/homeassistant/components/glances/sensor.py b/homeassistant/components/glances/sensor.py index 0b18d22084e..7e9d767f20d 100644 --- a/homeassistant/components/glances/sensor.py +++ b/homeassistant/components/glances/sensor.py @@ -16,9 +16,9 @@ from homeassistant.const import ( PERCENTAGE, REVOLUTIONS_PER_MINUTE, STATE_UNAVAILABLE, - TEMP_CELSIUS, Platform, UnitOfInformation, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_registry @@ -171,7 +171,7 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = ( key="temperature_core", type="sensors", name_suffix="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, ), @@ -179,7 +179,7 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = ( key="temperature_hdd", type="sensors", name_suffix="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, ), diff --git a/homeassistant/components/goalzero/sensor.py b/homeassistant/components/goalzero/sensor.py index 4baff11e711..e75f21f1152 100644 --- a/homeassistant/components/goalzero/sensor.py +++ b/homeassistant/components/goalzero/sensor.py @@ -13,11 +13,11 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, SIGNAL_STRENGTH_DECIBELS, - TEMP_CELSIUS, UnitOfElectricCurrent, UnitOfElectricPotential, UnitOfEnergy, UnitOfPower, + UnitOfTemperature, UnitOfTime, ) from homeassistant.core import HomeAssistant @@ -97,7 +97,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="temperature", name="Temperature", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, entity_category=EntityCategory.DIAGNOSTIC, ), SensorEntityDescription( diff --git a/homeassistant/components/gogogate2/sensor.py b/homeassistant/components/gogogate2/sensor.py index 1f48dde007e..378d9742da0 100644 --- a/homeassistant/components/gogogate2/sensor.py +++ b/homeassistant/components/gogogate2/sensor.py @@ -11,7 +11,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import PERCENTAGE, TEMP_CELSIUS +from homeassistant.const import PERCENTAGE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -96,7 +96,7 @@ class DoorSensorTemperature(DoorSensorEntity): _attr_device_class = SensorDeviceClass.TEMPERATURE _attr_state_class = SensorStateClass.MEASUREMENT - _attr_native_unit_of_measurement = TEMP_CELSIUS + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS def __init__( self, diff --git a/homeassistant/components/google_assistant/trait.py b/homeassistant/components/google_assistant/trait.py index a76b0a7d687..8fb5aed76a4 100644 --- a/homeassistant/components/google_assistant/trait.py +++ b/homeassistant/components/google_assistant/trait.py @@ -63,8 +63,7 @@ from homeassistant.const import ( STATE_STANDBY, STATE_UNAVAILABLE, STATE_UNKNOWN, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import DOMAIN as HA_DOMAIN from homeassistant.helpers.network import get_url @@ -175,7 +174,7 @@ def register_trait(trait): def _google_temp_unit(units): """Return Google temperature unit.""" - if units == TEMP_FAHRENHEIT: + if units == UnitOfTemperature.FAHRENHEIT: return "F" return "C" @@ -845,7 +844,10 @@ class TemperatureControlTrait(_Trait): current_temp = self.state.state if current_temp not in (STATE_UNKNOWN, STATE_UNAVAILABLE): temp = round( - TemperatureConverter.convert(float(current_temp), unit, TEMP_CELSIUS), 1 + TemperatureConverter.convert( + float(current_temp), unit, UnitOfTemperature.CELSIUS + ), + 1, ) response["temperatureSetpointCelsius"] = temp response["temperatureAmbientCelsius"] = temp @@ -951,7 +953,10 @@ class TemperatureSettingTrait(_Trait): current_temp = attrs.get(climate.ATTR_CURRENT_TEMPERATURE) if current_temp is not None: response["thermostatTemperatureAmbient"] = round( - TemperatureConverter.convert(current_temp, unit, TEMP_CELSIUS), 1 + TemperatureConverter.convert( + current_temp, unit, UnitOfTemperature.CELSIUS + ), + 1, ) current_humidity = attrs.get(climate.ATTR_CURRENT_HUMIDITY) @@ -962,27 +967,37 @@ class TemperatureSettingTrait(_Trait): if supported & climate.SUPPORT_TARGET_TEMPERATURE_RANGE: response["thermostatTemperatureSetpointHigh"] = round( TemperatureConverter.convert( - attrs[climate.ATTR_TARGET_TEMP_HIGH], unit, TEMP_CELSIUS + attrs[climate.ATTR_TARGET_TEMP_HIGH], + unit, + UnitOfTemperature.CELSIUS, ), 1, ) response["thermostatTemperatureSetpointLow"] = round( TemperatureConverter.convert( - attrs[climate.ATTR_TARGET_TEMP_LOW], unit, TEMP_CELSIUS + attrs[climate.ATTR_TARGET_TEMP_LOW], + unit, + UnitOfTemperature.CELSIUS, ), 1, ) else: if (target_temp := attrs.get(ATTR_TEMPERATURE)) is not None: target_temp = round( - TemperatureConverter.convert(target_temp, unit, TEMP_CELSIUS), 1 + TemperatureConverter.convert( + target_temp, unit, UnitOfTemperature.CELSIUS + ), + 1, ) response["thermostatTemperatureSetpointHigh"] = target_temp response["thermostatTemperatureSetpointLow"] = target_temp else: if (target_temp := attrs.get(ATTR_TEMPERATURE)) is not None: response["thermostatTemperatureSetpoint"] = round( - TemperatureConverter.convert(target_temp, unit, TEMP_CELSIUS), 1 + TemperatureConverter.convert( + target_temp, unit, UnitOfTemperature.CELSIUS + ), + 1, ) return response @@ -996,9 +1011,9 @@ class TemperatureSettingTrait(_Trait): if command == COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT: temp = TemperatureConverter.convert( - params["thermostatTemperatureSetpoint"], TEMP_CELSIUS, unit + params["thermostatTemperatureSetpoint"], UnitOfTemperature.CELSIUS, unit ) - if unit == TEMP_FAHRENHEIT: + if unit == UnitOfTemperature.FAHRENHEIT: temp = round(temp) if temp < min_temp or temp > max_temp: @@ -1017,9 +1032,11 @@ class TemperatureSettingTrait(_Trait): elif command == COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE: temp_high = TemperatureConverter.convert( - params["thermostatTemperatureSetpointHigh"], TEMP_CELSIUS, unit + params["thermostatTemperatureSetpointHigh"], + UnitOfTemperature.CELSIUS, + unit, ) - if unit == TEMP_FAHRENHEIT: + if unit == UnitOfTemperature.FAHRENHEIT: temp_high = round(temp_high) if temp_high < min_temp or temp_high > max_temp: @@ -1032,9 +1049,11 @@ class TemperatureSettingTrait(_Trait): ) temp_low = TemperatureConverter.convert( - params["thermostatTemperatureSetpointLow"], TEMP_CELSIUS, unit + params["thermostatTemperatureSetpointLow"], + UnitOfTemperature.CELSIUS, + unit, ) - if unit == TEMP_FAHRENHEIT: + if unit == UnitOfTemperature.FAHRENHEIT: temp_low = round(temp_low) if temp_low < min_temp or temp_low > max_temp: diff --git a/homeassistant/components/govee_ble/sensor.py b/homeassistant/components/govee_ble/sensor.py index 1d193287419..6014585ffe6 100644 --- a/homeassistant/components/govee_ble/sensor.py +++ b/homeassistant/components/govee_ble/sensor.py @@ -22,7 +22,7 @@ from homeassistant.components.sensor import ( from homeassistant.const import ( PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -34,7 +34,7 @@ SENSOR_DESCRIPTIONS = { (DeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription( key=f"{DeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, ), (DeviceClass.HUMIDITY, Units.PERCENTAGE): SensorEntityDescription( diff --git a/homeassistant/components/growatt_server/sensor_types/inverter.py b/homeassistant/components/growatt_server/sensor_types/inverter.py index 643713bbe06..746e4880cef 100644 --- a/homeassistant/components/growatt_server/sensor_types/inverter.py +++ b/homeassistant/components/growatt_server/sensor_types/inverter.py @@ -3,12 +3,12 @@ from __future__ import annotations from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass from homeassistant.const import ( - TEMP_CELSIUS, UnitOfElectricCurrent, UnitOfElectricPotential, UnitOfEnergy, UnitOfFrequency, UnitOfPower, + UnitOfTemperature, ) from .sensor_entity_description import GrowattSensorEntityDescription @@ -155,7 +155,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = ( key="inverter_ipm_temperature", name="Intelligent Power Management temperature", api_key="ipmTemperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, precision=1, ), @@ -163,7 +163,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = ( key="inverter_temperature", name="Temperature", api_key="temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, precision=1, ), diff --git a/homeassistant/components/growatt_server/sensor_types/tlx.py b/homeassistant/components/growatt_server/sensor_types/tlx.py index 51c7bd8bd94..4703c39a8f9 100644 --- a/homeassistant/components/growatt_server/sensor_types/tlx.py +++ b/homeassistant/components/growatt_server/sensor_types/tlx.py @@ -8,12 +8,12 @@ from __future__ import annotations from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass from homeassistant.const import ( PERCENTAGE, - TEMP_CELSIUS, UnitOfElectricCurrent, UnitOfElectricPotential, UnitOfEnergy, UnitOfFrequency, UnitOfPower, + UnitOfTemperature, ) from .sensor_entity_description import GrowattSensorEntityDescription @@ -255,7 +255,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = ( key="tlx_temperature_1", name="Temperature 1", api_key="temp1", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, precision=1, ), @@ -263,7 +263,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = ( key="tlx_temperature_2", name="Temperature 2", api_key="temp2", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, precision=1, ), @@ -271,7 +271,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = ( key="tlx_temperature_3", name="Temperature 3", api_key="temp3", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, precision=1, ), @@ -279,7 +279,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = ( key="tlx_temperature_4", name="Temperature 4", api_key="temp4", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, precision=1, ), @@ -287,7 +287,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = ( key="tlx_temperature_5", name="Temperature 5", api_key="temp5", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, precision=1, ), diff --git a/homeassistant/components/guardian/sensor.py b/homeassistant/components/guardian/sensor.py index 18ff4c0bc52..4849666736e 100644 --- a/homeassistant/components/guardian/sensor.py +++ b/homeassistant/components/guardian/sensor.py @@ -10,7 +10,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_FAHRENHEIT, UnitOfElectricPotential, UnitOfTime +from homeassistant.const import UnitOfElectricPotential, UnitOfTemperature, UnitOfTime from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import EntityCategory @@ -54,7 +54,7 @@ PAIRED_SENSOR_DESCRIPTIONS = ( key=SENSOR_KIND_TEMPERATURE, name="Temperature", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_FAHRENHEIT, + native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT, state_class=SensorStateClass.MEASUREMENT, ), ) @@ -63,7 +63,7 @@ VALVE_CONTROLLER_DESCRIPTIONS = ( key=SENSOR_KIND_TEMPERATURE, name="Temperature", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_FAHRENHEIT, + native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT, state_class=SensorStateClass.MEASUREMENT, api_category=API_SYSTEM_ONBOARD_SENSOR_STATUS, ), diff --git a/homeassistant/components/hddtemp/sensor.py b/homeassistant/components/hddtemp/sensor.py index 7ff8de90509..117de2116a4 100644 --- a/homeassistant/components/hddtemp/sensor.py +++ b/homeassistant/components/hddtemp/sensor.py @@ -18,8 +18,7 @@ from homeassistant.const import ( CONF_HOST, CONF_NAME, CONF_PORT, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -99,9 +98,9 @@ class HddTempSensor(SensorEntity): self._details = self.hddtemp.data[self.disk].split("|") self._attr_native_value = self._details[2] if self._details is not None and self._details[3] == "F": - self._attr_native_unit_of_measurement = TEMP_FAHRENHEIT + self._attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT else: - self._attr_native_unit_of_measurement = TEMP_CELSIUS + self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS else: self._attr_native_value = None diff --git a/homeassistant/components/homekit/accessories.py b/homeassistant/components/homekit/accessories.py index eef43892677..b43ab932cf6 100644 --- a/homeassistant/components/homekit/accessories.py +++ b/homeassistant/components/homekit/accessories.py @@ -35,8 +35,7 @@ from homeassistant.const import ( PERCENTAGE, STATE_ON, STATE_UNAVAILABLE, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, __version__, ) from homeassistant.core import ( @@ -184,8 +183,8 @@ def get_accessory( # noqa: C901 unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) if device_class == SensorDeviceClass.TEMPERATURE or unit in ( - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature.CELSIUS, + UnitOfTemperature.FAHRENHEIT, ): a_type = "TemperatureSensor" elif device_class == SensorDeviceClass.HUMIDITY and unit == PERCENTAGE: diff --git a/homeassistant/components/homekit/type_sensors.py b/homeassistant/components/homekit/type_sensors.py index 4e9c897dff9..27a1156111f 100644 --- a/homeassistant/components/homekit/type_sensors.py +++ b/homeassistant/components/homekit/type_sensors.py @@ -13,7 +13,7 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, STATE_HOME, STATE_ON, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import callback @@ -124,7 +124,9 @@ class TemperatureSensor(HomeAccessory): @callback def async_update_state(self, new_state): """Update temperature after state changed.""" - unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS) + unit = new_state.attributes.get( + ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature.CELSIUS + ) if (temperature := convert_to_float(new_state.state)) is not None: temperature = temperature_to_homekit(temperature, unit) self.char_temp.set_value(temperature) diff --git a/homeassistant/components/homekit/type_thermostats.py b/homeassistant/components/homekit/type_thermostats.py index d7bee679369..f4bed70c09c 100644 --- a/homeassistant/components/homekit/type_thermostats.py +++ b/homeassistant/components/homekit/type_thermostats.py @@ -53,8 +53,7 @@ from homeassistant.const import ( ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE, PERCENTAGE, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import State, callback from homeassistant.util.percentage import ( @@ -98,7 +97,7 @@ DEFAULT_HVAC_MODES = [ ] HC_HOMEKIT_VALID_MODES_WATER_HEATER = {"Heat": 1} -UNIT_HASS_TO_HOMEKIT = {TEMP_CELSIUS: 0, TEMP_FAHRENHEIT: 1} +UNIT_HASS_TO_HOMEKIT = {UnitOfTemperature.CELSIUS: 0, UnitOfTemperature.FAHRENHEIT: 1} HC_HEAT_COOL_OFF = 0 HC_HEAT_COOL_HEAT = 1 diff --git a/homeassistant/components/homekit/util.py b/homeassistant/components/homekit/util.py index 413786c22c4..2663f7b004d 100644 --- a/homeassistant/components/homekit/util.py +++ b/homeassistant/components/homekit/util.py @@ -35,7 +35,7 @@ from homeassistant.const import ( CONF_NAME, CONF_PORT, CONF_TYPE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import Event, HomeAssistant, State, callback, split_entity_id import homeassistant.helpers.config_validation as cv @@ -391,12 +391,20 @@ def cleanup_name_for_homekit(name: str | None) -> str: def temperature_to_homekit(temperature: float | int, unit: str) -> float: """Convert temperature to Celsius for HomeKit.""" - return round(TemperatureConverter.convert(temperature, unit, TEMP_CELSIUS), 1) + return round( + TemperatureConverter.convert(temperature, unit, UnitOfTemperature.CELSIUS), 1 + ) def temperature_to_states(temperature: float | int, unit: str) -> float: """Convert temperature back from Celsius to Home Assistant unit.""" - return round(TemperatureConverter.convert(temperature, TEMP_CELSIUS, unit) * 2) / 2 + return ( + round( + TemperatureConverter.convert(temperature, UnitOfTemperature.CELSIUS, unit) + * 2 + ) + / 2 + ) def density_to_air_quality(density: float) -> int: diff --git a/homeassistant/components/homekit_controller/sensor.py b/homeassistant/components/homekit_controller/sensor.py index d7b92f4a44d..5d3e9669705 100644 --- a/homeassistant/components/homekit_controller/sensor.py +++ b/homeassistant/components/homekit_controller/sensor.py @@ -26,7 +26,6 @@ from homeassistant.const import ( LIGHT_LUX, PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - TEMP_CELSIUS, Platform, UnitOfElectricCurrent, UnitOfElectricPotential, @@ -34,6 +33,7 @@ from homeassistant.const import ( UnitOfPower, UnitOfPressure, UnitOfSoundPressure, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import EntityCategory @@ -230,7 +230,7 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = { name="Current Temperature", device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, # This sensor is only for temperature characteristics that are not part # of a temperature sensor service. probe=(lambda char: char.service.type != ServicesTypes.TEMPERATURE_SENSOR), @@ -380,7 +380,7 @@ class HomeKitTemperatureSensor(HomeKitSensor): """Representation of a Homekit temperature sensor.""" _attr_device_class = SensorDeviceClass.TEMPERATURE - _attr_native_unit_of_measurement = TEMP_CELSIUS + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS def get_characteristic_types(self) -> list[str]: """Define the homekit characteristics the entity is tracking.""" diff --git a/homeassistant/components/homematic/sensor.py b/homeassistant/components/homematic/sensor.py index ecf3ad2c54e..927532b0d02 100644 --- a/homeassistant/components/homematic/sensor.py +++ b/homeassistant/components/homematic/sensor.py @@ -17,7 +17,6 @@ from homeassistant.const import ( DEGREE, LIGHT_LUX, PERCENTAGE, - TEMP_CELSIUS, UnitOfElectricCurrent, UnitOfElectricPotential, UnitOfEnergy, @@ -26,6 +25,7 @@ from homeassistant.const import ( UnitOfPrecipitationDepth, UnitOfPressure, UnitOfSpeed, + UnitOfTemperature, UnitOfVolume, ) from homeassistant.core import HomeAssistant @@ -63,13 +63,13 @@ SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = { ), "ACTUAL_TEMPERATURE": SensorEntityDescription( key="ACTUAL_TEMPERATURE", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, ), "TEMPERATURE": SensorEntityDescription( key="TEMPERATURE", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, ), diff --git a/homeassistant/components/hue/v1/sensor.py b/homeassistant/components/hue/v1/sensor.py index 3a79f5f37f1..5adca4ef8d7 100644 --- a/homeassistant/components/hue/v1/sensor.py +++ b/homeassistant/components/hue/v1/sensor.py @@ -11,7 +11,7 @@ from homeassistant.components.sensor import ( SensorEntity, SensorStateClass, ) -from homeassistant.const import LIGHT_LUX, PERCENTAGE, TEMP_CELSIUS +from homeassistant.const import LIGHT_LUX, PERCENTAGE, UnitOfTemperature from homeassistant.helpers.entity import EntityCategory from ..const import DOMAIN as HUE_DOMAIN @@ -76,7 +76,7 @@ class HueTemperature(GenericHueGaugeSensorEntity): _attr_device_class = SensorDeviceClass.TEMPERATURE _attr_state_class = SensorStateClass.MEASUREMENT - _attr_native_unit_of_measurement = TEMP_CELSIUS + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS @property def native_value(self): diff --git a/homeassistant/components/hue/v2/sensor.py b/homeassistant/components/hue/v2/sensor.py index e4b07d899e2..7fa34c59869 100644 --- a/homeassistant/components/hue/v2/sensor.py +++ b/homeassistant/components/hue/v2/sensor.py @@ -23,7 +23,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import LIGHT_LUX, PERCENTAGE, TEMP_CELSIUS +from homeassistant.const import LIGHT_LUX, PERCENTAGE, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -96,7 +96,7 @@ class HueSensorBase(HueBaseEntity, SensorEntity): class HueTemperatureSensor(HueSensorBase): """Representation of a Hue Temperature sensor.""" - _attr_native_unit_of_measurement = TEMP_CELSIUS + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS _attr_device_class = SensorDeviceClass.TEMPERATURE @property