Use monotonic time for query timing (#1070)

To fix intermittent issues with [windows
CI](https://github.com/python-kasa/python-kasa/actions/runs/9952477932/job/27493918272?pr=1068).
Probably better to use monotonic here anyway.

```
FAILED kasa/tests/test_smartdevice.py::test_update_module_update_delays[L530E(EU)_3.0_1.1.6.json-SMART] - ValueError: Clock moved backwards. Refusing to generate ID.
```
This commit is contained in:
Steven B.
2024-07-16 13:25:32 +01:00
committed by GitHub
parent 7e9b1687d0
commit b220beb811
5 changed files with 11 additions and 9 deletions

View File

@@ -72,7 +72,7 @@ class HttpClient:
# Once we know a device needs a wait between sequential queries always wait
# first rather than keep erroring then waiting.
if self._wait_between_requests:
now = time.time()
now = time.monotonic()
gap = now - self._last_request_time
if gap < self._wait_between_requests:
sleep = self._wait_between_requests - gap
@@ -123,7 +123,7 @@ class HttpClient:
ex,
)
self._wait_between_requests = self.WAIT_BETWEEN_REQUESTS_ON_OSERROR
self._last_request_time = time.time()
self._last_request_time = time.monotonic()
raise _ConnectionError(
f"Device connection error: {self._config.host}: {ex}", ex
) from ex
@@ -140,7 +140,7 @@ class HttpClient:
# For performance only request system time if waiting is enabled
if self._wait_between_requests:
self._last_request_time = time.time()
self._last_request_time = time.monotonic()
return resp.status, response_data