Use new HumidifierDeviceClass enum in generic_hygrostat (#61607)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/61738/head
epenet 2021-12-13 23:16:54 +01:00 committed by GitHub
parent 85607970cf
commit 6157dfe68b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View File

@ -2,10 +2,7 @@
import voluptuous as vol
from homeassistant.components.humidifier.const import (
DEVICE_CLASS_DEHUMIDIFIER,
DEVICE_CLASS_HUMIDIFIER,
)
from homeassistant.components.humidifier import HumidifierDeviceClass
from homeassistant.const import CONF_NAME
from homeassistant.helpers import config_validation as cv, discovery
@ -34,7 +31,7 @@ HYGROSTAT_SCHEMA = vol.Schema(
vol.Required(CONF_HUMIDIFIER): cv.entity_id,
vol.Required(CONF_SENSOR): cv.entity_id,
vol.Optional(CONF_DEVICE_CLASS): vol.In(
[DEVICE_CLASS_HUMIDIFIER, DEVICE_CLASS_DEHUMIDIFIER]
[HumidifierDeviceClass.HUMIDIFIER, HumidifierDeviceClass.DEHUMIDIFIER]
),
vol.Optional(CONF_MAX_HUMIDITY): vol.Coerce(int),
vol.Optional(CONF_MIN_DUR): vol.All(cv.time_period, cv.positive_timedelta),

View File

@ -2,11 +2,13 @@
import asyncio
import logging
from homeassistant.components.humidifier import PLATFORM_SCHEMA, HumidifierEntity
from homeassistant.components.humidifier import (
PLATFORM_SCHEMA,
HumidifierDeviceClass,
HumidifierEntity,
)
from homeassistant.components.humidifier.const import (
ATTR_HUMIDITY,
DEVICE_CLASS_DEHUMIDIFIER,
DEVICE_CLASS_HUMIDIFIER,
MODE_AWAY,
MODE_NORMAL,
SUPPORT_MODES,
@ -146,7 +148,7 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
self._remove_stale_tracking = None
self._is_away = False
if not self._device_class:
self._device_class = DEVICE_CLASS_HUMIDIFIER
self._device_class = HumidifierDeviceClass.HUMIDIFIER
async def async_added_to_hass(self):
"""Run when entity about to be added."""
@ -185,7 +187,7 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
if old_state.state:
self._state = old_state.state == STATE_ON
if self._target_humidity is None:
if self._device_class == DEVICE_CLASS_HUMIDIFIER:
if self._device_class == HumidifierDeviceClass.HUMIDIFIER:
self._target_humidity = self.min_humidity
else:
self._target_humidity = self.max_humidity
@ -396,8 +398,10 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
too_dry = self._target_humidity - self._cur_humidity >= dry_tolerance
too_wet = self._cur_humidity - self._target_humidity >= wet_tolerance
if self._is_device_active:
if (self._device_class == DEVICE_CLASS_HUMIDIFIER and too_wet) or (
self._device_class == DEVICE_CLASS_DEHUMIDIFIER and too_dry
if (
self._device_class == HumidifierDeviceClass.HUMIDIFIER and too_wet
) or (
self._device_class == HumidifierDeviceClass.DEHUMIDIFIER and too_dry
):
_LOGGER.info("Turning off humidifier %s", self._switch_entity_id)
await self._async_device_turn_off()
@ -405,8 +409,10 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
# The time argument is passed only in keep-alive case
await self._async_device_turn_on()
else:
if (self._device_class == DEVICE_CLASS_HUMIDIFIER and too_dry) or (
self._device_class == DEVICE_CLASS_DEHUMIDIFIER and too_wet
if (
self._device_class == HumidifierDeviceClass.HUMIDIFIER and too_dry
) or (
self._device_class == HumidifierDeviceClass.DEHUMIDIFIER and too_wet
):
_LOGGER.info("Turning on humidifier %s", self._switch_entity_id)
await self._async_device_turn_on()