Enforce FanEntityFeature (#82458)
* Enforce FanEntityFeature * Adjust pylint
This commit is contained in:
parent
34607d4410
commit
12cb17620e
7 changed files with 14 additions and 12 deletions
|
@ -82,9 +82,9 @@ class BondFan(BondEntity, FanEntity):
|
||||||
self._attr_preset_mode = PRESET_MODE_BREEZE if breeze[0] else None
|
self._attr_preset_mode = PRESET_MODE_BREEZE if breeze[0] else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> FanEntityFeature | int:
|
def supported_features(self) -> FanEntityFeature:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
features = 0
|
features = FanEntityFeature(0)
|
||||||
if self._device.supports_speed():
|
if self._device.supports_speed():
|
||||||
features |= FanEntityFeature.SET_SPEED
|
features |= FanEntityFeature.SET_SPEED
|
||||||
if self._device.supports_direction():
|
if self._device.supports_direction():
|
||||||
|
|
|
@ -158,9 +158,9 @@ class EsphomeFan(EsphomeEntity[FanInfo, FanState], FanEntity):
|
||||||
return _FAN_DIRECTIONS.from_esphome(self._state.direction)
|
return _FAN_DIRECTIONS.from_esphome(self._state.direction)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> FanEntityFeature | int:
|
def supported_features(self) -> FanEntityFeature:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
flags = 0
|
flags = FanEntityFeature(0)
|
||||||
if self._static_info.supports_oscillation:
|
if self._static_info.supports_oscillation:
|
||||||
flags |= FanEntityFeature.OSCILLATE
|
flags |= FanEntityFeature.OSCILLATE
|
||||||
if self._static_info.supports_speed:
|
if self._static_info.supports_speed:
|
||||||
|
|
|
@ -190,7 +190,7 @@ class FanEntity(ToggleEntity):
|
||||||
_attr_preset_mode: str | None
|
_attr_preset_mode: str | None
|
||||||
_attr_preset_modes: list[str] | None
|
_attr_preset_modes: list[str] | None
|
||||||
_attr_speed_count: int
|
_attr_speed_count: int
|
||||||
_attr_supported_features: FanEntityFeature | int = 0
|
_attr_supported_features: FanEntityFeature = FanEntityFeature(0)
|
||||||
|
|
||||||
def set_percentage(self, percentage: int) -> None:
|
def set_percentage(self, percentage: int) -> None:
|
||||||
"""Set the speed of the fan, as a percentage."""
|
"""Set the speed of the fan, as a percentage."""
|
||||||
|
@ -363,7 +363,7 @@ class FanEntity(ToggleEntity):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> FanEntityFeature | int:
|
def supported_features(self) -> FanEntityFeature:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return self._attr_supported_features
|
return self._attr_supported_features
|
||||||
|
|
||||||
|
|
|
@ -313,8 +313,10 @@ class FanGroup(GroupEntity, FanEntity):
|
||||||
"_direction", FanEntityFeature.DIRECTION, ATTR_DIRECTION
|
"_direction", FanEntityFeature.DIRECTION, ATTR_DIRECTION
|
||||||
)
|
)
|
||||||
|
|
||||||
self._attr_supported_features = reduce(
|
self._attr_supported_features = FanEntityFeature(
|
||||||
ior, [feature for feature in SUPPORTED_FLAGS if self._fans[feature]], 0
|
reduce(
|
||||||
|
ior, [feature for feature in SUPPORTED_FLAGS if self._fans[feature]], 0
|
||||||
|
)
|
||||||
)
|
)
|
||||||
self._attr_assumed_state |= any(
|
self._attr_assumed_state |= any(
|
||||||
state.attributes.get(ATTR_ASSUMED_STATE) for state in states
|
state.attributes.get(ATTR_ASSUMED_STATE) for state in states
|
||||||
|
|
|
@ -95,9 +95,9 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity):
|
||||||
return oscillating == 1
|
return oscillating == 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> FanEntityFeature | int:
|
def supported_features(self) -> FanEntityFeature:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
features = 0
|
features = FanEntityFeature(0)
|
||||||
|
|
||||||
if self.service.has(CharacteristicsTypes.ROTATION_DIRECTION):
|
if self.service.has(CharacteristicsTypes.ROTATION_DIRECTION):
|
||||||
features |= FanEntityFeature.DIRECTION
|
features |= FanEntityFeature.DIRECTION
|
||||||
|
|
|
@ -334,7 +334,7 @@ class MqttFan(MqttEntity, FanEntity):
|
||||||
optimistic or self._topic[CONF_PRESET_MODE_STATE_TOPIC] is None
|
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._attr_supported_features |= (
|
||||||
self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None
|
self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None
|
||||||
and FanEntityFeature.OSCILLATE
|
and FanEntityFeature.OSCILLATE
|
||||||
|
|
|
@ -1290,7 +1290,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
||||||
),
|
),
|
||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="supported_features",
|
function_name="supported_features",
|
||||||
return_type=["FanEntityFeature", "int"],
|
return_type="FanEntityFeature",
|
||||||
),
|
),
|
||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="set_percentage",
|
function_name="set_percentage",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue