From a6ddac9004b7f73633f2019f3b5267e1486756c1 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 20 Dec 2022 18:30:46 +0100 Subject: [PATCH] Use UnitOfTemperature in integrations (i-m) (#84307) --- homeassistant/components/iaqualink/sensor.py | 6 +++--- homeassistant/components/ihc/auto_setup.py | 4 ++-- homeassistant/components/ihc/manual_setup.py | 8 ++++++-- homeassistant/components/incomfort/sensor.py | 6 +++--- homeassistant/components/inkbird/sensor.py | 4 ++-- homeassistant/components/intellifire/sensor.py | 6 +++--- homeassistant/components/isy994/sensor.py | 10 +++++++--- homeassistant/components/juicenet/sensor.py | 4 ++-- homeassistant/components/justnimbus/sensor.py | 4 ++-- homeassistant/components/kaiterra/sensor.py | 6 +++--- homeassistant/components/konnected/sensor.py | 4 ++-- homeassistant/components/lacrosse/sensor.py | 4 ++-- homeassistant/components/lcn/schemas.py | 7 +++---- homeassistant/components/lookin/sensor.py | 4 ++-- homeassistant/components/luftdaten/sensor.py | 4 ++-- homeassistant/components/meater/sensor.py | 10 +++++----- homeassistant/components/mfi/sensor.py | 4 ++-- homeassistant/components/mill/sensor.py | 6 +++--- homeassistant/components/moat/sensor.py | 4 ++-- homeassistant/components/mobile_app/sensor.py | 4 ++-- 20 files changed, 58 insertions(+), 51 deletions(-) diff --git a/homeassistant/components/iaqualink/sensor.py b/homeassistant/components/iaqualink/sensor.py index f1636a09c90..8086aa29ee0 100644 --- a/homeassistant/components/iaqualink/sensor.py +++ b/homeassistant/components/iaqualink/sensor.py @@ -3,7 +3,7 @@ from __future__ import annotations from homeassistant.components.sensor import DOMAIN, SensorDeviceClass, SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -38,8 +38,8 @@ class HassAqualinkSensor(AqualinkEntity, SensorEntity): """Return the measurement unit for the sensor.""" if self.dev.name.endswith("_temp"): if self.dev.system.temp_unit == "F": - return TEMP_FAHRENHEIT - return TEMP_CELSIUS + return UnitOfTemperature.FAHRENHEIT + return UnitOfTemperature.CELSIUS return None @property diff --git a/homeassistant/components/ihc/auto_setup.py b/homeassistant/components/ihc/auto_setup.py index ae271108848..d23c3e65a41 100644 --- a/homeassistant/components/ihc/auto_setup.py +++ b/homeassistant/components/ihc/auto_setup.py @@ -6,7 +6,7 @@ from defusedxml import ElementTree import voluptuous as vol from homeassistant.config import load_yaml_config_file -from homeassistant.const import CONF_TYPE, CONF_UNIT_OF_MEASUREMENT, TEMP_CELSIUS +from homeassistant.const import CONF_TYPE, CONF_UNIT_OF_MEASUREMENT, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers import discovery import homeassistant.helpers.config_validation as cv @@ -63,7 +63,7 @@ AUTO_SETUP_SCHEMA = vol.Schema( vol.Required(CONF_NODE): cv.string, vol.Required(CONF_XPATH): cv.string, vol.Optional( - CONF_UNIT_OF_MEASUREMENT, default=TEMP_CELSIUS + CONF_UNIT_OF_MEASUREMENT, default=UnitOfTemperature.CELSIUS ): cv.string, } ) diff --git a/homeassistant/components/ihc/manual_setup.py b/homeassistant/components/ihc/manual_setup.py index 297997281c6..c14d387ba61 100644 --- a/homeassistant/components/ihc/manual_setup.py +++ b/homeassistant/components/ihc/manual_setup.py @@ -12,7 +12,7 @@ from homeassistant.const import ( CONF_UNIT_OF_MEASUREMENT, CONF_URL, CONF_USERNAME, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers import discovery @@ -81,7 +81,11 @@ LIGHT_SCHEMA = DEVICE_SCHEMA.extend( ) SENSOR_SCHEMA = DEVICE_SCHEMA.extend( - {vol.Optional(CONF_UNIT_OF_MEASUREMENT, default=TEMP_CELSIUS): cv.string} + { + vol.Optional( + CONF_UNIT_OF_MEASUREMENT, default=UnitOfTemperature.CELSIUS + ): cv.string + } ) IHC_SCHEMA = vol.Schema( diff --git a/homeassistant/components/incomfort/sensor.py b/homeassistant/components/incomfort/sensor.py index 3db3eab49e4..b1b391aaaab 100644 --- a/homeassistant/components/incomfort/sensor.py +++ b/homeassistant/components/incomfort/sensor.py @@ -10,7 +10,7 @@ from homeassistant.components.sensor import ( SensorEntity, SensorEntityDescription, ) -from homeassistant.const import TEMP_CELSIUS, UnitOfPressure +from homeassistant.const import UnitOfPressure, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -41,14 +41,14 @@ SENSOR_TYPES: tuple[IncomfortSensorEntityDescription, ...] = ( key="heater_temp", name=INCOMFORT_HEATER_TEMP, device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, extra_key="is_pumping", ), IncomfortSensorEntityDescription( key="tap_temp", name=INCOMFORT_TAP_TEMP, device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, extra_key="is_tapping", ), ) diff --git a/homeassistant/components/inkbird/sensor.py b/homeassistant/components/inkbird/sensor.py index d0e06e81647..74716d465a8 100644 --- a/homeassistant/components/inkbird/sensor.py +++ b/homeassistant/components/inkbird/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/intellifire/sensor.py b/homeassistant/components/intellifire/sensor.py index cbd31249133..0bb398ea70f 100644 --- a/homeassistant/components/intellifire/sensor.py +++ b/homeassistant/components/intellifire/sensor.py @@ -14,7 +14,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) 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 @@ -68,7 +68,7 @@ INTELLIFIRE_SENSORS: tuple[IntellifireSensorEntityDescription, ...] = ( name="Temperature", state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value_fn=lambda data: data.temperature_c, ), IntellifireSensorEntityDescription( @@ -76,7 +76,7 @@ INTELLIFIRE_SENSORS: tuple[IntellifireSensorEntityDescription, ...] = ( name="Target Temperature", state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value_fn=lambda data: data.thermostat_setpoint_c, ), IntellifireSensorEntityDescription( diff --git a/homeassistant/components/isy994/sensor.py b/homeassistant/components/isy994/sensor.py index b02050f6f7b..3931c9d4cf9 100644 --- a/homeassistant/components/isy994/sensor.py +++ b/homeassistant/components/isy994/sensor.py @@ -27,7 +27,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -173,7 +173,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity): value = convert_isy_value_to_hass(value, uom, self.target.prec) # Convert temperatures to Home Assistant's unit - if uom in (TEMP_CELSIUS, TEMP_FAHRENHEIT): + if uom in (UnitOfTemperature.CELSIUS, UnitOfTemperature.FAHRENHEIT): value = self.hass.config.units.temperature(value, uom) if value is None: @@ -189,7 +189,11 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity): # Check if this is a known index pair UOM if isinstance(raw_units, dict) or raw_units in (UOM_ON_OFF, UOM_INDEX): return None - if raw_units in (TEMP_FAHRENHEIT, TEMP_CELSIUS, UOM_DOUBLE_TEMP): + if raw_units in ( + UnitOfTemperature.FAHRENHEIT, + UnitOfTemperature.CELSIUS, + UOM_DOUBLE_TEMP, + ): return self.hass.config.units.temperature_unit return raw_units diff --git a/homeassistant/components/juicenet/sensor.py b/homeassistant/components/juicenet/sensor.py index 415f5de0720..e87c752962b 100644 --- a/homeassistant/components/juicenet/sensor.py +++ b/homeassistant/components/juicenet/sensor.py @@ -9,11 +9,11 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - TEMP_CELSIUS, UnitOfElectricCurrent, UnitOfElectricPotential, UnitOfEnergy, UnitOfPower, + UnitOfTemperature, UnitOfTime, ) from homeassistant.core import HomeAssistant @@ -30,7 +30,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="temperature", name="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/justnimbus/sensor.py b/homeassistant/components/justnimbus/sensor.py index 754fa66ae51..310a9a939c0 100644 --- a/homeassistant/components/justnimbus/sensor.py +++ b/homeassistant/components/justnimbus/sensor.py @@ -14,8 +14,8 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_CLIENT_ID, - TEMP_CELSIUS, UnitOfPressure, + UnitOfTemperature, UnitOfTime, UnitOfVolume, ) @@ -92,7 +92,7 @@ SENSOR_TYPES = ( JustNimbusEntityDescription( key="reservoir_temp", name="Reservoir 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/kaiterra/sensor.py b/homeassistant/components/kaiterra/sensor.py index 29013052c1c..63a73a1157a 100644 --- a/homeassistant/components/kaiterra/sensor.py +++ b/homeassistant/components/kaiterra/sensor.py @@ -8,7 +8,7 @@ from homeassistant.components.sensor import ( SensorEntity, SensorEntityDescription, ) -from homeassistant.const import CONF_DEVICE_ID, CONF_NAME, TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import CONF_DEVICE_ID, CONF_NAME, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -105,9 +105,9 @@ class KaiterraSensor(SensorEntity): value = self._sensor["units"].value if value == "F": - return TEMP_FAHRENHEIT + return UnitOfTemperature.FAHRENHEIT if value == "C": - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS return value async def async_added_to_hass(self) -> None: diff --git a/homeassistant/components/konnected/sensor.py b/homeassistant/components/konnected/sensor.py index 7bfa1fad446..89436913606 100644 --- a/homeassistant/components/konnected/sensor.py +++ b/homeassistant/components/konnected/sensor.py @@ -14,7 +14,7 @@ from homeassistant.const import ( CONF_TYPE, CONF_ZONE, PERCENTAGE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -27,7 +27,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = { "temperature": SensorEntityDescription( key="temperature", name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, ), "humidity": SensorEntityDescription( diff --git a/homeassistant/components/lacrosse/sensor.py b/homeassistant/components/lacrosse/sensor.py index e2f028907d9..a9edea22b0d 100644 --- a/homeassistant/components/lacrosse/sensor.py +++ b/homeassistant/components/lacrosse/sensor.py @@ -23,7 +23,7 @@ from homeassistant.const import ( CONF_TYPE, EVENT_HOMEASSISTANT_STOP, PERCENTAGE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv @@ -187,7 +187,7 @@ class LaCrosseTemperature(LaCrosseSensor): _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/lcn/schemas.py b/homeassistant/components/lcn/schemas.py index 290f7dd55f4..bd02c80da66 100644 --- a/homeassistant/components/lcn/schemas.py +++ b/homeassistant/components/lcn/schemas.py @@ -17,8 +17,7 @@ from homeassistant.const import ( CONF_SWITCHES, CONF_UNIT_OF_MEASUREMENT, CONF_USERNAME, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) import homeassistant.helpers.config_validation as cv @@ -74,8 +73,8 @@ DOMAIN_DATA_CLIMATE = { vol.Optional(CONF_MAX_TEMP, default=DEFAULT_MAX_TEMP): vol.Coerce(float), vol.Optional(CONF_MIN_TEMP, default=DEFAULT_MIN_TEMP): vol.Coerce(float), vol.Optional(CONF_LOCKABLE, default=False): vol.Coerce(bool), - vol.Optional(CONF_UNIT_OF_MEASUREMENT, default=TEMP_CELSIUS): vol.In( - TEMP_CELSIUS, TEMP_FAHRENHEIT + vol.Optional(CONF_UNIT_OF_MEASUREMENT, default=UnitOfTemperature.CELSIUS): vol.In( + UnitOfTemperature.CELSIUS, UnitOfTemperature.FAHRENHEIT ), } diff --git a/homeassistant/components/lookin/sensor.py b/homeassistant/components/lookin/sensor.py index 6dee2f2c0ac..822c28fda30 100644 --- a/homeassistant/components/lookin/sensor.py +++ b/homeassistant/components/lookin/sensor.py @@ -10,7 +10,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 @@ -25,7 +25,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="temperature", name="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/luftdaten/sensor.py b/homeassistant/components/luftdaten/sensor.py index fd2fa5b6c2c..0bd595493db 100644 --- a/homeassistant/components/luftdaten/sensor.py +++ b/homeassistant/components/luftdaten/sensor.py @@ -16,8 +16,8 @@ from homeassistant.const import ( CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONF_SHOW_ON_MAP, PERCENTAGE, - TEMP_CELSIUS, UnitOfPressure, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo @@ -33,7 +33,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, state_class=SensorStateClass.MEASUREMENT, ), diff --git a/homeassistant/components/meater/sensor.py b/homeassistant/components/meater/sensor.py index 8322b9a0202..0a1240c7471 100644 --- a/homeassistant/components/meater/sensor.py +++ b/homeassistant/components/meater/sensor.py @@ -14,7 +14,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import ( @@ -65,7 +65,7 @@ SENSOR_TYPES = ( key="ambient", device_class=SensorDeviceClass.TEMPERATURE, name="Ambient", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, available=lambda probe: probe is not None, value=lambda probe: probe.ambient_temperature, @@ -75,7 +75,7 @@ SENSOR_TYPES = ( key="internal", device_class=SensorDeviceClass.TEMPERATURE, name="Internal", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, available=lambda probe: probe is not None, value=lambda probe: probe.internal_temperature, @@ -100,7 +100,7 @@ SENSOR_TYPES = ( key="cook_target_temp", device_class=SensorDeviceClass.TEMPERATURE, name="Target", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, available=lambda probe: probe is not None and probe.cook is not None, value=lambda probe: probe.cook.target_temperature @@ -112,7 +112,7 @@ SENSOR_TYPES = ( key="cook_peak_temp", device_class=SensorDeviceClass.TEMPERATURE, name="Peak", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, available=lambda probe: probe is not None and probe.cook is not None, value=lambda probe: probe.cook.peak_temperature diff --git a/homeassistant/components/mfi/sensor.py b/homeassistant/components/mfi/sensor.py index de7e661d9d2..38f6d973b9d 100644 --- a/homeassistant/components/mfi/sensor.py +++ b/homeassistant/components/mfi/sensor.py @@ -21,7 +21,7 @@ from homeassistant.const import ( CONF_VERIFY_SSL, STATE_OFF, STATE_ON, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -136,7 +136,7 @@ class MfiSensor(SensorEntity): return "State" if tag == "temperature": - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS if tag == "active_pwr": return "Watts" if self._port.model == "Input Digital": diff --git a/homeassistant/components/mill/sensor.py b/homeassistant/components/mill/sensor.py index 2c8711b90e8..776ba1dc632 100644 --- a/homeassistant/components/mill/sensor.py +++ b/homeassistant/components/mill/sensor.py @@ -16,9 +16,9 @@ from homeassistant.const import ( CONF_IP_ADDRESS, CONF_USERNAME, PERCENTAGE, - TEMP_CELSIUS, UnitOfEnergy, UnitOfPower, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC @@ -62,7 +62,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key=TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, name="Temperature", state_class=SensorStateClass.MEASUREMENT, ), @@ -112,7 +112,7 @@ LOCAL_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="raw_ambient_temperature", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, name="Uncalibrated temperature", state_class=SensorStateClass.MEASUREMENT, entity_registry_enabled_default=False, diff --git a/homeassistant/components/moat/sensor.py b/homeassistant/components/moat/sensor.py index f354dfd8f9b..fc83d1fe757 100644 --- a/homeassistant/components/moat/sensor.py +++ b/homeassistant/components/moat/sensor.py @@ -22,8 +22,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_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/mobile_app/sensor.py b/homeassistant/components/mobile_app/sensor.py index d802dc92b52..0d2c05df518 100644 --- a/homeassistant/components/mobile_app/sensor.py +++ b/homeassistant/components/mobile_app/sensor.py @@ -5,7 +5,7 @@ from typing import Any from homeassistant.components.sensor import RestoreSensor, SensorDeviceClass from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_WEBHOOK_ID, STATE_UNKNOWN, TEMP_CELSIUS +from homeassistant.const import CONF_WEBHOOK_ID, STATE_UNKNOWN, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_registry as er from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -92,7 +92,7 @@ class MobileAppSensor(MobileAppEntity, RestoreSensor): self.device_class == SensorDeviceClass.TEMPERATURE and sensor_unique_id == "battery_temperature" ): - self._config[ATTR_SENSOR_UOM] = TEMP_CELSIUS + self._config[ATTR_SENSOR_UOM] = UnitOfTemperature.CELSIUS return self._config[ATTR_SENSOR_STATE] = last_sensor_data.native_value