mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-24 12:25:20 +01:00
Add support for fan preset modes (#616)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
b22258cca7
commit
5961535dda
@ -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
@ -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
|
||||
|
@ -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 ====================
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user