Skip to content

Commit

Permalink
fix(cli): Add consumption-details commant
Browse files Browse the repository at this point in the history
  • Loading branch information
germainlefebvre4 committed Jan 27, 2025
1 parent f1e47d3 commit ef6fa8c
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 157 deletions.
20 changes: 20 additions & 0 deletions libtado/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,5 +521,25 @@ def schedule_block_day_type(tado, zone, schedule, day_type):
click.echo('')


@main.command()
@click.pass_obj
@click.option('--month-date', '-d', required=True, type=str, help='Month year (i.e. 2022-09)')
def consumption_details(tado, month_date):
"""Get the consumption details of your home."""
consumption_details = tado.get_consumption_details(month_date)

click.echo('Consumption for %s' % (month_date))
click.echo('')

click.echo('Summary:')
click.echo(' Consumption (%s): %d' % (consumption_details['summary']['unit'], consumption_details['summary']['consumption']))
click.echo(' Cost: %.2f' % (consumption_details['summary']['costInCents']/100))
click.echo('')

click.echo('Details:')
for cd in consumption_details['graphConsumption']['monthlyAggregation']['requestedMonth']['consumptionPerDate']:
click.echo(' %s\tConsumption (%s): %s\t\tCost: %.2f' % (cd['date'], consumption_details['graphConsumption']['unit'], cd['consumption'], cd['costInCents']/100))


if __name__ == "__main__":
main()
314 changes: 157 additions & 157 deletions libtado/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,7 @@ def get_consumption_details(self, monthYear, ngsw_bypass=True):
Get energy consumption details of your home by month and year
Parameters:
monthYear (str): Month and year of the range date.
monthYear (str): Month and year of the range date. e.g. "2022-09".
ngsw_bypass (bool): Bypass the ngsw cache.
Returns:
Expand All @@ -2558,162 +2558,162 @@ def get_consumption_details(self, monthYear, ngsw_bypass=True):
??? info "Result example"
```json
{
"isInPreferredUnit": true,
"summary": {
"costInCents": 12618.34,
"costForecastInCents": null,
"averageDailyCostInCents": 407.04322580645163,
"consumption": 115.449,
"consumptionForecast": null,
"averageDailyConsumption": 3.7241612903225807,
"unit": "m3",
"tariff": {
"unit": "kWh",
"unitPriceInCents": 10.36
}
},
"graphConsumption": {
"unit": "m3",
"monthlyAggregation": {
"endOfMonthForecast": null,
"requestedMonth": {
"startDate": "2024-12-01",
"endDate": "2024-12-31",
"hasDomesticHotWater": false,
"totalConsumption": 115.449,
"totalCostInCents": 12618.34,
"consumptionPerDate": [
{
"date": "2024-12-01",
"consumption": 3.721,
"costInCents": 406.7,
"hotWater": null,
"heating": 3.721,
"hasData": true
},
[...] // 29 more days
]
},
"monthBefore": {
"startDate": "2024-11-01",
"endDate": "2024-11-30",
"hasDomesticHotWater": false,
"totalConsumption": 82.69,
"totalCostInCents": 9037.85,
"consumptionPerDate": [
{
"date": "2024-11-01",
"consumption": 1.471,
"costInCents": 160.78,
"hotWater": null,
"heating": 1.471,
"hasData": true
},
[...] // 29 more days
]
},
"yearBefore": {
"startDate": "2023-12-01",
"endDate": "2023-12-31",
"hasDomesticHotWater": false,
"totalConsumption": 105.242,
"totalCostInCents": 11502.74,
"consumptionPerDate": [
{
"date": "2023-12-01",
"consumption": 7.89,
"costInCents": 862.36,
"hotWater": null,
"heating": 7.89,
"hasData": true
},
[...] // 29 more days
]
}
}
},
"consumptionComparison": {
"consumption": {
"comparedToMonthBefore": {
"percentage": 40,
"trend": "INCREASE",
"requestedMonth": "2024-12",
"comparedToMonth": "2024-11"
},
"comparedToYearBefore": {
"percentage": 10,
"trend": "INCREASE",
"requestedMonth": "2024-12",
"comparedToMonth": "2023-12"
}
},
"cost": {
"comparedToMonthBefore": {
"percentage": 40,
"trend": "INCREASE",
"requestedMonth": "2024-12",
"comparedToMonth": "2024-11"
},
"comparedToYearBefore": {
"percentage": 10,
"trend": "INCREASE",
"requestedMonth": "2024-12",
"comparedToMonth": "2023-12"
}
}
},
"heatingHotWaterSplit": null,
"roomBreakdown": {
"unit": "m3",
"requestedMonth": {
"perRoom": [
{
"id": 1,
"name": "Maison",
"consumption": 45.772999999999996,
"costInCents": 5002.9
},
...
],
"startDate": "2024-12-01",
"endDate": "2024-12-31"
},
"yearBefore": {
"perRoom": [
{
"id": 1,
"name": "Maison",
"consumption": 39.895,
"costInCents": 4360.44
},
...
],
"startDate": "2023-12-01",
"endDate": "2023-12-31"
}
},
"heatingInsights": {
"heatingHours": {
"diff": 54,
"trend": "INCREASE",
"comparedTo": "2023-12"
},
"outsideTemperature": {
"diff": 1,
"trend": "DECREASE",
"comparedTo": "2023-12"
},
"awayHours": {
"diff": 25,
"trend": "DECREASE",
"comparedTo": "2023-12"
}
},
"showAddData": true
}
```
```json
{
"isInPreferredUnit": true,
"summary": {
"costInCents": 12618.34,
"costForecastInCents": null,
"averageDailyCostInCents": 407.04322580645163,
"consumption": 115.449,
"consumptionForecast": null,
"averageDailyConsumption": 3.7241612903225807,
"unit": "m3",
"tariff": {
"unit": "kWh",
"unitPriceInCents": 10.36
}
},
"graphConsumption": {
"unit": "m3",
"monthlyAggregation": {
"endOfMonthForecast": null,
"requestedMonth": {
"startDate": "2024-12-01",
"endDate": "2024-12-31",
"hasDomesticHotWater": false,
"totalConsumption": 115.449,
"totalCostInCents": 12618.34,
"consumptionPerDate": [
{
"date": "2024-12-01",
"consumption": 3.721,
"costInCents": 406.7,
"hotWater": null,
"heating": 3.721,
"hasData": true
},
[...] // 29 more days
]
},
"monthBefore": {
"startDate": "2024-11-01",
"endDate": "2024-11-30",
"hasDomesticHotWater": false,
"totalConsumption": 82.69,
"totalCostInCents": 9037.85,
"consumptionPerDate": [
{
"date": "2024-11-01",
"consumption": 1.471,
"costInCents": 160.78,
"hotWater": null,
"heating": 1.471,
"hasData": true
},
[...] // 29 more days
]
},
"yearBefore": {
"startDate": "2023-12-01",
"endDate": "2023-12-31",
"hasDomesticHotWater": false,
"totalConsumption": 105.242,
"totalCostInCents": 11502.74,
"consumptionPerDate": [
{
"date": "2023-12-01",
"consumption": 7.89,
"costInCents": 862.36,
"hotWater": null,
"heating": 7.89,
"hasData": true
},
[...] // 29 more days
]
}
}
},
"consumptionComparison": {
"consumption": {
"comparedToMonthBefore": {
"percentage": 40,
"trend": "INCREASE",
"requestedMonth": "2024-12",
"comparedToMonth": "2024-11"
},
"comparedToYearBefore": {
"percentage": 10,
"trend": "INCREASE",
"requestedMonth": "2024-12",
"comparedToMonth": "2023-12"
}
},
"cost": {
"comparedToMonthBefore": {
"percentage": 40,
"trend": "INCREASE",
"requestedMonth": "2024-12",
"comparedToMonth": "2024-11"
},
"comparedToYearBefore": {
"percentage": 10,
"trend": "INCREASE",
"requestedMonth": "2024-12",
"comparedToMonth": "2023-12"
}
}
},
"heatingHotWaterSplit": null,
"roomBreakdown": {
"unit": "m3",
"requestedMonth": {
"perRoom": [
{
"id": 1,
"name": "Maison",
"consumption": 45.772999999999996,
"costInCents": 5002.9
},
...
],
"startDate": "2024-12-01",
"endDate": "2024-12-31"
},
"yearBefore": {
"perRoom": [
{
"id": 1,
"name": "Maison",
"consumption": 39.895,
"costInCents": 4360.44
},
...
],
"startDate": "2023-12-01",
"endDate": "2023-12-31"
}
},
"heatingInsights": {
"heatingHours": {
"diff": 54,
"trend": "INCREASE",
"comparedTo": "2023-12"
},
"outsideTemperature": {
"diff": 1,
"trend": "DECREASE",
"comparedTo": "2023-12"
},
"awayHours": {
"diff": 25,
"trend": "DECREASE",
"comparedTo": "2023-12"
}
},
"showAddData": true
}
```
"""

data = self._api_energy_insights_call('homes/%i/consumptionDetails?month=%s&ngsw-bypass=%s' % (self.id, monthYear, ngsw_bypass))
Expand Down

0 comments on commit ef6fa8c

Please sign in to comment.