diff --git a/custom_components/opencwb/const.py b/custom_components/opencwb/const.py index 5dee4be..e90d134 100755 --- a/custom_components/opencwb/const.py +++ b/custom_components/opencwb/const.py @@ -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, ) @@ -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", @@ -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", @@ -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, }, } diff --git a/custom_components/opencwb/weather.py b/custom_components/opencwb/weather.py index cc2cda9..9731fac 100755 --- a/custom_components/opencwb/weather.py +++ b/custom_components/opencwb/weather.py @@ -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 @@ -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] @@ -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]