From fe87e93e24d43c27eee4ebd79dc75cad10382331 Mon Sep 17 00:00:00 2001 From: lin-hongkuan <234943746+lin-hongkuan@users.noreply.github.com> Date: Thu, 25 Jun 2026 06:18:11 +0800 Subject: [PATCH] Support homeId in me response --- PyTado/http.py | 9 +++++++-- tests/test_http.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/PyTado/http.py b/PyTado/http.py index bd8650d..7f64da5 100644 --- a/PyTado/http.py +++ b/PyTado/http.py @@ -648,9 +648,14 @@ def _get_id(self) -> int: if not isinstance(response, dict): raise TadoException("Unexpected response type") - homes_ = response["homes"] + homes_ = response.get("homes") + if isinstance(homes_, list) and homes_: + return int(homes_[0]["id"]) - return int(homes_[0]["id"]) + if home_id := response.get("homeId"): + return int(home_id) + + raise TadoException("No home id found in response") def _check_x_line_generation(self) -> bool: # get home info diff --git a/tests/test_http.py b/tests/test_http.py index c0fbda6..b83d8c3 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -73,6 +73,22 @@ def test_login_successful(self): self.assertEqual(instance._id, 1234) self.assertEqual(instance.is_x_line, False) + @responses.activate + def test_login_successful_with_home_id_response(self): + """Test that login accepts a me response with homeId.""" + responses.replace( + responses.GET, + "https://my.tado.com/api/v2/me", + json={"homeId": 1234}, + status=200, + ) + + instance = Http(debug=True) + instance.device_activation() + + self.assertEqual(instance._id, 1234) + self.assertEqual(instance.is_x_line, False) + @responses.activate def test_login_failed(self): """Test that login fails with appropriate exceptions."""