Adjust HumidifierEntity type hints (#82248)

pull/82256/head
epenet 2022-11-17 10:58:46 +01:00 committed by GitHub
parent 38a8e86dde
commit 2453f95b24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 5 deletions

View File

@ -147,7 +147,6 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
self._min_humidity = min_humidity
self._max_humidity = max_humidity
self._target_humidity = target_humidity
self._attr_supported_features = 0
if away_humidity:
self._attr_supported_features |= HumidifierEntityFeature.MODES
self._away_humidity = away_humidity

View File

@ -137,6 +137,7 @@ class HumidifierEntity(ToggleEntity):
_attr_max_humidity: int = DEFAULT_MAX_HUMIDITY
_attr_min_humidity: int = DEFAULT_MIN_HUMIDITY
_attr_mode: str | None
_attr_supported_features: HumidifierEntityFeature | int = 0
_attr_target_humidity: int | None = None
@property
@ -223,3 +224,8 @@ class HumidifierEntity(ToggleEntity):
def max_humidity(self) -> int:
"""Return the maximum humidity."""
return self._attr_max_humidity
@property
def supported_features(self) -> HumidifierEntityFeature | int:
"""Return the list of supported features."""
return self._attr_supported_features

View File

@ -271,8 +271,6 @@ class MqttHumidifier(MqttEntity, HumidifierEntity):
self._attr_available_modes = []
if self._attr_available_modes:
self._attr_supported_features = HumidifierEntityFeature.MODES
else:
self._attr_supported_features = 0
optimistic: bool = config[CONF_OPTIMISTIC]
self._optimistic = optimistic or self._topic[CONF_STATE_TOPIC] is None

View File

@ -93,7 +93,6 @@ class TuyaHumidifierEntity(TuyaEntity, HumidifierEntity):
super().__init__(device, device_manager)
self.entity_description = description
self._attr_unique_id = f"{super().unique_id}{description.key}"
self._attr_supported_features = 0
# Determine main switch DPCode
self._switch_dpcode = self.find_dpcode(

View File

@ -115,7 +115,6 @@ class XiaomiGenericHumidifier(XiaomiCoordinatedMiioEntity, HumidifierEntity):
_attr_device_class = HumidifierDeviceClass.HUMIDIFIER
_attr_supported_features = HumidifierEntityFeature.MODES
supported_features: int
def __init__(self, device, entry, unique_id, coordinator):
"""Initialize the generic Xiaomi device."""

View File

@ -1395,6 +1395,61 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
],
),
],
"humidifier": [
ClassTypeHintMatch(
base_class="Entity",
matches=_ENTITY_MATCH,
),
ClassTypeHintMatch(
base_class="ToggleEntity",
matches=_TOGGLE_ENTITY_MATCH,
),
ClassTypeHintMatch(
base_class="HumidifierEntity",
matches=[
TypeHintMatch(
function_name="available_modes",
return_type=["list[str]", None],
),
TypeHintMatch(
function_name="device_class",
return_type=["HumidifierDeviceClass", "str", None],
),
TypeHintMatch(
function_name="min_humidity",
return_type=["int"],
),
TypeHintMatch(
function_name="max_humidity",
return_type=["int"],
),
TypeHintMatch(
function_name="mode",
return_type=["str", None],
),
TypeHintMatch(
function_name="supported_features",
return_type=["HumidifierEntityFeature", "int"],
),
TypeHintMatch(
function_name="target_humidity",
return_type=["int", None],
),
TypeHintMatch(
function_name="set_humidity",
arg_types={1: "str"},
return_type=None,
has_async_counterpart=True,
),
TypeHintMatch(
function_name="set_mode",
arg_types={1: "str"},
return_type=None,
has_async_counterpart=True,
),
],
),
],
"light": [
ClassTypeHintMatch(
base_class="Entity",