Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce FanEntityFeature #82458

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/bond/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def _apply_state(self) -> None:
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():
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/esphome/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def current_direction(self) -> str | None:
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:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/fan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -363,7 +363,7 @@ def state_attributes(self) -> dict[str, float | str | None]:
return data

@property
def supported_features(self) -> FanEntityFeature | int:
def supported_features(self) -> FanEntityFeature:
"""Flag supported features."""
return self._attr_supported_features

Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/group/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,10 @@ def async_update_group_state(self) -> None:
"_direction", FanEntityFeature.DIRECTION, ATTR_DIRECTION
)

self._attr_supported_features = reduce(
ior, [feature for feature in SUPPORTED_FLAGS if self._fans[feature]], 0
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
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homekit_controller/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def oscillating(self) -> bool:
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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _setup_from_config(self, config: ConfigType) -> 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._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None
and FanEntityFeature.OSCILLATE
Expand Down
2 changes: 1 addition & 1 deletion pylint/plugins/hass_enforce_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ class ClassTypeHintMatch:
),
TypeHintMatch(
function_name="supported_features",
return_type=["FanEntityFeature", "int"],
return_type="FanEntityFeature",
),
TypeHintMatch(
function_name="set_percentage",
Expand Down