Skip to content

Commit

Permalink
Merge pull request #107 from wmalgadey/minder-api-support
Browse files Browse the repository at this point in the history
adding the minder api from PR !64
  • Loading branch information
wmalgadey authored Dec 20, 2024
2 parents f5fd83f + 321be9d commit 069d422
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
8 changes: 8 additions & 0 deletions PyTado/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pprint
from datetime import datetime, timedelta
from typing import Any
from urllib.parse import urlencode

import requests

Expand All @@ -27,6 +28,7 @@ class Endpoint(enum.StrEnum):
EIQ = "https://energy-insights.tado.com/api/"
TARIFF = "https://tariff-experience.tado.com/api/"
GENIE = "https://genie.tado.com/api/v2/"
MINDER = "https://minder.tado.com/v1/"


class Domain(enum.StrEnum):
Expand Down Expand Up @@ -65,6 +67,7 @@ def __init__(
domain: Domain = Domain.HOME,
device: int | None = None,
mode: Mode = Mode.OBJECT,
params: dict[str, Any] | None = None,
):
self.endpoint = endpoint
self.command = command
Expand All @@ -73,6 +76,7 @@ def __init__(
self.domain = domain
self.device = device
self.mode = mode
self.params = params


class TadoXRequest(TadoRequest):
Expand All @@ -87,6 +91,7 @@ def __init__(
domain: Domain = Domain.HOME,
device: int | None = None,
mode: Mode = Mode.OBJECT,
params: dict[str, Any] | None = None,
):
super().__init__(
endpoint=endpoint,
Expand All @@ -96,6 +101,7 @@ def __init__(
domain=domain,
device=device,
mode=mode,
params=params,
)
self._action = action

Expand Down Expand Up @@ -214,6 +220,8 @@ def _configure_url(self, request: TadoRequest) -> str:
url = f"{request.endpoint}{request.domain}/{request.device}/{request.command}"
elif request.domain == Domain.ME:
url = f"{request.endpoint}{request.domain}"
elif request.endpoint == Endpoint.MINDER:
url = f"{request.endpoint}{request.domain}/{self.id:d}/{request.command}?{urlencode(request.params)}"
else:
url = f"{request.endpoint}{request.domain}/{self._id:d}/{request.command}"
return url
Expand Down
15 changes: 15 additions & 0 deletions PyTado/interface/api/my_tado.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,18 @@ def set_zone_heating_circuit(self, zone, heating_circuit):
request.payload = {"circuitNumber": heating_circuit}

return self._http.request(request)

def get_running_times(
self, date=datetime.datetime.now().strftime("%Y-%m-%d")
) -> dict:
"""
Get the running times from the Minder API
"""

request = TadoRequest()
request.command = "runningTimes"
request.action = Action.GET
request.endpoint = Endpoint.MINDER
request.params = {"from": date}

return self._http.request(request)
80 changes: 80 additions & 0 deletions tests/fixtures/running_times.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"lastUpdated": "2023-08-05T19:50:21Z",
"runningTimes": [
{
"endTime": "2023-08-02 00:00:00",
"runningTimeInSeconds": 0,
"startTime": "2023-08-01 00:00:00",
"zones": [
{
"id": 1,
"runningTimeInSeconds": 1
},
{
"id": 2,
"runningTimeInSeconds": 2
},
{
"id": 3,
"runningTimeInSeconds": 3
},
{
"id": 4,
"runningTimeInSeconds": 4
}
]
},
{
"endTime": "2023-08-03 00:00:00",
"runningTimeInSeconds": 0,
"startTime": "2023-08-02 00:00:00",
"zones": [
{
"id": 1,
"runningTimeInSeconds": 5
},
{
"id": 2,
"runningTimeInSeconds": 6
},
{
"id": 3,
"runningTimeInSeconds": 7
},
{
"id": 4,
"runningTimeInSeconds": 8
}
]
},
{
"endTime": "2023-08-04 00:00:00",
"runningTimeInSeconds": 0,
"startTime": "2023-08-03 00:00:00",
"zones": [
{
"id": 1,
"runningTimeInSeconds": 9
},
{
"id": 2,
"runningTimeInSeconds": 10
},
{
"id": 3,
"runningTimeInSeconds": 11
},
{
"id": 4,
"runningTimeInSeconds": 12
}
]
}
],
"summary": {
"endTime": "2023-08-06 00:00:00",
"meanInSecondsPerDay": 24,
"startTime": "2023-08-01 00:00:00",
"totalRunningTimeInSeconds": 120
}
}
13 changes: 13 additions & 0 deletions tests/test_my_tado.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,16 @@ def test_home_cant_be_set_to_auto_when_home_does_not_support_geofencing(
with mock.patch("PyTado.http.Http.request"):
with self.assertRaises(Exception):
self.tado_client.set_auto()

def test_get_running_times(self):
"""Test the get_running_times method."""

with mock.patch(
"PyTado.http.Http.request",
return_value=json.loads(common.load_fixture("running_times.json")),
):
running_times = self.tado_client.get_running_times("2023-08-01")

assert self.tado_client._http.request.called
assert running_times["lastUpdated"] == "2023-08-05T19:50:21Z"
assert running_times["runningTimes"][0]["zones"][0]["id"] == 1

0 comments on commit 069d422

Please sign in to comment.