Skip to content

Commit

Permalink
feat(api): Get Energy Insights
Browse files Browse the repository at this point in the history
  • Loading branch information
germainlefebvre4 committed Oct 13, 2023
1 parent 19e2a17 commit 88ac07b
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
1 change: 1 addition & 0 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
# print(tado.get_energy_savings("2022-09", "FRA"))
# print(tado.get_consumption_overview("2023-09", "FRA", True))
# print(tado.get_enery_settings())
# print(tado.get_energy_insights("2023-09-01", "2023-09-30", "FRA", True))
131 changes: 131 additions & 0 deletions libtado/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,3 +1775,134 @@ def get_enery_settings(self, ngsw_bypass=True):

data = self._api_energy_insights_call('homes/%i/settings?ngsw-bypass=%s' % (self.id, ngsw_bypass))
return data

def get_energy_insights(self, start_date, end_date, country, ngsw_bypass=True):
"""
Get energy insights of your home
Returns:
Energy insights.
Example:
```json
{
"consumptionComparison": {
"currentMonth": {
"consumed": {
"energy": [
{
"toEndOfRange": 1.5,
"unit": "m3",
"perZone": [
{
"zone": 1,
"toEndOfRange": 0.6025913295286759
}
]
},
{
"toEndOfRange": 15.83,
"unit": "kWh",
"perZone": [
{
"zone": 1,
"toEndOfRange": 6.36
}
]
}
]
},
"dateRange": {
"start": "2023-10-01",
"end": "2023-10-13"
}
},
"comparedTo": {
"consumed": {
"energy": [
{
"toEndOfRange": 16.9,
"unit": "m3",
"perZone": [
{
"zone": 1,
"toEndOfRange": 6.098444101091741
}
]
},
{
"toEndOfRange": 178.3,
"unit": "kWh",
"perZone": [
{
"zone": 1,
"toEndOfRange": 64.34
}
]
}
]
},
"dateRange": {
"start": "2022-10-01",
"end": "2022-10-13"
}
}
},
"costForecast": {
"costEndOfMonthInCents": 417.5
},
"weatherComparison": {
"currentMonth": {
"averageTemperature": 17.2,
"dateRange": {
"start": "2023-10-01",
"end": "2023-10-13"
}
},
"comparedTo": {
"averageTemperature": 12.7,
"dateRange": {
"start": "2022-10-01",
"end": "2022-10-13"
}
}
},
"heatingTimeComparison": {
"currentMonth": {
"heatingTimeHours": 13,
"dateRange": {
"start": "2023-10-01",
"end": "2023-10-14"
}
},
"comparedTo": {
"heatingTimeHours": 155,
"dateRange": {
"start": "2022-10-01",
"end": "2022-10-14"
}
}
},
"awayTimeComparison": {
"currentMonth": {
"awayTimeInHours": 39,
"dateRange": {
"start": "2023-10-01",
"end": "2023-10-13"
}
},
"comparedTo": {
"awayTimeInHours": 74,
"dateRange": {
"start": "2022-10-01",
"end": "2022-10-13"
}
}
},
"heatingHotwaterComparison": null
}
```
"""

data = self._api_energy_insights_call('homes/%i/insights?startDate=%s&endDate=%s&country=%s&ngsw-bypass=%s' % (self.id, start_date, end_date, country, ngsw_bypass))
return data
53 changes: 53 additions & 0 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,56 @@ def test_get_enery_settings(self):
assert isinstance(response, dict)
KEYS = ["consumptionUnit", "dataSource", "homeId", "preferredEnergyUnit", "showReadingsBanner"]
assert all(name in response for name in KEYS)

def test_get_energy_insights(self):
start_date = "2023-09-01"
end_date = "2023-09-30"
country = "FRA"
response = tado.get_energy_insights(start_date=start_date, end_date=end_date, country=country)

assert isinstance(response, dict)
KEYS = ["awayTimeComparison", "consumptionComparison", "costForecast", "heatingHotwaterComparison", "heatingTimeComparison", "weatherComparison"]
assert all(name in response for name in KEYS)

KEYS = ["comparedTo", "currentMonth"]
assert all(name in response["awayTimeComparison"] for name in KEYS)
assert all(name in response["consumptionComparison"] for name in KEYS)
assert all(name in response["heatingTimeComparison"] for name in KEYS)
assert all(name in response["weatherComparison"] for name in KEYS)

KEYS = ["awayTimeInHours", "dateRange"]
assert all(name in response["awayTimeComparison"]["comparedTo"] for name in KEYS)
KEYS = ["consumed", "dateRange"]
assert all(name in response["consumptionComparison"]["comparedTo"] for name in KEYS)
KEYS = ["heatingTimeHours", "dateRange"]
assert all(name in response["heatingTimeComparison"]["comparedTo"] for name in KEYS)
KEYS = ["averageTemperature", "dateRange"]
assert all(name in response["weatherComparison"]["comparedTo"] for name in KEYS)

KEYS = ["start", "end"]
assert all(name in response["awayTimeComparison"]["comparedTo"]["dateRange"] for name in KEYS)
assert all(name in response["consumptionComparison"]["comparedTo"]["dateRange"] for name in KEYS)
assert all(name in response["heatingTimeComparison"]["comparedTo"]["dateRange"] for name in KEYS)
assert all(name in response["weatherComparison"]["comparedTo"]["dateRange"] for name in KEYS)


KEYS = ["awayTimeInHours", "dateRange"]
assert all(name in response["awayTimeComparison"]["currentMonth"] for name in KEYS)
KEYS = ["consumed", "dateRange"]
assert all(name in response["consumptionComparison"]["currentMonth"] for name in KEYS)
KEYS = ["heatingTimeHours", "dateRange"]
assert all(name in response["heatingTimeComparison"]["currentMonth"] for name in KEYS)
KEYS = ["averageTemperature", "dateRange"]
assert all(name in response["weatherComparison"]["currentMonth"] for name in KEYS)

KEYS = ["energy"]
assert all(name in response["consumptionComparison"]["comparedTo"]["consumed"] for name in KEYS)
if len(response["consumptionComparison"]["comparedTo"]["consumed"]["energy"]) > 0:
KEYS = ["perZone", "toEndOfRange", "unit"]
assert all(name in response["consumptionComparison"]["comparedTo"]["consumed"]["energy"][0] for name in KEYS)
if len(response["consumptionComparison"]["comparedTo"]["consumed"]["energy"][0]["perZone"]) > 0:
KEYS = ["toEndOfRange", "zone"]
assert all(name in response["consumptionComparison"]["comparedTo"]["consumed"]["energy"][0]["perZone"][0] for name in KEYS)

KEYS = ["costEndOfMonthInCents"]
assert all(name in response["costForecast"] for name in KEYS)

0 comments on commit 88ac07b

Please sign in to comment.