Skip to content

Commit

Permalink
Add aggr data v2 call (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
drc38 authored Feb 17, 2023
1 parent e2ad3cd commit 0845e8c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/fronius_sw_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ async def main():
flow_data = await fronius.get_system_flow_data()
print(f"{flow_data}\n")

print("Getting aggregated V2 data:")
aggr_data = await fronius.get_system_aggr_data_v2()
print(f"{aggr_data}\n")


if __name__ == "__main__":
asyncio.run(main())
18 changes: 17 additions & 1 deletion fronius_solarweb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

from .errors import NotAuthorizedException, NotFoundException

from .schema.pvsystem import PvSystemMetaData, PvSystemsMetaData, PvSystemFlowData
from .schema.pvsystem import (
PvSystemMetaData,
PvSystemsMetaData,
PvSystemFlowData,
PvSystemAggrDataV2,
)
from .schema.device import DeviceMetaData, DevicesMetaData
from .schema.service import ReleaseInfo

Expand Down Expand Up @@ -146,3 +151,14 @@ async def get_system_flow_data(self, tz: str = "zulu") -> PvSystemFlowData:
)
json_data = await self._check_api_response(r)
return PvSystemFlowData(**json_data)

async def get_system_aggr_data_v2(
self, period: str = "total"
) -> PvSystemAggrDataV2:
_LOGGER.debug("Listing PV system aggregated v2 data")
r = await self.httpx_client.get(
f"{SW_BASE_URL}/pvsystems/{self.pv_system_id}/aggrdata?period={period}",
headers=self._common_headers,
)
json_data = await self._check_api_response(r)
return PvSystemAggrDataV2(**json_data)
11 changes: 11 additions & 0 deletions fronius_solarweb/schema/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Data(BaseModel):
channels: Optional[list[Channel]]


class AggrData(BaseModel):
logDateTime: Optional[str]
channels: Optional[list[Channel]]


class Status(BaseModel):
isOnline: bool
battMode: Optional[str]
Expand Down Expand Up @@ -54,3 +59,9 @@ class PvSystemFlowData(BaseModel):
pvSystemId: str
status: Optional[Status]
data: Optional[Data]


class PvSystemAggrDataV2(BaseModel):
pvSystemId: str
data: Optional[list[AggrData]]
links: Optional[Links]

0 comments on commit 0845e8c

Please sign in to comment.