Skip to content

Commit

Permalink
Add support for new FanEntityFeature flags (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey authored Jul 29, 2024
1 parent 168c60b commit e897841
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions zha/application/platforms/fan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
PRESET_MODES_TO_NAME,
SPEED_OFF,
SPEED_RANGE,
SUPPORT_SET_SPEED,
FanEntityFeature,
)
from zha.application.platforms.fan.helpers import (
Expand Down Expand Up @@ -65,7 +64,7 @@ class FanEntityInfo(BaseEntityInfo):
"""Fan entity info."""

preset_modes: list[str]
supported_features: int
supported_features: FanEntityFeature
speed_count: int
speed_list: list[str]

Expand All @@ -75,7 +74,11 @@ class BaseFan(BaseEntity):

PLATFORM = Platform.FAN

_attr_supported_features = FanEntityFeature.SET_SPEED
_attr_supported_features: FanEntityFeature = (
FanEntityFeature.SET_SPEED
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)
_attr_translation_key: str = "fan"

@functools.cached_property
Expand Down Expand Up @@ -109,9 +112,9 @@ def speed_count(self) -> int:
return int_states_in_range(self.speed_range)

@functools.cached_property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature:
"""Flag supported features."""
return SUPPORT_SET_SPEED
return self._attr_supported_features

@property
def is_on(self) -> bool:
Expand Down Expand Up @@ -440,7 +443,12 @@ def default_on_percentage(self) -> int:
class KofFan(Fan):
"""Representation of a fan made by King Of Fans."""

_attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
_attr_supported_features = (
FanEntityFeature.SET_SPEED
| FanEntityFeature.PRESET_MODE
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)

@functools.cached_property
def speed_range(self) -> tuple[int, int]:
Expand Down
4 changes: 2 additions & 2 deletions zha/application/platforms/fan/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
ATTR_PRESET_MODE: Final[str] = "preset_mode"
ATTR_PRESET_MODES: Final[str] = "preset_modes"

SUPPORT_SET_SPEED: Final[int] = 1

SPEED_OFF: Final[str] = "off"
SPEED_LOW: Final[str] = "low"
SPEED_MEDIUM: Final[str] = "medium"
Expand All @@ -49,3 +47,5 @@ class FanEntityFeature(IntFlag):
OSCILLATE = 2
DIRECTION = 4
PRESET_MODE = 8
TURN_OFF = 16
TURN_ON = 32

0 comments on commit e897841

Please sign in to comment.