Skip to content

Commit

Permalink
Add has_occupancy property to Device
Browse files Browse the repository at this point in the history
Also define a `OCCUPANCY_MIN_API_VERSION` constant.
  • Loading branch information
jfroy committed Jul 27, 2022
1 parent 15cfa92 commit 078a83e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions aiobafi6/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# The minimum device API version supported by aiobafi6.
MIN_API_VERSION = 4

# The minimum device API version for occupancy support.
OCCUPANCY_MIN_API_VERSION = 5
17 changes: 15 additions & 2 deletions aiobafi6/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from google.protobuf.message import Message

from . import wireutils
from .const import OCCUPANCY_MIN_API_VERSION
from .discovery import Service
from .proto import aiobafi6_pb2
from .protoprop import (
Expand Down Expand Up @@ -492,6 +493,16 @@ def has_auto_comfort(self) -> bool: # pylint: disable=missing-function-docstrin
hc3 = maybe_proto_field(self._properties.capabilities, "has_comfort3") or False
return hc1 and hc3

@property
def has_occupancy(self) -> bool: # pylint: disable=missing-function-docstring
try:
api_version = int(self.api_version or 0)
except ValueError:
api_version = 0
# There is probably a capability flag for this but it is unknown. Speculatively,
# a device that supports auto comfort is assumed to supports occupancy.
return api_version >= OCCUPANCY_MIN_API_VERSION and self.has_auto_comfort

# Fan

# pylint: disable=unnecessary-lambda
Expand Down Expand Up @@ -530,7 +541,7 @@ def has_auto_comfort(self) -> bool: # pylint: disable=missing-function-docstrin
target_rpm = ProtoProp[int]()
current_rpm = ProtoProp[int]()

fan_occupancy_detected = ProtoProp[bool](min_api_version=5)
fan_occupancy_detected = ProtoProp[bool](min_api_version=OCCUPANCY_MIN_API_VERSION)

# Light

Expand All @@ -550,7 +561,9 @@ def has_auto_comfort(self) -> bool: # pylint: disable=missing-function-docstrin
light_warmest_color_temperature = ProtoProp[int]()
light_coolest_color_temperature = ProtoProp[int]()

light_occupancy_detected = ProtoProp[bool](min_api_version=5)
light_occupancy_detected = ProtoProp[bool](
min_api_version=OCCUPANCY_MIN_API_VERSION
)

# Sensors

Expand Down

0 comments on commit 078a83e

Please sign in to comment.