Skip to content

Commit e897841

Browse files
authored
Add support for new FanEntityFeature flags (#100)
1 parent 168c60b commit e897841

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

zha/application/platforms/fan/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
PRESET_MODES_TO_NAME,
2929
SPEED_OFF,
3030
SPEED_RANGE,
31-
SUPPORT_SET_SPEED,
3231
FanEntityFeature,
3332
)
3433
from zha.application.platforms.fan.helpers import (
@@ -65,7 +64,7 @@ class FanEntityInfo(BaseEntityInfo):
6564
"""Fan entity info."""
6665

6766
preset_modes: list[str]
68-
supported_features: int
67+
supported_features: FanEntityFeature
6968
speed_count: int
7069
speed_list: list[str]
7170

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

7675
PLATFORM = Platform.FAN
7776

78-
_attr_supported_features = FanEntityFeature.SET_SPEED
77+
_attr_supported_features: FanEntityFeature = (
78+
FanEntityFeature.SET_SPEED
79+
| FanEntityFeature.TURN_OFF
80+
| FanEntityFeature.TURN_ON
81+
)
7982
_attr_translation_key: str = "fan"
8083

8184
@functools.cached_property
@@ -109,9 +112,9 @@ def speed_count(self) -> int:
109112
return int_states_in_range(self.speed_range)
110113

111114
@functools.cached_property
112-
def supported_features(self) -> int:
115+
def supported_features(self) -> FanEntityFeature:
113116
"""Flag supported features."""
114-
return SUPPORT_SET_SPEED
117+
return self._attr_supported_features
115118

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

443-
_attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
446+
_attr_supported_features = (
447+
FanEntityFeature.SET_SPEED
448+
| FanEntityFeature.PRESET_MODE
449+
| FanEntityFeature.TURN_OFF
450+
| FanEntityFeature.TURN_ON
451+
)
444452

445453
@functools.cached_property
446454
def speed_range(self) -> tuple[int, int]:

zha/application/platforms/fan/const.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
ATTR_PRESET_MODE: Final[str] = "preset_mode"
3232
ATTR_PRESET_MODES: Final[str] = "preset_modes"
3333

34-
SUPPORT_SET_SPEED: Final[int] = 1
35-
3634
SPEED_OFF: Final[str] = "off"
3735
SPEED_LOW: Final[str] = "low"
3836
SPEED_MEDIUM: Final[str] = "medium"
@@ -49,3 +47,5 @@ class FanEntityFeature(IntFlag):
4947
OSCILLATE = 2
5048
DIRECTION = 4
5149
PRESET_MODE = 8
50+
TURN_OFF = 16
51+
TURN_ON = 32

0 commit comments

Comments
 (0)