Adjust type hints for FanEntityFeature (#82241)

* Adjust type hints for FanEntityFeature

* Adjust template default
This commit is contained in:
epenet 2022-11-17 10:30:39 +01:00 committed by GitHub
parent 3d00923665
commit 1b80c66195
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 20 deletions

View file

@ -82,7 +82,7 @@ class BondFan(BondEntity, FanEntity):
self._attr_preset_mode = PRESET_MODE_BREEZE if breeze[0] else None
@property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature | int:
"""Flag supported features."""
features = 0
if self._device.supports_speed():

View file

@ -158,7 +158,7 @@ class EsphomeFan(EsphomeEntity[FanInfo, FanState], FanEntity):
return _FAN_DIRECTIONS.from_esphome(self._state.direction)
@property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature | int:
"""Flag supported features."""
flags = 0
if self._static_info.supports_oscillation:

View file

@ -190,7 +190,7 @@ class FanEntity(ToggleEntity):
_attr_preset_mode: str | None
_attr_preset_modes: list[str] | None
_attr_speed_count: int
_attr_supported_features: int = 0
_attr_supported_features: FanEntityFeature | int = 0
def set_percentage(self, percentage: int) -> None:
"""Set the speed of the fan, as a percentage."""
@ -363,7 +363,7 @@ class FanEntity(ToggleEntity):
return data
@property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature | int:
"""Flag supported features."""
return self._attr_supported_features

View file

@ -95,7 +95,7 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity):
return oscillating == 1
@property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature | int:
"""Flag supported features."""
features = 0

View file

@ -76,9 +76,9 @@ class KNXFan(KnxEntity, FanEntity):
await self._device.set_speed(percentage)
@property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature:
"""Flag supported features."""
flags: int = FanEntityFeature.SET_SPEED
flags = FanEntityFeature.SET_SPEED
if self._device.supports_oscillation:
flags |= FanEntityFeature.OSCILLATE

View file

@ -147,7 +147,6 @@ class TemplateFan(TemplateEntity, FanEntity):
self._preset_mode_template = config.get(CONF_PRESET_MODE_TEMPLATE)
self._oscillating_template = config.get(CONF_OSCILLATING_TEMPLATE)
self._direction_template = config.get(CONF_DIRECTION_TEMPLATE)
self._supported_features = 0
self._on_script = Script(hass, config[CONF_ON_ACTION], friendly_name, DOMAIN)
self._off_script = Script(hass, config[CONF_OFF_ACTION], friendly_name, DOMAIN)
@ -189,18 +188,13 @@ class TemplateFan(TemplateEntity, FanEntity):
self._preset_modes = config.get(CONF_PRESET_MODES)
if self._percentage_template:
self._supported_features |= FanEntityFeature.SET_SPEED
self._attr_supported_features |= FanEntityFeature.SET_SPEED
if self._preset_mode_template and self._preset_modes:
self._supported_features |= FanEntityFeature.PRESET_MODE
self._attr_supported_features |= FanEntityFeature.PRESET_MODE
if self._oscillating_template:
self._supported_features |= FanEntityFeature.OSCILLATE
self._attr_supported_features |= FanEntityFeature.OSCILLATE
if self._direction_template:
self._supported_features |= FanEntityFeature.DIRECTION
@property
def supported_features(self) -> int:
"""Flag supported features."""
return self._supported_features
self._attr_supported_features |= FanEntityFeature.DIRECTION
@property
def speed_count(self) -> int:

View file

@ -250,9 +250,9 @@ class ValueMappingZwaveFan(ZwaveFan):
return len(self.fan_value_mapping.speeds)
@property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature:
"""Flag supported features."""
flags: int = FanEntityFeature.SET_SPEED
flags = FanEntityFeature.SET_SPEED
if self.has_fan_value_mapping and self.fan_value_mapping.presets:
flags |= FanEntityFeature.PRESET_MODE
@ -387,7 +387,7 @@ class ZwaveThermostatFan(ZWaveBaseEntity, FanEntity):
return list(self._fan_mode.metadata.states.values())
@property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature:
"""Flag supported features."""
return FanEntityFeature.PRESET_MODE

View file

@ -1288,6 +1288,10 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
function_name="preset_modes",
return_type=["list[str]", None],
),
TypeHintMatch(
function_name="supported_features",
return_type=["FanEntityFeature", "int"],
),
TypeHintMatch(
function_name="set_percentage",
arg_types={1: "int"},