Enforce FanEntityFeature (#82458)

* Enforce FanEntityFeature

* Adjust pylint
pull/82567/head
epenet 2022-11-22 07:13:54 +01:00 committed by GitHub
parent 34607d4410
commit 12cb17620e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 12 deletions

View File

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

View File

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

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: FanEntityFeature | int = 0
_attr_supported_features: FanEntityFeature = FanEntityFeature(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) -> FanEntityFeature | int:
def supported_features(self) -> FanEntityFeature:
"""Flag supported features."""
return self._attr_supported_features

View File

@ -313,9 +313,11 @@ class FanGroup(GroupEntity, FanEntity):
"_direction", FanEntityFeature.DIRECTION, ATTR_DIRECTION
)
self._attr_supported_features = reduce(
self._attr_supported_features = FanEntityFeature(
reduce(
ior, [feature for feature in SUPPORTED_FLAGS if self._fans[feature]], 0
)
)
self._attr_assumed_state |= any(
state.attributes.get(ATTR_ASSUMED_STATE) for state in states
)

View File

@ -95,9 +95,9 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity):
return oscillating == 1
@property
def supported_features(self) -> FanEntityFeature | int:
def supported_features(self) -> FanEntityFeature:
"""Flag supported features."""
features = 0
features = FanEntityFeature(0)
if self.service.has(CharacteristicsTypes.ROTATION_DIRECTION):
features |= FanEntityFeature.DIRECTION

View File

@ -334,7 +334,7 @@ class MqttFan(MqttEntity, FanEntity):
optimistic or self._topic[CONF_PRESET_MODE_STATE_TOPIC] is None
)
self._attr_supported_features = 0
self._attr_supported_features = FanEntityFeature(0)
self._attr_supported_features |= (
self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None
and FanEntityFeature.OSCILLATE

View File

@ -1290,7 +1290,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
),
TypeHintMatch(
function_name="supported_features",
return_type=["FanEntityFeature", "int"],
return_type="FanEntityFeature",
),
TypeHintMatch(
function_name="set_percentage",