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

@@ -300,7 +300,9 @@ class KlapTransport(BaseTransport):
# There is a 24 hour timeout on the session cookie
# but the clock on the device is not always accurate
# so we set the expiry to 24 hours from now minus a buffer
self._session_expire_at = time.time() + timeout - SESSION_EXPIRE_BUFFER_SECONDS
self._session_expire_at = (
time.monotonic() + timeout - SESSION_EXPIRE_BUFFER_SECONDS
)
self._encryption_session = await self.perform_handshake2(
local_seed, remote_seed, auth_hash
)
@@ -312,7 +314,7 @@ class KlapTransport(BaseTransport):
"""Return true if session has expired."""
return (
self._session_expire_at is None
or self._session_expire_at - time.time() <= 0
or self._session_expire_at - time.monotonic() <= 0
)
async def send(self, request: str):