Skip to content

Commit b8f6243

Browse files
authored
Allows getting statistics from Aquarea Client (#23)
* Adding models * Getting stats from client
1 parent 15e98a8 commit b8f6243

File tree

4 files changed

+122
-2
lines changed

4 files changed

+122
-2
lines changed

aioaquarea/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ClientError,
2323
RequestFailedError,
2424
)
25+
from .statistics import Consumption, DateType
2526

2627
__all__: Tuple[str, ...] = (
2728
"Client",
@@ -39,4 +40,6 @@
3940
"ExtendedOperationMode",
4041
"UpdateOperationMode",
4142
"QuietMode"
43+
"DateType",
44+
"Consumption",
4245
)

aioaquarea/const.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
AQUAREA_SERVICE_BASE = "https://aquarea-smart.panasonic.com/"
44
AQUAREA_SERVICE_LOGIN = "remote/v1/api/auth/login"
55
AQUAREA_SERVICE_DEVICES = "remote/v1/api/devices"
6+
AQUAREA_SERVICE_CONSUMPTION = "remote/v1/api/consumption"
67
AQUAREA_SERVICE_CONTRACT = "remote/contract"
78

8-
AQUAREA_SERVICE_A2W_STATUS_DISPLAY = "https://aquarea-smart.panasonic.com/remote/a2wStatusDisplay"
9+
AQUAREA_SERVICE_A2W_STATUS_DISPLAY = (
10+
"https://aquarea-smart.panasonic.com/remote/a2wStatusDisplay"
11+
)
912

1013
PANASONIC = "Panasonic"

aioaquarea/core.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import annotations
33

44
import asyncio
5-
from datetime import datetime, timezone
5+
from datetime import date, datetime, timezone
66
import functools
77
import logging
88
from typing import List, Optional
@@ -13,6 +13,7 @@
1313
from .const import (
1414
AQUAREA_SERVICE_A2W_STATUS_DISPLAY,
1515
AQUAREA_SERVICE_BASE,
16+
AQUAREA_SERVICE_CONSUMPTION,
1617
AQUAREA_SERVICE_CONTRACT,
1718
AQUAREA_SERVICE_DEVICES,
1819
AQUAREA_SERVICE_LOGIN,
@@ -35,6 +36,7 @@
3536
ZoneSensor,
3637
)
3738
from .errors import ApiError, AuthenticationError, AuthenticationErrorCodes, InvalidData
39+
from .statistics import Consumption, DateType
3840

3941

4042
def auth_required(fn):
@@ -533,6 +535,19 @@ async def post_set_quiet_mode(
533535
json=data,
534536
)
535537

538+
async def get_device_consumption(
539+
self, long_id: str, aggregation: DateType, date_input: str
540+
) -> Consumption:
541+
"""Get device consumption"""
542+
response = await self.request(
543+
"GET",
544+
f"{AQUAREA_SERVICE_CONSUMPTION}/{long_id}?{aggregation}={date_input}",
545+
referer=AQUAREA_SERVICE_A2W_STATUS_DISPLAY,
546+
)
547+
548+
date_data = await response.json()
549+
return Consumption(date_data.get("dateData")[0])
550+
536551

537552
class TankImpl(Tank):
538553
"""Tank implementation"""

aioaquarea/statistics.py

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""Statistics models for Aquarea"""
2+
from __future__ import annotations
3+
4+
from dataclasses import dataclass
5+
6+
try:
7+
from enum import StrEnum
8+
except ImportError:
9+
from strenum import StrEnum
10+
11+
12+
class DateType(StrEnum):
13+
"""Date types"""
14+
15+
DAY = "date"
16+
WEEK = "week"
17+
MONTH = "month"
18+
YEAR = "year"
19+
20+
21+
class AggregationType(StrEnum):
22+
"""Aggregation type"""
23+
24+
HOURLY = "hourly"
25+
DAILY = "daily"
26+
MONTHLY = "monthly"
27+
28+
29+
class DataType(StrEnum):
30+
"""Data type"""
31+
32+
HEAT = "Heat"
33+
COOL = "AC"
34+
WATER_TANK = "HW"
35+
TOTAL = "Consume"
36+
37+
38+
class GenerationDataType(StrEnum):
39+
"""Generation data type"""
40+
41+
GHT = "GHT"
42+
GHR = "GHR"
43+
GHW = "GHW"
44+
45+
46+
class DataSetName(StrEnum):
47+
"""Data set name"""
48+
49+
ENERGY = "energyShowing"
50+
GENERATED = "generateEnergyShowing"
51+
COST = "costShowing"
52+
TEMPERATURE = "temperatureShowing"
53+
54+
55+
class Consumption:
56+
"""Consumption"""
57+
58+
def __init__(self, date_data: dict[str, object]):
59+
self._data = dict(
60+
[
61+
(
62+
dataset.get("name"),
63+
dict(
64+
[
65+
(data.get("name"), data.get("values"))
66+
for data in dataset.get("data", [])
67+
]
68+
),
69+
)
70+
for dataset in date_data.get("dataSets", [])
71+
]
72+
)
73+
self._start_date = date_data.get("startDate")
74+
self._aggregation = AggregationType(date_data.get("timeline", {}).get("type"))
75+
76+
@property
77+
def energy(self) -> dict[DataType, list[float | None]]:
78+
"""Energy consumption in kWh"""
79+
return self._data.get(DataSetName.ENERGY)
80+
81+
@property
82+
def generation(self) -> dict[GenerationDataType, list[float]]:
83+
"""Energy generation in kWh"""
84+
return self._data.get(DataSetName.GENERATED)
85+
86+
@property
87+
def cost(self) -> dict[DataType, list[float]]:
88+
"""Energy cost in configured currency"""
89+
return self._data.get(DataSetName.COST)
90+
91+
@property
92+
def start_date(self) -> str:
93+
"""Start date of the period"""
94+
return self._start_date
95+
96+
@property
97+
def aggregation(self) -> AggregationType:
98+
"""Aggregation type"""
99+
return self._aggregation

0 commit comments

Comments
 (0)