Add support for fan preset modes (#616)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Tucker Kern 2023-12-05 19:34:57 -07:00 committed by GitHub
parent b22258cca7
commit 5961535dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 250 additions and 234 deletions

View File

@ -365,6 +365,7 @@ message ListEntitiesFanResponse {
bool disabled_by_default = 9;
string icon = 10;
EntityCategory entity_category = 11;
repeated string supported_preset_modes = 12;
}
enum FanSpeed {
FAN_SPEED_LOW = 0;
@ -387,6 +388,7 @@ message FanStateResponse {
FanSpeed speed = 4 [deprecated = true];
FanDirection direction = 5;
int32 speed_level = 6;
string preset_mode = 7;
}
message FanCommandRequest {
option (id) = 31;
@ -405,6 +407,8 @@ message FanCommandRequest {
FanDirection direction = 9;
bool has_speed_level = 10;
int32 speed_level = 11;
bool has_preset_mode = 12;
string preset_mode = 13;
}
// ==================== LIGHT ====================

File diff suppressed because one or more lines are too long

View File

@ -956,6 +956,7 @@ class APIClient:
speed_level: int | None = None,
oscillating: bool | None = None,
direction: FanDirection | None = None,
preset_mode: str | None = None,
) -> None:
req = FanCommandRequest(key=key)
if state is not None:
@ -973,6 +974,9 @@ class APIClient:
if direction is not None:
req.has_direction = True
req.direction = direction
if preset_mode is not None:
req.has_preset_mode = True
req.preset_mode = preset_mode
self._get_connection().send_message(req)
async def light_command( # pylint: disable=too-many-branches

View File

@ -248,6 +248,9 @@ class FanInfo(EntityInfo):
supports_speed: bool = False
supports_direction: bool = False
supported_speed_levels: int = 0
supported_preset_modes: list[str] = converter_field(
default_factory=list, converter=list
)
class FanSpeed(APIIntEnum):
@ -272,6 +275,7 @@ class FanState(EntityState):
direction: FanDirection | None = converter_field(
default=FanDirection.FORWARD, converter=FanDirection.convert
)
preset_mode: str = ""
# ==================== LIGHT ====================

View File

@ -400,6 +400,10 @@ async def test_cover_command(
dict(key=1, direction=FanDirection.REVERSE),
dict(key=1, has_direction=True, direction=FanDirection.REVERSE),
),
(
dict(key=1, preset_mode="auto"),
dict(key=1, has_preset_mode=True, preset_mode="auto"),
),
],
)
async def test_fan_command(