Skip to content

Commit

Permalink
Adjust user_procies query to match updated API (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
DCSBL authored Feb 25, 2024
1 parent 3be1374 commit 88d9f88
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
42 changes: 36 additions & 6 deletions python_frank_energie/frank_energie.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,45 @@ async def prices(

return MarketPrices.from_dict(await self._query(query_data))

async def user_prices(self, start_date: date) -> MarketPrices:
"""Get customer market prices."""
async def user_prices(self, start_date: date, site_reference: str) -> MarketPrices:
"""Get customer market prices.
Full query:
query MarketPrices($date: String!, $siteReference: String!) {
customerMarketPrices(date: $date, siteReference: $siteReference) {
id
electricityPrices {
id
from
till
date
marketPrice
marketPriceTax
consumptionSourcingMarkupPrice
energyTax
perUnit
}
gasPrices {
id
from
till
date
marketPrice
marketPriceTax
consumptionSourcingMarkupPrice
energyTax
perUnit
}
}
}
"""
if self._auth is None:
raise AuthRequiredException

query_data = {
"query": """
query CustomerMarketPrices($date: String!) {
customerMarketPrices(date: $date) {
query MarketPrices($date: String!, $siteReference: String!) {
customerMarketPrices(date: $date, siteReference: $siteReference) {
electricityPrices {
from
till
Expand All @@ -446,8 +476,8 @@ async def user_prices(self, start_date: date) -> MarketPrices:
}
}
""",
"variables": {"date": str(start_date)},
"operationName": "CustomerMarketPrices",
"variables": {"date": str(start_date), "siteReference": site_reference},
"operationName": "MarketPrices",
}

return MarketPrices.from_userprices_dict(await self._query(query_data))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_frank_energie.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ async def test_user_prices(aresponses):

async with aiohttp.ClientSession() as session:
api = FrankEnergie(session, auth_token="a", refresh_token="b") # noqa: S106
prices = await api.user_prices(datetime.utcnow().date())
prices = await api.user_prices(datetime.utcnow().date(), "1234AB 10")
await api.close()

assert prices.electricity is not None
Expand Down

0 comments on commit 88d9f88

Please sign in to comment.