Add support for fan direction (#8)

This commit is contained in:
Jim Ekman 2020-12-14 04:16:37 +01:00 committed by GitHub
parent 892ee4d806
commit fa48a08445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 164 additions and 89 deletions

View File

@ -301,12 +301,17 @@ message ListEntitiesFanResponse {
bool supports_oscillation = 5;
bool supports_speed = 6;
bool supports_direction = 7;
}
enum FanSpeed {
FAN_SPEED_LOW = 0;
FAN_SPEED_MEDIUM = 1;
FAN_SPEED_HIGH = 2;
}
enum FanDirection {
FAN_DIRECTION_FORWARD = 0;
FAN_DIRECTION_REVERSE = 1;
}
message FanStateResponse {
option (id) = 23;
option (source) = SOURCE_SERVER;
@ -317,6 +322,7 @@ message FanStateResponse {
bool state = 2;
bool oscillating = 3;
FanSpeed speed = 4;
FanDirection direction = 5;
}
message FanCommandRequest {
option (id) = 31;
@ -331,6 +337,8 @@ message FanCommandRequest {
FanSpeed speed = 5;
bool has_oscillating = 6;
bool oscillating = 7;
bool has_direction = 8;
FanDirection direction = 9;
}
// ==================== LIGHT ====================

File diff suppressed because one or more lines are too long

View File

@ -253,7 +253,8 @@ class APIClient:
key: int,
state: Optional[bool] = None,
speed: Optional[FanSpeed] = None,
oscillating: Optional[bool] = None
oscillating: Optional[bool] = None,
direction: Optional[FanDirection] = None
) -> None:
self._check_authenticated()
@ -268,6 +269,9 @@ class APIClient:
if oscillating is not None:
req.has_oscillating = True
req.oscillating = oscillating
if direction is not None:
req.has_direction = True
req.direction = direction
await self._connection.send_message(req)
async def light_command(self,

View File

@ -99,6 +99,7 @@ class CoverState(EntityState):
class FanInfo(EntityInfo):
supports_oscillation = attr.ib(type=bool, default=False)
supports_speed = attr.ib(type=bool, default=False)
supports_direction = attr.ib(type=bool, default=False)
class FanSpeed(enum.IntEnum):
@ -107,11 +108,17 @@ class FanSpeed(enum.IntEnum):
HIGH = 2
class FanDirection(enum.IntEnum):
FORWARD = 0
REVERSE = 1
@attr.s
class FanState(EntityState):
state = attr.ib(type=bool, default=False)
oscillating = attr.ib(type=bool, default=False)
speed = attr.ib(type=FanSpeed, converter=FanSpeed, default=FanSpeed.LOW)
direction = attr.ib(type=FanDirection, converter=FanDirection, default=FanDirection.FORWARD)
# ==================== LIGHT ====================