diff --git a/custom_components/yandex_weather/sensor.py b/custom_components/yandex_weather/sensor.py index 94c1e28..412a018 100644 --- a/custom_components/yandex_weather/sensor.py +++ b/custom_components/yandex_weather/sensor.py @@ -14,12 +14,11 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, - PRESSURE_HPA, - PRESSURE_MMHG, - SPEED_METERS_PER_SECOND, STATE_UNAVAILABLE, STATE_UNKNOWN, - TEMP_CELSIUS, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -50,7 +49,7 @@ SensorEntityDescription( key=ATTR_API_TEMPERATURE, name="Temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, entity_registry_enabled_default=False, @@ -58,7 +57,7 @@ SensorEntityDescription( key=ATTR_API_FEELS_LIKE_TEMPERATURE, name="Feels like temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, entity_registry_enabled_default=False, @@ -66,7 +65,7 @@ SensorEntityDescription( key=ATTR_API_WIND_SPEED, name="Wind speed", - native_unit_of_measurement=SPEED_METERS_PER_SECOND, + native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND, state_class=SensorStateClass.MEASUREMENT, entity_registry_enabled_default=False, icon="mdi:weather-windy", @@ -89,7 +88,7 @@ SensorEntityDescription( key=ATTR_API_PRESSURE, name="Pressure", - native_unit_of_measurement=PRESSURE_HPA, + native_unit_of_measurement=UnitOfPressure.HPA, device_class=SensorDeviceClass.PRESSURE, state_class=SensorStateClass.MEASUREMENT, entity_registry_enabled_default=False, @@ -117,7 +116,7 @@ SensorEntityDescription( key=ATTR_API_PRESSURE_MMHG, name="Pressure mmHg", - native_unit_of_measurement=PRESSURE_MMHG, + native_unit_of_measurement=UnitOfPressure.MMHG, icon="mdi:gauge", # should not define device_class, because HA will try to convert pressure to system units. state_class=SensorStateClass.MEASUREMENT, @@ -126,7 +125,7 @@ SensorEntityDescription( key=ATTR_MIN_FORECAST_TEMPERATURE, name="Minimal forecast temperature", - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, entity_registry_enabled_default=False, diff --git a/custom_components/yandex_weather/weather.py b/custom_components/yandex_weather/weather.py index 47a6cad..4401b4d 100644 --- a/custom_components/yandex_weather/weather.py +++ b/custom_components/yandex_weather/weather.py @@ -19,11 +19,11 @@ ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - LENGTH_MILLIMETERS, - PRESSURE_HPA, - SPEED_METERS_PER_SECOND, STATE_UNAVAILABLE, - TEMP_CELSIUS, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -75,10 +75,10 @@ class YandexWeather(WeatherEntity, CoordinatorEntity, RestoreEntity): """Yandex.Weather entry.""" _attr_attribution = ATTRIBUTION - _attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_precipitation_unit = LENGTH_MILLIMETERS + _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS _twice_daily_forecast: list[Forecast] | None coordinator: WeatherUpdater