Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions PyTado/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading