Skip to content

Commit 8e1bbc2

Browse files
committed
fix: doorbells are not supported with yale global brand
1 parent 9cecd02 commit 8e1bbc2

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

yalexs/api_async.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ async def async_validate_verification_code(
109109
)
110110
)
111111

112-
async def async_get_doorbells(self, access_token: str) -> Doorbell:
112+
async def async_get_doorbells(self, access_token: str) -> list[Doorbell]:
113+
if not self.brand_supports_doorbells:
114+
return []
113115
response = await self._async_dict_to_api(
114116
self._build_get_doorbells_request(access_token)
115117
)

yalexs/api_common.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .doorbell import Doorbell
1212
from .lock import Lock, LockDoorStatus, determine_door_state, door_state_to_string
1313
from .time import parse_datetime
14+
from .backports.functools import cached_property
1415

1516
API_EXCEPTION_RETRY_TIME = 0.1
1617
API_RETRY_TIME = 2.5
@@ -63,10 +64,14 @@
6364
_LOGGER = logging.getLogger(__name__)
6465

6566

67+
def _get_brand_config(brand: Brand) -> BrandConfig:
68+
return BRAND_CONFIG.get(brand, BRAND_CONFIG[DEFAULT_BRAND])
69+
70+
6671
def _api_headers(
6772
access_token: str | None = None, brand: Brand | None = None
6873
) -> dict[str, str]:
69-
brand_config: BrandConfig = BRAND_CONFIG.get(brand, BRAND_CONFIG[DEFAULT_BRAND])
74+
brand_config = _get_brand_config(brand)
7075

7176
headers = {
7277
HEADER_ACCEPT_VERSION: HEADER_VALUE_ACCEPT_VERSION,
@@ -169,6 +174,12 @@ def __init__(self, brand: Brand) -> None:
169174
"""Init."""
170175
self._base_url = BASE_URLS[brand]
171176
self.brand = brand
177+
self.brand_config = _get_brand_config(brand)
178+
179+
@cached_property
180+
def brand_supports_doorbells(self) -> bool:
181+
"""Return if the brand supports doorbells."""
182+
return self.brand_config.supports_doorbells
172183

173184
def get_brand_url(self, url_str: str) -> str:
174185
"""Get url."""

yalexs/const.py

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class BrandConfig:
4545
api_key_header: str
4646
branding_header: str
4747
api_key: str
48+
supports_doorbells: bool
4849

4950

5051
HEADER_VALUE_API_KEY_OLD = "7cab4bbd-2693-4fc1-b99b-dec0fb20f9d4"
@@ -66,6 +67,7 @@ class BrandConfig:
6667
api_key_header=HEADER_AUGUST_API_KEY,
6768
branding_header=HEADER_AUGUST_BRANDING,
6869
api_key=HEADER_VALUE_API_KEY,
70+
supports_doorbells=True,
6971
),
7072
Brand.YALE_ACCESS: BrandConfig(
7173
name="Yale Access",
@@ -74,6 +76,7 @@ class BrandConfig:
7476
api_key_header=HEADER_AUGUST_API_KEY,
7577
branding_header=HEADER_AUGUST_BRANDING,
7678
api_key=HEADER_VALUE_API_KEY,
79+
supports_doorbells=True,
7780
),
7881
Brand.YALE_HOME: BrandConfig(
7982
name="Yale Home",
@@ -82,6 +85,7 @@ class BrandConfig:
8285
api_key_header=HEADER_API_KEY,
8386
branding_header=HEADER_BRANDING,
8487
api_key=HEADER_VALUE_API_KEY,
88+
supports_doorbells=True,
8589
),
8690
Brand.YALE_GLOBAL: BrandConfig(
8791
name="Yale Global",
@@ -93,6 +97,7 @@ class BrandConfig:
9397
# having the API key in the code because it must
9498
# run on the user's device
9599
api_key="d16a1029-d823-4b55-a4ce-a769a9b56f0e",
100+
supports_doorbells=False,
96101
),
97102
}
98103

0 commit comments

Comments
 (0)