Skip to content

Commit f26b3dc

Browse files
committed
always wait 100ms between REST calls
1 parent 8d13f53 commit f26b3dc

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

example.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,32 @@ async def main():
1616
# client = await TedeeClient.create(personal_token, local_token, ip)
1717
client = TedeeClient(local_ip=ip, local_token=local_token)
1818
bridge = await client.get_local_bridge()
19-
await client.delete_webhook(5)
20-
await client.register_webhook("http://192.168.1.151/events")
19+
# await client.delete_webhook(5)
20+
# await client.register_webhook("http://192.168.1.151/events")
2121
await client.get_locks()
22+
# await client.sync()
23+
# await client.sync()
24+
# bridges = await client.get_bridges()
25+
# client = await TedeeClient.create(
26+
# personal_token, local_token, ip, bridge_id=bridges[0].bridge_id
27+
# )
28+
locks = client.locks
29+
print(1)
2230
await client.sync()
31+
print(2)
2332
await client.sync()
24-
bridges = await client.get_bridges()
25-
client = await TedeeClient.create(
26-
personal_token, local_token, ip, bridge_id=bridges[0].bridge_id
27-
)
28-
locks = client.locks
2933

30-
locks_list = [lock.to_dict() for _, lock in client.locks_dict.items()]
31-
print(locks_list)
32-
json_locks = json.dumps(locks_list)
33-
loaded = json.loads(json_locks)
34-
for lock in loaded:
35-
dec = TedeeLock(**lock)
3634
for lock in locks:
3735
print("----------------------------------------------")
3836
print("Lock name: " + lock.lock_name)
3937
print("Lock id: " + str(lock.lock_id))
4038
print("Lock Battery: " + str(lock.battery_level))
41-
print("Is Locked: " + str(client.is_locked(lock.id)))
42-
print("Is Unlocked: " + str(client.is_unlocked(lock.id)))
39+
print("Is Locked: " + str(client.is_locked(lock.lock_id)))
40+
print("Is Unlocked: " + str(client.is_unlocked(lock.lock_id)))
4341
# await client.register_webhook("http://test.local", headers=[{"Authorization": "Basic " + "test"}])
42+
print(3)
4443
await client.sync()
45-
# await client.lock(lock.id)
44+
await client.unlock(lock.lock_id)
4645
# await asyncio.sleep(5)
4746
# await client.open(lock.id)
4847
# await asyncio.sleep(5)

pytedee_async/const.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@
1515
TIMEOUT = 10
1616
UNLOCK_DELAY = 5
1717
LOCK_DELAY = 5
18-
LOCAL_CALL_MIN_DISTANCE = 1

pytedee_async/helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Helper functions for pytedee_async."""
2+
import asyncio
23
from http import HTTPStatus
34
from typing import Any, Mapping
45

@@ -27,6 +28,8 @@ async def is_personal_key_valid(
2728
except (aiohttp.ClientError, aiohttp.ServerConnectionError, TimeoutError):
2829
return False
2930

31+
await asyncio.sleep(0.1)
32+
3033
if response.status in (
3134
HTTPStatus.OK,
3235
HTTPStatus.CREATED,
@@ -61,7 +64,10 @@ async def http_request(
6164
) as exc:
6265
raise TedeeClientException(f"Error during http call: {exc}") from exc
6366

67+
await asyncio.sleep(0.1)
68+
6469
status_code = response.status
70+
6571
if response.status in (
6672
HTTPStatus.OK,
6773
HTTPStatus.CREATED,

pytedee_async/tedee_client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
API_URL_BRIDGE,
2121
API_URL_LOCK,
2222
API_URL_SYNC,
23-
LOCAL_CALL_MIN_DISTANCE,
2423
LOCK_DELAY,
2524
TIMEOUT,
2625
UNLOCK_DELAY,
@@ -378,11 +377,6 @@ async def _local_api_call(
378377
) -> tuple[bool, Any | None]:
379378
"""Call the local api"""
380379
if self._use_local_api:
381-
if (
382-
self._last_local_call
383-
and time.time() - self._last_local_call < LOCAL_CALL_MIN_DISTANCE
384-
):
385-
await asyncio.sleep(LOCAL_CALL_MIN_DISTANCE)
386380
try:
387381
_LOGGER.debug("Getting locks from Local API...")
388382
self._last_local_call = time.time()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pytedee_async",
8-
version="0.2.12",
8+
version="0.2.13",
99
author="Josef Zweck",
1010
author_email="24647999+zweckj@users.noreply.github.com",
1111
description="A Tedee Lock Client package",

0 commit comments

Comments
 (0)