diff --git a/homeassistant/components/plant/__init__.py b/homeassistant/components/plant/__init__.py index 69f440b6859..35273e6fce0 100644 --- a/homeassistant/components/plant/__init__.py +++ b/homeassistant/components/plant/__init__.py @@ -18,7 +18,7 @@ from homeassistant.const import ( STATE_PROBLEM, STATE_UNAVAILABLE, STATE_UNKNOWN, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError @@ -138,7 +138,7 @@ class Plant(Entity): "min": CONF_MIN_BATTERY_LEVEL, }, READING_TEMPERATURE: { - ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, "min": CONF_MIN_TEMPERATURE, "max": CONF_MAX_TEMPERATURE, }, diff --git a/homeassistant/components/plugwise/number.py b/homeassistant/components/plugwise/number.py index 0b8c7f820b4..836af62a388 100644 --- a/homeassistant/components/plugwise/number.py +++ b/homeassistant/components/plugwise/number.py @@ -13,7 +13,7 @@ from homeassistant.components.number import ( NumberMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -51,7 +51,7 @@ NUMBER_TYPES = ( native_max_value_key="upper_bound", native_min_value_key="lower_bound", native_step_key="resolution", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, native_value_key="setpoint", ), ) diff --git a/homeassistant/components/plugwise/sensor.py b/homeassistant/components/plugwise/sensor.py index e024123b067..d727d611d61 100644 --- a/homeassistant/components/plugwise/sensor.py +++ b/homeassistant/components/plugwise/sensor.py @@ -10,10 +10,10 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, - TEMP_CELSIUS, UnitOfEnergy, UnitOfPower, UnitOfPressure, + UnitOfTemperature, UnitOfVolume, ) from homeassistant.core import HomeAssistant @@ -28,7 +28,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="setpoint", name="Setpoint", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, entity_category=EntityCategory.DIAGNOSTIC, @@ -36,7 +36,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="setpoint_high", name="Cooling setpoint", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, entity_category=EntityCategory.DIAGNOSTIC, @@ -44,7 +44,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="setpoint_low", name="Heating setpoint", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, entity_category=EntityCategory.DIAGNOSTIC, @@ -52,7 +52,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="temperature", name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -60,7 +60,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="intended_boiler_temperature", name="Intended boiler temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -68,7 +68,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="temperature_difference", name="Temperature difference", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -76,14 +76,14 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="outdoor_temperature", name="Outdoor temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="outdoor_air_temperature", name="Outdoor air temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -91,7 +91,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="water_temperature", name="Water temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -99,7 +99,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="return_temperature", name="Return temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -295,7 +295,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="dhw_temperature", name="DHW temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -303,7 +303,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="domestic_hot_water_setpoint", name="DHW setpoint", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -311,7 +311,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="maximum_boiler_temperature", name="Maximum boiler temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, diff --git a/homeassistant/components/prometheus/__init__.py b/homeassistant/components/prometheus/__init__.py index c1573755e11..1d5e45c414e 100644 --- a/homeassistant/components/prometheus/__init__.py +++ b/homeassistant/components/prometheus/__init__.py @@ -31,8 +31,7 @@ from homeassistant.const import ( STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers import entityfilter, state as state_helper @@ -347,9 +346,12 @@ class PrometheusMetrics: with suppress(ValueError): value = self.state_as_number(state) - if state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_FAHRENHEIT: + if ( + state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) + == UnitOfTemperature.FAHRENHEIT + ): value = TemperatureConverter.convert( - value, TEMP_FAHRENHEIT, TEMP_CELSIUS + value, UnitOfTemperature.FAHRENHEIT, UnitOfTemperature.CELSIUS ) metric.labels(**self._labels(state)).set(value) @@ -395,8 +397,10 @@ class PrometheusMetrics: def _handle_climate_temp(self, state, attr, metric_name, metric_description): if temp := state.attributes.get(attr): - if self._climate_units == TEMP_FAHRENHEIT: - temp = TemperatureConverter.convert(temp, TEMP_FAHRENHEIT, TEMP_CELSIUS) + if self._climate_units == UnitOfTemperature.FAHRENHEIT: + temp = TemperatureConverter.convert( + temp, UnitOfTemperature.FAHRENHEIT, UnitOfTemperature.CELSIUS + ) metric = self._metric( metric_name, self.prometheus_cli.Gauge, @@ -508,9 +512,12 @@ class PrometheusMetrics: try: value = self.state_as_number(state) - if state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_FAHRENHEIT: + if ( + state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) + == UnitOfTemperature.FAHRENHEIT + ): value = TemperatureConverter.convert( - value, TEMP_FAHRENHEIT, TEMP_CELSIUS + value, UnitOfTemperature.FAHRENHEIT, UnitOfTemperature.CELSIUS ) _metric.labels(**self._labels(state)).set(value) except ValueError: @@ -559,8 +566,8 @@ class PrometheusMetrics: return units = { - TEMP_CELSIUS: "celsius", - TEMP_FAHRENHEIT: "celsius", # F should go into C metric + UnitOfTemperature.CELSIUS: "celsius", + UnitOfTemperature.FAHRENHEIT: "celsius", # F should go into C metric PERCENTAGE: "percent", } default = unit.replace("/", "_per_") diff --git a/homeassistant/components/prusalink/sensor.py b/homeassistant/components/prusalink/sensor.py index 366d9dd9883..a8cdf0625c9 100644 --- a/homeassistant/components/prusalink/sensor.py +++ b/homeassistant/components/prusalink/sensor.py @@ -15,7 +15,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_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -66,7 +66,7 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = { PrusaLinkSensorEntityDescription[PrinterInfo]( key="printer.telemetry.temp-bed", name="Heatbed", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: cast(float, data["telemetry"]["temp-bed"]), @@ -75,7 +75,7 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = { PrusaLinkSensorEntityDescription[PrinterInfo]( key="printer.telemetry.temp-nozzle", name="Nozzle Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: cast(float, data["telemetry"]["temp-nozzle"]), diff --git a/homeassistant/components/pvoutput/sensor.py b/homeassistant/components/pvoutput/sensor.py index bf5dd76d503..6eacb1751c7 100644 --- a/homeassistant/components/pvoutput/sensor.py +++ b/homeassistant/components/pvoutput/sensor.py @@ -14,10 +14,10 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - TEMP_CELSIUS, UnitOfElectricPotential, UnitOfEnergy, UnitOfPower, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo @@ -85,7 +85,7 @@ SENSORS: tuple[PVOutputSensorEntityDescription, ...] = ( PVOutputSensorEntityDescription( key="temperature", name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda status: status.temperature, diff --git a/homeassistant/components/qingping/sensor.py b/homeassistant/components/qingping/sensor.py index 674c10fa934..84276c11292 100644 --- a/homeassistant/components/qingping/sensor.py +++ b/homeassistant/components/qingping/sensor.py @@ -28,8 +28,8 @@ from homeassistant.const import ( LIGHT_LUX, PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - TEMP_CELSIUS, UnitOfPressure, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -109,7 +109,7 @@ SENSOR_DESCRIPTIONS = { ): SensorEntityDescription( key=f"{QingpingSensorDeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, ), } diff --git a/homeassistant/components/qnap/sensor.py b/homeassistant/components/qnap/sensor.py index 18d5471e08b..96bb0d61aec 100644 --- a/homeassistant/components/qnap/sensor.py +++ b/homeassistant/components/qnap/sensor.py @@ -24,9 +24,9 @@ from homeassistant.const import ( CONF_USERNAME, CONF_VERIFY_SSL, PERCENTAGE, - TEMP_CELSIUS, UnitOfDataRate, UnitOfInformation, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady @@ -74,7 +74,7 @@ _SYSTEM_MON_COND: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="system_temp", name="System Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, ), ) @@ -82,7 +82,7 @@ _CPU_MON_COND: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="cpu_temp", name="CPU Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, ), SensorEntityDescription( @@ -144,7 +144,7 @@ _DRIVE_MON_COND: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="drive_temp", name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, ), ) diff --git a/homeassistant/components/qnap_qsw/sensor.py b/homeassistant/components/qnap_qsw/sensor.py index f86a4d3aa74..a00103a0f32 100644 --- a/homeassistant/components/qnap_qsw/sensor.py +++ b/homeassistant/components/qnap_qsw/sensor.py @@ -32,9 +32,9 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - TEMP_CELSIUS, UnitOfDataRate, UnitOfInformation, + UnitOfTemperature, UnitOfTime, ) from homeassistant.core import HomeAssistant, callback @@ -117,7 +117,7 @@ SENSOR_TYPES: Final[tuple[QswSensorEntityDescription, ...]] = ( device_class=SensorDeviceClass.TEMPERATURE, key=QSD_SYSTEM_SENSOR, name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, subkey=QSD_TEMP, ), diff --git a/homeassistant/components/renault/sensor.py b/homeassistant/components/renault/sensor.py index 257f0564ef1..679fbbd370f 100644 --- a/homeassistant/components/renault/sensor.py +++ b/homeassistant/components/renault/sensor.py @@ -24,10 +24,10 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, - TEMP_CELSIUS, UnitOfEnergy, UnitOfLength, UnitOfPower, + UnitOfTemperature, UnitOfTime, UnitOfVolume, ) @@ -266,7 +266,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = ( device_class=SensorDeviceClass.TEMPERATURE, entity_class=RenaultSensor[KamereonVehicleBatteryStatusData], name="Battery temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, ), RenaultSensorEntityDescription( @@ -324,7 +324,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = ( data_key="externalTemperature", entity_class=RenaultSensor[KamereonVehicleHvacStatusData], name="Outside temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, ), RenaultSensorEntityDescription( diff --git a/homeassistant/components/repetier/__init__.py b/homeassistant/components/repetier/__init__.py index c657d5d0502..6a0df99ce1d 100644 --- a/homeassistant/components/repetier/__init__.py +++ b/homeassistant/components/repetier/__init__.py @@ -17,7 +17,7 @@ from homeassistant.const import ( CONF_PORT, CONF_SENSORS, PERCENTAGE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -142,21 +142,21 @@ SENSOR_TYPES: dict[str, RepetierSensorEntityDescription] = { "bed_temperature": RepetierSensorEntityDescription( key="bed_temperature", type="temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, name="_bed_", device_class=SensorDeviceClass.TEMPERATURE, ), "extruder_temperature": RepetierSensorEntityDescription( key="extruder_temperature", type="temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, name="_extruder_", device_class=SensorDeviceClass.TEMPERATURE, ), "chamber_temperature": RepetierSensorEntityDescription( key="chamber_temperature", type="temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, name="_chamber_", device_class=SensorDeviceClass.TEMPERATURE, ), diff --git a/homeassistant/components/sensibo/sensor.py b/homeassistant/components/sensibo/sensor.py index bb54edbe03a..348c5986bd2 100644 --- a/homeassistant/components/sensibo/sensor.py +++ b/homeassistant/components/sensibo/sensor.py @@ -21,8 +21,8 @@ from homeassistant.const import ( CONCENTRATION_PARTS_PER_MILLION, PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - TEMP_CELSIUS, UnitOfElectricPotential, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -311,7 +311,7 @@ class SensiboMotionSensor(SensiboMotionBaseEntity, SensorEntity): def native_unit_of_measurement(self) -> str | None: """Add native unit of measurement.""" if self.entity_description.device_class == SensorDeviceClass.TEMPERATURE: - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS return self.entity_description.native_unit_of_measurement @property @@ -345,7 +345,7 @@ class SensiboDeviceSensor(SensiboDeviceBaseEntity, SensorEntity): def native_unit_of_measurement(self) -> str | None: """Add native unit of measurement.""" if self.entity_description.device_class == SensorDeviceClass.TEMPERATURE: - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS return self.entity_description.native_unit_of_measurement @property diff --git a/homeassistant/components/sensorpro/sensor.py b/homeassistant/components/sensorpro/sensor.py index ce5e5fec9f2..edfe2fb21c5 100644 --- a/homeassistant/components/sensorpro/sensor.py +++ b/homeassistant/components/sensorpro/sensor.py @@ -25,8 +25,8 @@ from homeassistant.components.sensor import ( from homeassistant.const import ( PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - TEMP_CELSIUS, UnitOfElectricPotential, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -67,7 +67,7 @@ SENSOR_DESCRIPTIONS = { ): SensorEntityDescription( key=f"{SensorProSensorDeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, ), ( diff --git a/homeassistant/components/sensorpush/sensor.py b/homeassistant/components/sensorpush/sensor.py index d5109e57173..7742642e92c 100644 --- a/homeassistant/components/sensorpush/sensor.py +++ b/homeassistant/components/sensorpush/sensor.py @@ -22,8 +22,8 @@ from homeassistant.components.sensor import ( from homeassistant.const import ( PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - TEMP_CELSIUS, UnitOfPressure, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -35,7 +35,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/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index e9feaf06933..70a29857708 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -20,11 +20,11 @@ from homeassistant.const import ( LIGHT_LUX, PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - TEMP_CELSIUS, UnitOfElectricCurrent, UnitOfElectricPotential, UnitOfEnergy, UnitOfPower, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -79,7 +79,7 @@ SENSORS: Final = { ("device", "deviceTemp"): BlockSensorDescription( key="device|deviceTemp", name="Device Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value=lambda value: round(value, 1), device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, @@ -221,7 +221,7 @@ SENSORS: Final = { ("sensor", "temp"): BlockSensorDescription( key="sensor|temp", name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value=lambda value: round(value, 1), device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, @@ -230,7 +230,7 @@ SENSORS: Final = { ("sensor", "extTemp"): BlockSensorDescription( key="sensor|extTemp", name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value=lambda value: round(value, 1), device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, @@ -345,7 +345,7 @@ RPC_SENSORS: Final = { key="switch", sub_key="temperature", name="Device Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value=lambda status, _: round(status["tC"], 1), device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, @@ -357,7 +357,7 @@ RPC_SENSORS: Final = { key="temperature", sub_key="tC", name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value=lambda status, _: round(status, 1), device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, diff --git a/homeassistant/components/simplisafe/sensor.py b/homeassistant/components/simplisafe/sensor.py index 39566434f27..949d8890398 100644 --- a/homeassistant/components/simplisafe/sensor.py +++ b/homeassistant/components/simplisafe/sensor.py @@ -11,7 +11,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_FAHRENHEIT +from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -42,7 +42,7 @@ class SimplisafeFreezeSensor(SimpliSafeEntity, SensorEntity): """Define a SimpliSafe freeze sensor entity.""" _attr_device_class = SensorDeviceClass.TEMPERATURE - _attr_native_unit_of_measurement = TEMP_FAHRENHEIT + _attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT _attr_state_class = SensorStateClass.MEASUREMENT def __init__( diff --git a/homeassistant/components/skybeacon/sensor.py b/homeassistant/components/skybeacon/sensor.py index 367c5b87a10..0ff6ebd41cd 100644 --- a/homeassistant/components/skybeacon/sensor.py +++ b/homeassistant/components/skybeacon/sensor.py @@ -21,7 +21,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_STOP, PERCENTAGE, STATE_UNKNOWN, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -105,7 +105,7 @@ class SkybeaconTemp(SensorEntity): """Representation of a Skybeacon temperature sensor.""" _attr_device_class = SensorDeviceClass.TEMPERATURE - _attr_native_unit_of_measurement = TEMP_CELSIUS + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS def __init__(self, name, mon): """Initialize a sensor.""" diff --git a/homeassistant/components/smarty/sensor.py b/homeassistant/components/smarty/sensor.py index 1c76fe3bfb9..57d681594cf 100644 --- a/homeassistant/components/smarty/sensor.py +++ b/homeassistant/components/smarty/sensor.py @@ -7,7 +7,7 @@ import logging from pysmarty import Smarty from homeassistant.components.sensor import SensorDeviceClass, SensorEntity -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -78,7 +78,7 @@ class SupplyAirTemperatureSensor(SmartySensor): super().__init__( name=f"{name} Supply Air Temperature", device_class=SensorDeviceClass.TEMPERATURE, - unit_of_measurement=TEMP_CELSIUS, + unit_of_measurement=UnitOfTemperature.CELSIUS, smarty=smarty, ) @@ -96,7 +96,7 @@ class ExtractAirTemperatureSensor(SmartySensor): super().__init__( name=f"{name} Extract Air Temperature", device_class=SensorDeviceClass.TEMPERATURE, - unit_of_measurement=TEMP_CELSIUS, + unit_of_measurement=UnitOfTemperature.CELSIUS, smarty=smarty, ) @@ -114,7 +114,7 @@ class OutdoorAirTemperatureSensor(SmartySensor): super().__init__( name=f"{name} Outdoor Air Temperature", device_class=SensorDeviceClass.TEMPERATURE, - unit_of_measurement=TEMP_CELSIUS, + unit_of_measurement=UnitOfTemperature.CELSIUS, smarty=smarty, ) diff --git a/homeassistant/components/solax/sensor.py b/homeassistant/components/solax/sensor.py index d588f4811bb..2a923c3b725 100644 --- a/homeassistant/components/solax/sensor.py +++ b/homeassistant/components/solax/sensor.py @@ -17,12 +17,12 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, - TEMP_CELSIUS, UnitOfElectricCurrent, UnitOfElectricPotential, UnitOfEnergy, UnitOfFrequency, UnitOfPower, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady @@ -40,7 +40,7 @@ SENSOR_DESCRIPTIONS: dict[tuple[Units, bool], SensorEntityDescription] = { (Units.C, False): SensorEntityDescription( key=f"{Units.C}_{False}", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, ), (Units.KWH, False): SensorEntityDescription( diff --git a/homeassistant/components/steamist/sensor.py b/homeassistant/components/steamist/sensor.py index 702feda580f..17cc0e8c272 100644 --- a/homeassistant/components/steamist/sensor.py +++ b/homeassistant/components/steamist/sensor.py @@ -13,7 +13,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, UnitOfTime +from homeassistant.const import UnitOfTemperature, UnitOfTime from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -25,8 +25,8 @@ _KEY_MINUTES_REMAIN = "minutes_remain" _KEY_TEMP = "temp" UNIT_MAPPINGS = { - "C": TEMP_CELSIUS, - "F": TEMP_FAHRENHEIT, + "C": UnitOfTemperature.CELSIUS, + "F": UnitOfTemperature.FAHRENHEIT, } diff --git a/homeassistant/components/switchbot/sensor.py b/homeassistant/components/switchbot/sensor.py index bafb08cc908..342328d470e 100644 --- a/homeassistant/components/switchbot/sensor.py +++ b/homeassistant/components/switchbot/sensor.py @@ -12,8 +12,8 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - TEMP_CELSIUS, UnitOfPower, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -69,7 +69,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = { "temperature": SensorEntityDescription( key="temperature", name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.TEMPERATURE, ), diff --git a/homeassistant/components/synology_dsm/sensor.py b/homeassistant/components/synology_dsm/sensor.py index 7741ec6a669..156dbe3e79c 100644 --- a/homeassistant/components/synology_dsm/sensor.py +++ b/homeassistant/components/synology_dsm/sensor.py @@ -19,9 +19,9 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_DISKS, PERCENTAGE, - TEMP_CELSIUS, UnitOfDataRate, UnitOfInformation, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -223,7 +223,7 @@ STORAGE_VOL_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = ( api_key=SynoStorage.API_KEY, key="volume_disk_temp_avg", name="Average Disk Temp", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, ), @@ -231,7 +231,7 @@ STORAGE_VOL_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = ( api_key=SynoStorage.API_KEY, key="volume_disk_temp_max", name="Maximum Disk Temp", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, entity_registry_enabled_default=False, entity_category=EntityCategory.DIAGNOSTIC, @@ -257,7 +257,7 @@ STORAGE_DISK_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = ( api_key=SynoStorage.API_KEY, key="disk_temp", 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, @@ -269,7 +269,7 @@ INFORMATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = ( api_key=SynoDSMInformation.API_KEY, 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, diff --git a/homeassistant/components/system_bridge/sensor.py b/homeassistant/components/system_bridge/sensor.py index aaa8becfe2f..bc02c9f1cda 100644 --- a/homeassistant/components/system_bridge/sensor.py +++ b/homeassistant/components/system_bridge/sensor.py @@ -17,11 +17,11 @@ from homeassistant.const import ( CONF_PORT, PERCENTAGE, REVOLUTIONS_PER_MINUTE, - TEMP_CELSIUS, UnitOfElectricPotential, UnitOfFrequency, UnitOfInformation, UnitOfPower, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -147,7 +147,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = ( entity_registry_enabled_default=False, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value=lambda data: data.cpu.temperature, ), SystemBridgeSensorEntityDescription( @@ -474,7 +474,7 @@ async def async_setup_entry( entity_registry_enabled_default=False, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value=lambda data, k=gpu["key"]: getattr( data.gpu, f"{k}_temperature" ), diff --git a/homeassistant/components/systemmonitor/sensor.py b/homeassistant/components/systemmonitor/sensor.py index d706af879db..fca06e37caa 100644 --- a/homeassistant/components/systemmonitor/sensor.py +++ b/homeassistant/components/systemmonitor/sensor.py @@ -29,9 +29,9 @@ from homeassistant.const import ( PERCENTAGE, STATE_OFF, STATE_ON, - TEMP_CELSIUS, UnitOfDataRate, UnitOfInformation, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv @@ -218,7 +218,7 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = { "processor_temperature": SysMonitorSensorEntityDescription( key="processor_temperature", name="Processor temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, ),