diff --git a/check.py b/check.py index 87e4d71..d909084 100644 --- a/check.py +++ b/check.py @@ -19,3 +19,4 @@ # print(tado.get_mobile_devices()) # print(tado.get_energy_consumption("2022-09-01", "2022-09-30", "FRA", True)) # print(tado.get_energy_savings("2022-09", "FRA")) +# print(tado.get_consumption_overview("2023-09", "FRA", True)) diff --git a/libtado/api.py b/libtado/api.py index f40871d..018aeca 100644 --- a/libtado/api.py +++ b/libtado/api.py @@ -1637,3 +1637,119 @@ def set_cost_simulation(self, country, ngsw_bypass=True, payload=None): data = self._api_energy_insights_call('homes/%i/costSimulator?country=%s&ngsw-bypass=%s' % (self.id, country, ngsw_bypass), data=payload, method='POST') return data + + def get_consumption_overview(self, monthYear, country, ngsw_bypass=True): + """ + Get energy consumption overview of your home by month and year + + Returns: + consumptionInputState: Consumption input state + currency: Currency + customTariff: Custom tariff + energySavingsReport: Energy savings report + monthlyAggregation: Monthly aggregation + tariffInfo: Tariffication information + unit: Measurement unit + + Example: + ```json + { + "currency": "EUR", + "tariff": "0.104 €/kWh", + "tariffInfo": { + "currencySign": "€", + "consumptionUnit": "kWh", + "tariffInCents": 10.36, + "customTariff": false + }, + "customTariff": false, + "consumptionInputState": "full", + "unit": "m3", + "energySavingsReport": { + "totalSavingsInPercent": 4.7, + "yearMonth": "2023-09" + }, + "monthlyAggregation": { + "endOfMonthForecast": { + "startDate": "2023-10-13", + "endDate": "2023-10-31", + "totalConsumption": 3.82, + "totalCostInCents": 417.52, + "consumptionPerDate": [ + { + "date": "2023-10-14", + "consumption": 0.2122222222222222, + "costInCents": 23.2 + }, + [...] // 17 more days + { + "date": "2023-10-31", + "consumption": 0.2122222222222222, + "costInCents": 23.2 + } + ] + }, + "requestedMonth": { + "startDate": "2023-10-01", + "endDate": "2023-10-13", + "totalConsumption": 1.5, + "totalCostInCents": 163.95, + "consumptionPerDate": [ + { + "date": "2023-10-01", + "consumption": 0, + "costInCents": 0 + }, + [...] // 12 more days + { + "date": "2023-10-13", + "consumption": 0, + "costInCents": 0 + } + ] + }, + "monthBefore": { + "startDate": "2023-09-01", + "endDate": "2023-09-30", + "totalConsumption": 1.2799999999999998, + "totalCostInCents": 139.9, + "consumptionPerDate": [ + { + "date": "2023-09-01", + "consumption": 0, + "costInCents": 0 + }, + [...] // 29 more days + { + "date": "2023-09-30", + "consumption": 0.36, + "costInCents": 39.35 + } + ] + }, + "yearBefore": { + "startDate": "2022-10-01", + "endDate": "2022-10-31", + "totalConsumption": 22.569999999999997, + "totalCostInCents": 2466.86, + "consumptionPerDate": [ + { + "date": "2022-10-01", + "consumption": 0.67, + "costInCents": 73.23 + }, + [...] // 30 more days + { + "date": "2022-10-31", + "consumption": 0.65, + "costInCents": 71.04 + } + ] + } + } + } + ``` + """ + + data = self._api_energy_insights_call('homes/%i/consumptionOverview?month=%s&country=%s&ngsw-bypass=%s' % (self.id, monthYear, country, ngsw_bypass)) + return data diff --git a/tests/api/test_api.py b/tests/api/test_api.py index 55a111f..249017c 100644 --- a/tests/api/test_api.py +++ b/tests/api/test_api.py @@ -406,3 +406,28 @@ def test_set_cost_simulation(self): if len(response["estimationPerZone"]) > 0: KEYS = ["zone", "consumption", "costInCents"] assert all(name in response["estimationPerZone"][0] for name in KEYS) + + def test_get_consumption_overview(self): + monthYear = "2023-09" + country = "FRA" + response = tado.get_consumption_overview(monthYear=monthYear, country=country) + + assert isinstance(response, dict) + KEYS = ["consumptionInputState", "currency", "customTariff", "energySavingsReport", "monthlyAggregation", "tariff", "tariffInfo", "unit"] + assert all(name in response for name in KEYS) + + KEYS = ["totalSavingsInPercent", "yearMonth"] + assert all(name in response["energySavingsReport"] for name in KEYS) + + KEYS = ["endOfMonthForecast"] + assert all(name in response["monthlyAggregation"] for name in KEYS) + + # KEYS = ["consumptionPerDate", "endDate", "startDate", "totalConsumption", "totalCostInCents"] + # assert all(name in response["monthlyAggregation"]["endOfMonthForecast"] for name in KEYS) + + # if len(response["monthlyAggregation"]["endOfMonthForecast"]["consumptionPerDate"]) > 0: + # KEYS = ["consumption", "costInCents", "date"] + # assert all(name in response["monthlyAggregation"]["endOfMonthForecast"]["consumptionPerDate"][0] for name in KEYS) + + KEYS = ["consumptionUnit", "currencySign", "customTariff", "tariffInCents"] + assert all(name in response["tariffInfo"] for name in KEYS)