Skip to content

Commit

Permalink
Implement computed property for fans without auto comfort
Browse files Browse the repository at this point in the history
This commit defines 2 unknown fields in the `Capabilities` message that
are not set on fans without auto comfort. The `Device` property exposes a
new computed property (`has_auto_comfort`) when both of those fields are
set to true.

See home-assistant/core#72934
  • Loading branch information
jfroy committed Jun 3, 2022
1 parent ff14259 commit 1f6c2a4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
7 changes: 7 additions & 0 deletions aiobafi6/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,13 @@ def has_fan(self) -> bool:
def has_light(self) -> t.Optional[bool]:
return maybe_proto_field(self._properties.capabilities, "has_light")

@property
def has_auto_comfort(self) -> bool:
# https://github.com/home-assistant/core/issues/72934
c1 = maybe_proto_field(self._properties.capabilities, "has_comfort1") or False
c3 = maybe_proto_field(self._properties.capabilities, "has_comfort3") or False
return c1 and c3

# Fan

fan_mode = ProtoProp[OffOnAuto](writable=True, from_proto=lambda v: OffOnAuto(v))
Expand Down
29 changes: 29 additions & 0 deletions aiobafi6/device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,32 @@ async def test_service_property_read_only():
d = Device(Service(("127.0.0.1",), PORT))
with pytest.raises(AttributeError):
d.service = Service(("127.0.0.2",), PORT) # type: ignore


@pytest.mark.asyncio
async def test_has_auto_comfort():
d = Device(Service(("127.0.0.1",), PORT))
assert not d.has_auto_comfort

d._properties.capabilities.has_comfort1 = False
assert not d.has_auto_comfort

d._properties.capabilities.ClearField("has_comfort1")
d._properties.capabilities.has_comfort3 = False
assert not d.has_auto_comfort

d._properties.capabilities.has_comfort1 = False
d._properties.capabilities.has_comfort3 = False
assert not d.has_auto_comfort

d._properties.capabilities.ClearField("has_comfort3")
d._properties.capabilities.has_comfort1 = True
assert not d.has_auto_comfort

d._properties.capabilities.ClearField("has_comfort1")
d._properties.capabilities.has_comfort3 = True
assert not d.has_auto_comfort

d._properties.capabilities.has_comfort1 = True
d._properties.capabilities.has_comfort3 = True
assert d.has_auto_comfort
24 changes: 12 additions & 12 deletions aiobafi6/proto/aiobafi6_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions aiobafi6/proto/aiobafi6_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ SCHEDULES: ProperyQuery
SENSORS: ProperyQuery

class Capabilities(_message.Message):
__slots__ = ["has_light"]
__slots__ = ["has_comfort1", "has_comfort3", "has_light"]
HAS_COMFORT1_FIELD_NUMBER: ClassVar[int]
HAS_COMFORT3_FIELD_NUMBER: ClassVar[int]
HAS_LIGHT_FIELD_NUMBER: ClassVar[int]
has_comfort1: bool
has_comfort3: bool
has_light: bool
def __init__(self, has_light: bool = ...) -> None: ...
def __init__(self, has_comfort1: bool = ..., has_comfort3: bool = ..., has_light: bool = ...) -> None: ...

class Commit(_message.Message):
__slots__ = ["properties"]
Expand Down
6 changes: 5 additions & 1 deletion proto/aiobafi6.proto
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ message FirmwareProperties {
optional string mac_address = 4;
}

message Capabilities { optional bool has_light = 4; }
message Capabilities {
optional bool has_comfort1 = 1;
optional bool has_comfort3 = 3;
optional bool has_light = 4;
}

message WifiProperties { optional string ssid = 1; }

Expand Down

0 comments on commit 1f6c2a4

Please sign in to comment.