Skip to content

Commit

Permalink
For compatibility of HA core 2024.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunglung committed Jan 13, 2024
1 parent d799959 commit 8bdbdc8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
49 changes: 23 additions & 26 deletions custom_components/opencwb/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
ATTR_FORECAST_WIND_BEARING,
ATTR_FORECAST_WIND_SPEED,
)
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import (
DEGREE,
DEVICE_CLASS_HUMIDITY,
# DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TIMESTAMP,
LENGTH_MILLIMETERS,
UnitOfLength,
PERCENTAGE,
# PRESSURE_HPA,
SPEED_METERS_PER_SECOND,
TEMP_CELSIUS,
UnitOfSpeed,
UnitOfTemperature,
UV_INDEX,
)

Expand Down Expand Up @@ -143,37 +140,37 @@
ATTR_API_WEATHER: {SENSOR_NAME: "Weather"},
ATTR_API_DEW_POINT: {
SENSOR_NAME: "Dew Point",
SENSOR_UNIT: TEMP_CELSIUS,
SENSOR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
SENSOR_UNIT: UnitOfTemperature.CELSIUS,
SENSOR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
},
ATTR_API_TEMPERATURE: {
SENSOR_NAME: "Temperature",
SENSOR_UNIT: TEMP_CELSIUS,
SENSOR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
SENSOR_UNIT: UnitOfTemperature.CELSIUS,
SENSOR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
},
ATTR_API_FEELS_LIKE_TEMPERATURE: {
SENSOR_NAME: "Feels like temperature",
SENSOR_UNIT: TEMP_CELSIUS,
SENSOR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
SENSOR_UNIT: UnitOfTemperature.CELSIUS,
SENSOR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
},
ATTR_API_WIND_SPEED: {
SENSOR_NAME: "Wind speed",
SENSOR_UNIT: SPEED_METERS_PER_SECOND,
SENSOR_UNIT: UnitOfSpeed.METERS_PER_SECOND,
},
ATTR_API_WIND_BEARING: {SENSOR_NAME: "Wind bearing", SENSOR_UNIT: DEGREE},
ATTR_API_HUMIDITY: {
SENSOR_NAME: "Humidity",
SENSOR_UNIT: PERCENTAGE,
SENSOR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
SENSOR_DEVICE_CLASS: SensorDeviceClass.HUMIDITY,
},
# ATTR_API_PRESSURE: {
# SENSOR_NAME: "Pressure",
# SENSOR_UNIT: PRESSURE_HPA,
# SENSOR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE,
# SENSOR_DEVICE_CLASS: SensorDeviceClass.PRESSURE,
# },
ATTR_API_CLOUDS: {SENSOR_NAME: "Cloud coverage", SENSOR_UNIT: PERCENTAGE},
# ATTR_API_RAIN: {SENSOR_NAME: "Rain", SENSOR_UNIT: LENGTH_MILLIMETERS},
# ATTR_API_SNOW: {SENSOR_NAME: "Snow", SENSOR_UNIT: LENGTH_MILLIMETERS},
# ATTR_API_RAIN: {SENSOR_NAME: "Rain", SENSOR_UNIT: UnitOfLength.MILLIMETERS},
# ATTR_API_SNOW: {SENSOR_NAME: "Snow", SENSOR_UNIT: UnitOfLength.MILLIMETERS},
# ATTR_API_PRECIPITATION_KIND: {SENSOR_NAME: "Precipitation kind"},
ATTR_API_UV_INDEX: {
SENSOR_NAME: "UV Index",
Expand All @@ -186,7 +183,7 @@
ATTR_FORECAST_CONDITION: {SENSOR_NAME: "Condition"},
ATTR_FORECAST_PRECIPITATION: {
SENSOR_NAME: "Precipitation",
SENSOR_UNIT: LENGTH_MILLIMETERS,
SENSOR_UNIT: UnitOfLength.MILLIMETERS,
},
ATTR_FORECAST_PRECIPITATION_PROBABILITY: {
SENSOR_NAME: "Precipitation probability",
Expand All @@ -195,25 +192,25 @@
# ATTR_FORECAST_PRESSURE: {
# SENSOR_NAME: "Pressure",
# SENSOR_UNIT: PRESSURE_HPA,
# SENSOR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE,
# SENSOR_DEVICE_CLASS: SensorDeviceClass.PRESSURE,
# },
ATTR_FORECAST_TEMP: {
SENSOR_NAME: "Temperature",
SENSOR_UNIT: TEMP_CELSIUS,
SENSOR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
SENSOR_UNIT: UnitOfTemperature.CELSIUS,
SENSOR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
},
# ATTR_FORECAST_TEMP_LOW: {
# SENSOR_NAME: "Temperature Low",
# SENSOR_UNIT: TEMP_CELSIUS,
# SENSOR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
# SENSOR_UNIT: UnitOfTemperature.CELSIUS,
# SENSOR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
# },
ATTR_FORECAST_TIME: {
SENSOR_NAME: "Time",
SENSOR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP,
SENSOR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
},
ATTR_API_WIND_BEARING: {SENSOR_NAME: "Wind bearing", SENSOR_UNIT: DEGREE},
ATTR_API_WIND_SPEED: {
SENSOR_NAME: "Wind speed",
SENSOR_UNIT: SPEED_METERS_PER_SECOND,
SENSOR_UNIT: UnitOfSpeed.METERS_PER_SECOND,
},
}
6 changes: 3 additions & 3 deletions custom_components/opencwb/weather.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Support for the OpenCWB (OCWB) service."""
from homeassistant.components.weather import WeatherEntity
from homeassistant.const import PRESSURE_HPA, PRESSURE_INHG, TEMP_CELSIUS
from homeassistant.const import UnitOfPressure, UnitOfTemperature
from homeassistant.util.unit_conversion import PressureConverter
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
Expand Down Expand Up @@ -84,7 +84,7 @@ async def async_added_to_hass(self):

async def async_update(self):
"""Get the latest data from OCWB and updates the states."""
self._attr_temperature_unit = TEMP_CELSIUS
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
self._attr_wind_speed_unit = self.anws_aoaws_now.wind_speed.units

self._attr_forecast = self._weather_coordinator.data[ATTR_API_FORECAST]
Expand All @@ -94,7 +94,7 @@ async def async_update(self):
# OpenWeatherMap returns pressure in hPA, so convert to
# inHg if we aren't using metric.
if not self.hass.config.units.is_metric and pressure:
self._attr_pressure = PressureConverter.convert(pressure, PRESSURE_HPA, PRESSURE_INHG)
self._attr_pressure = PressureConverter(pressure, UnitOfPressure.HPA, UnitOfPressure.INHG)
self._attr_pressure = pressure

wind_speed = self._weather_coordinator.data[ATTR_API_WIND_SPEED]
Expand Down

0 comments on commit 8bdbdc8

Please sign in to comment.