Skip to content

Commit

Permalink
fix: remove deprecated DEVICE_CLASS
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealWaldo committed Jan 5, 2023
1 parent 4f79182 commit 03c8530
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
17 changes: 7 additions & 10 deletions custom_components/optimal_humidity/const.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""Constants for optimal_humidity."""

from homeassistant.components.sensor import (
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE,
)
from homeassistant.components.sensor import SensorDeviceClass

from homeassistant.const import (
PERCENTAGE,
Expand Down Expand Up @@ -43,7 +40,7 @@
ATTR_DEWPOINT: (
ATTR_DEWPOINT,
TEMP_CELSIUS,
DEVICE_CLASS_TEMPERATURE,
SensorDeviceClass.TEMPERATURE,
"hass:thermometer",
),
ATTR_SPECIFIC_HUMIDITY: (
Expand All @@ -55,19 +52,19 @@
ATTR_OPTIMAL_HUMIDITY: (
ATTR_OPTIMAL_HUMIDITY,
PERCENTAGE,
DEVICE_CLASS_HUMIDITY,
SensorDeviceClass.HUMIDITY,
"mdi:water-percent",
),
ATTR_CRITICAL_HUMIDITY: (
ATTR_CRITICAL_HUMIDITY,
PERCENTAGE,
DEVICE_CLASS_HUMIDITY,
SensorDeviceClass.HUMIDITY,
"mdi:water-percent",
),
ATTR_HUMIDEX: (
ATTR_HUMIDEX,
TEMP_CELSIUS,
DEVICE_CLASS_TEMPERATURE,
SensorDeviceClass.TEMPERATURE,
"hass:thermometer",
),
ATTR_HUMIDEX_COMFORT: (
Expand All @@ -85,13 +82,13 @@
ATTR_OPTIMAL_HUMIDEX: (
ATTR_OPTIMAL_HUMIDEX,
TEMP_CELSIUS,
DEVICE_CLASS_TEMPERATURE,
SensorDeviceClass.TEMPERATURE,
"hass:thermometer",
),
ATTR_COMFORTABLE_HUMIDITY: (
ATTR_COMFORTABLE_HUMIDITY,
PERCENTAGE,
DEVICE_CLASS_HUMIDITY,
SensorDeviceClass.HUMIDITY,
"mdi:water-percent",
),
}
Expand Down
35 changes: 23 additions & 12 deletions custom_components/optimal_humidity/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
PLATFORM_SCHEMA,
)

from homeassistant.components.sensor import SensorDeviceClass

from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT,
CONF_NAME,
Expand All @@ -45,7 +47,6 @@
STATE_UNKNOWN,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
DEVICE_CLASS_TEMPERATURE,
)
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -150,7 +151,8 @@ def __init__(
self._is_metric = hass.config.units.is_metric

psychrolib.SetUnitSystem(psychrolib.SI)
self._indoor_pressure = psychrolib.GetStandardAtmPressure(hass.config.elevation)
self._indoor_pressure = psychrolib.GetStandardAtmPressure(
hass.config.elevation)
_LOGGER.debug(
"Pressure at current elevation of %s m is %s Pa",
hass.config.elevation,
Expand Down Expand Up @@ -225,7 +227,8 @@ def critical_humidity_startup(event):
crit_temp = self.hass.states.get(self._critical_temp_sensor)
indoor_hum = self.hass.states.get(self._indoor_humidity_sensor)
if self._indoor_pressure_sensor is not None:
indoor_pressure = self.hass.states.get(self._indoor_pressure_sensor)
indoor_pressure = self.hass.states.get(
self._indoor_pressure_sensor)

schedule_update = self._update_sensor(
self._indoor_temp_sensor, None, indoor_temp
Expand Down Expand Up @@ -277,7 +280,8 @@ def _update_sensor(self, entity, old_state, new_state):
elif entity == self._indoor_humidity_sensor:
self._indoor_hum = OptimalHumidity._update_hum_sensor(new_state)
elif entity == self._indoor_pressure_sensor:
self._indoor_pressure = OptimalHumidity._update_pressure_sensor(new_state)
self._indoor_pressure = OptimalHumidity._update_pressure_sensor(
new_state)

return True

Expand Down Expand Up @@ -472,7 +476,8 @@ def _humidex(self, temperature, humidity):
"""Calculate humidex given temperature and humidity"""
# It equals H = T + (0.5555 * (e - 10)), where T is the temperature in Celsius and e is the vapor pressure in millibars (mb)
psychrolib.SetUnitSystem(psychrolib.SI)
vapor_pressure = psychrolib.GetVapPresFromRelHum(temperature, humidity) * 0.01
vapor_pressure = psychrolib.GetVapPresFromRelHum(
temperature, humidity) * 0.01
return self._indoor_temp + (0.5555 * (vapor_pressure - 10))

def _calc_humidex(self):
Expand Down Expand Up @@ -544,7 +549,8 @@ def _calc_critical_humidity(self):
else:
psychrolib.SetUnitSystem(psychrolib.SI)
crit_humidity = (
psychrolib.GetRelHumFromTDewPoint(self._crit_temp, self._dewpoint) * 100
psychrolib.GetRelHumFromTDewPoint(
self._crit_temp, self._dewpoint) * 100
)

if crit_humidity > 100:
Expand Down Expand Up @@ -607,7 +613,8 @@ def _calc_optimal_humidex(self):
if None in (self._optimal_humidity, self._indoor_temp):
self._optimal_humidex = None
return
optimal_humidex = self._humidex(self._indoor_temp, self._optimal_humidity / 100)
optimal_humidex = self._humidex(
self._indoor_temp, self._optimal_humidity / 100)
self._optimal_humidex = float(f"{optimal_humidex:.2f}")
_LOGGER.debug(
"Optimal humidex set to %s %s", self._optimal_humidex, TEMP_CELSIUS
Expand Down Expand Up @@ -635,7 +642,8 @@ def _calc_comfortable_humidity(self):
)
* 100
)
_LOGGER.debug("Comfortable relative humidity is: %s", comfortable_humidity)
_LOGGER.debug("Comfortable relative humidity is: %s",
comfortable_humidity)
if comfortable_humidity > 100:
_LOGGER.warn(
"Not possible to reach a comfortable humidity at %s%s, will feel dry.",
Expand Down Expand Up @@ -668,7 +676,8 @@ def _calc_optimal_humidity(self):
_LOGGER.debug("Comfortable dewpoint is %s", comfortable_dew_point)

if comfortable_dew_point > self._crit_temp:
_LOGGER.debug("Comfortable dewpoint is above critical dry bulb temperature")
_LOGGER.debug(
"Comfortable dewpoint is above critical dry bulb temperature")
critical_humidity = 1
else:
critical_humidity = psychrolib.GetRelHumFromTDewPoint(
Expand Down Expand Up @@ -696,7 +705,8 @@ def _calc_optimal_humidity(self):
return
else:
optimal_humidity = (
psychrolib.GetRelHumFromTDewPoint(self._indoor_temp, dew_point)
psychrolib.GetRelHumFromTDewPoint(
self._indoor_temp, dew_point)
* 100
)
else:
Expand All @@ -709,7 +719,8 @@ def _calc_optimal_humidity(self):
else:
self._optimal_humidity = float(f"{optimal_humidity:.1f}")

_LOGGER.debug("Optimal humidity: %s %s", self._optimal_humidity, PERCENTAGE)
_LOGGER.debug("Optimal humidity: %s %s",
self._optimal_humidity, PERCENTAGE)

@property
def should_poll(self):
Expand All @@ -725,7 +736,7 @@ def name(self):
def unit_of_measurement(self):
"""Return the unit of measurement."""

if SENSOR_TYPES[self._sensor_type][3] == DEVICE_CLASS_TEMPERATURE:
if SENSOR_TYPES[self._sensor_type][3] == SensorDeviceClass.TEMPERATURE:
if self._is_metric:
return TEMP_CELSIUS
return TEMP_FAHRENHEIT
Expand Down

0 comments on commit 03c8530

Please sign in to comment.