Skip to content

Commit

Permalink
replace all deprecated constants with latest equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerkj committed Jan 9, 2024
1 parent de21ea0 commit eee2785
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions custom_components/worlds_air_quality_index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CONF_METHOD,
CONF_ID,
CONF_TEMPERATURE_UNIT,
TEMP_CELSIUS
UnitOfTemperature
)

from .const import (
Expand Down Expand Up @@ -69,7 +69,7 @@ async def async_migrate_entry(hass, config_entry):
config_entries.async_update_entry(config_entry, data=new_data)

if version == 2:
tempUnit = TEMP_CELSIUS
tempUnit = UnitOfTemperature.CELSIUS
new_data = {**data, CONF_TEMPERATURE_UNIT: tempUnit}

version = 3
Expand Down
15 changes: 7 additions & 8 deletions custom_components/worlds_air_quality_index/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
CONF_METHOD,
CONF_ID,
CONF_TEMPERATURE_UNIT,
TEMP_FAHRENHEIT,
TEMP_CELSIUS
UnitOfTemperature
)
from .const import (
DOMAIN,
Expand Down Expand Up @@ -76,10 +75,10 @@ async def async_step_geographic_localization(self, user_input=None) -> FlowResul
data_schema = vol.Schema(
{
vol.Required(CONF_TOKEN): cv.string,
vol.Required(CONF_TEMPERATURE_UNIT, default=TEMP_CELSIUS): vol.In(
vol.Required(CONF_TEMPERATURE_UNIT, default=UnitOfTemperature.CELSIUS): vol.In(
(
TEMP_CELSIUS,
TEMP_FAHRENHEIT
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT
)
),
vol.Required(CONF_LATITUDE, default=self.hass.config.latitude): cv.latitude,
Expand Down Expand Up @@ -147,10 +146,10 @@ async def async_step_station_id(self, user_input=None) -> FlowResult:
data_schema = vol.Schema(
{
vol.Required(CONF_TOKEN): cv.string,
vol.Required(CONF_TEMPERATURE_UNIT, default=TEMP_CELSIUS): vol.In(
vol.Required(CONF_TEMPERATURE_UNIT, default=UnitOfTemperature.CELSIUS): vol.In(
(
TEMP_CELSIUS,
TEMP_FAHRENHEIT
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT
)
),
vol.Required(CONF_ID): cv.string,
Expand Down
18 changes: 9 additions & 9 deletions custom_components/worlds_air_quality_index/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from typing import Final

from homeassistant.const import (
TEMP_CELSIUS,
PRESSURE_HPA,
UnitOfPressure,
UnitOfSpeed,
UnitOfTemperature,
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
SPEED_METERS_PER_SECOND,
LENGTH_MILLIMETERS,
UnitOfLength,
PERCENTAGE,
Platform
)
Expand All @@ -33,10 +33,10 @@
'h': ['Humidity', PERCENTAGE, 'mdi:water-percent', SensorDeviceClass.HUMIDITY],
'no2': ['Nitrogen dioxide (NO2)', CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, 'mdi:smog', SensorDeviceClass.NITROGEN_DIOXIDE],
'o3': ['Ozone (O3)', CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, 'mdi:skull-outline', SensorDeviceClass.OZONE],
'p': ['Atmospheric pressure', PRESSURE_HPA, 'mdi:gauge', SensorDeviceClass.PRESSURE],
'p': ['Atmospheric pressure', UnitOfPressure.HPA, 'mdi:gauge', SensorDeviceClass.PRESSURE],
'so2': ['Sulphur dioxide (SO2)', CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, 'mdi:smog', SensorDeviceClass.SULPHUR_DIOXIDE],
't': ['Temperature', TEMP_CELSIUS, 'mdi:thermometer', SensorDeviceClass.TEMPERATURE],
'r': ['Rain', LENGTH_MILLIMETERS, 'mdi:weather-rainy', None],
'w': ['Wind speed', SPEED_METERS_PER_SECOND, 'mdi:weather-windy', None],
'wg': ['Wind gust', SPEED_METERS_PER_SECOND, 'mdi:weather-windy', None],
't': ['Temperature', UnitOfTemperature.CELSIUS, 'mdi:thermometer', SensorDeviceClass.TEMPERATURE],
'r': ['Rain', UnitOfLength.MILLIMETERS, 'mdi:weather-rainy', None],
'w': ['Wind speed', UnitOfSpeed.METERS_PER_SECOND, 'mdi:weather-windy', None],
'wg': ['Wind gust', UnitOfSpeed.METERS_PER_SECOND, 'mdi:weather-windy', None],
}
7 changes: 3 additions & 4 deletions custom_components/worlds_air_quality_index/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
CONF_TEMPERATURE_UNIT,
CONF_TOKEN,
STATE_UNAVAILABLE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UnitOfTemperature,
)

from .const import (
Expand Down Expand Up @@ -159,7 +158,7 @@ def state(self):
def unit_of_measurement(self) -> str:
#Return the unit of measurement.

if SENSORS[self._resType][1] == TEMP_CELSIUS:
if SENSORS[self._resType][1] == UnitOfTemperature.CELSIUS:
return self._tempUnit
else:
return SENSORS[self._resType][1]
Expand Down Expand Up @@ -197,7 +196,7 @@ def update(self) -> None:

elif self._resType in self._data["data"]["iaqi"]:
if self._resType == 't':
if self._tempUnit == TEMP_FAHRENHEIT:
if self._tempUnit == UnitOfTemperature.FAHRENHEIT:
self._state = 9.0 * float(self._data["data"]["iaqi"]['t']["v"]) / 5.0 + 32.0
else:
self._state = float(self._data["data"]["iaqi"]['t']["v"])
Expand Down

0 comments on commit eee2785

Please sign in to comment.