Skip to content

Commit f2bcfe8

Browse files
committed
Add refresh token and expand tests
1 parent f603dca commit f2bcfe8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/tadoasync/tadoasync.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ class Tado: # pylint: disable=too-many-instance-attributes
8585

8686
def __init__(
8787
self,
88+
refresh_token: str | None = None,
8889
debug: bool | None = None,
8990
session: ClientSession | None = None,
9091
request_timeout: int = 10,
9192
) -> None:
9293
"""Initialize the Tado object."""
94+
self._refresh_token = refresh_token
9395
self._debug: bool = debug or False
9496
self._session = session
9597
self._request_timeout = request_timeout
@@ -102,7 +104,6 @@ def __init__(
102104

103105
self._access_token: str | None = None
104106
self._token_expiry: float | None = None
105-
self._refresh_token: str | None = None
106107
self._access_headers: dict[str, str] | None = None
107108
self._home_id: int | None = None
108109
self._me: GetMe | None = None

tests/test_tado.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
TadoError,
2222
TadoReadingError,
2323
)
24+
from tadoasync.tadoasync import DeviceActivationStatus
2425

2526
from syrupy import SnapshotAssertion
2627
from tests import load_fixture
@@ -209,6 +210,10 @@ async def test_get_devices(
209210
body=load_fixture("devices.json"),
210211
)
211212
assert await python_tado.get_devices() == snapshot
213+
assert (
214+
python_tado.device_verification_url
215+
== "https://login.tado.com/oauth2/device?user_code=7BQ5ZQ"
216+
)
212217

213218

214219
async def test_get_mobile_devices(
@@ -608,3 +613,14 @@ async def response_handler(_: str, **_kwargs: Any) -> CallbackResult: # pylint:
608613
with pytest.raises(TadoConnectionError):
609614
await tado.get_devices()
610615
await tado.close()
616+
617+
618+
async def test_async_init_with_refresh_token() -> None:
619+
"""Cover where refresh token exists and _device_ready is invoked."""
620+
tado = Tado()
621+
tado._refresh_token = "existing"
622+
623+
# Ensure device_activation_status starts NOT_STARTED
624+
assert tado.device_activation_status == DeviceActivationStatus.NOT_STARTED
625+
await tado.async_init()
626+
assert tado.device_activation_status == DeviceActivationStatus.COMPLETED

0 commit comments

Comments
 (0)