301301}}'''
302302
303303wheel_of_fortune_query = '''query {{
304- wheelOfFortuneSpins(accountNumber: "{account_id}") {{
305- electricity {{
306- remainingSpinsThisMonth
307- }}
308- gas {{
309- remainingSpinsThisMonth
310- }}
304+ electricity: wheelOfFortuneSpinsAllowed(fuelType:ELECTRICITY, accountNumber: "{account_id}") {{
305+ spinsAllowed
306+ }}
307+ gas: wheelOfFortuneSpinsAllowed(fuelType:GAS, accountNumber: "{account_id}") {{
308+ spinsAllowed
311309 }}
312310}}'''
313311
314312wheel_of_fortune_mutation = '''mutation {{
315- spinWheelOfFortune(input: {{ accountNumber: "{account_id}", supplyType : {supply_type}, termsAccepted: true }}) {{
316- spinResult {{
317- prizeAmount
313+ spinWheelOfFortune(input: {{ accountNumber: "{account_id}", fuelType : {fuel_type} }}) {{
314+ prize {{
315+ value
318316 }}
319317 }}
320318}}'''
@@ -643,6 +641,7 @@ def __init__(self, api_key, electricity_price_cap = None, gas_price_cap = None,
643641
644642 self ._api_key = api_key
645643 self ._base_url = 'https://api.octopus.energy'
644+ self ._backend_base_url = 'https://api.backend.octopus.energy'
646645
647646 self ._graphql_token = None
648647 self ._graphql_expiration = None
@@ -1752,20 +1751,21 @@ async def async_get_wheel_of_fortune_spins(self, account_id: str) -> WheelOfFort
17521751 try :
17531752 request_context = "wheel-of-fortune"
17541753 client = self ._create_client_session ()
1755- url = f'{ self ._base_url } /v1/graphql/'
1754+ url = f'{ self ._backend_base_url } /v1/graphql/'
17561755 payload = { "query" : wheel_of_fortune_query .format (account_id = account_id ) }
1757- headers = { "Authorization" : f"JWT { self ._graphql_token } " , integration_context_header : request_context }
1756+ headers = { "Authorization" : f"{ self ._graphql_token } " , integration_context_header : request_context }
17581757 async with client .post (url , json = payload , headers = headers ) as response :
17591758 response_body = await self .__async_read_response__ (response , url )
17601759 _LOGGER .debug (f'async_get_wheel_of_fortune_spins: { response_body } ' )
17611760
17621761 if (response_body is not None and "data" in response_body and
1763- "wheelOfFortuneSpins" in response_body ["data" ]):
1762+ "electricity" in response_body ["data" ] and
1763+ "gas" in response_body ["data" ]):
17641764
1765- spins = response_body ["data" ][ "wheelOfFortuneSpins" ]
1765+ spins = response_body ["data" ]
17661766 return WheelOfFortuneSpinsResponse (
1767- int (spins ["electricity" ]["remainingSpinsThisMonth " ]) if "electricity" in spins and "remainingSpinsThisMonth " in spins ["electricity" ] else 0 ,
1768- int (spins ["gas" ]["remainingSpinsThisMonth " ]) if "gas" in spins and "remainingSpinsThisMonth " in spins ["gas" ] else 0
1767+ int (spins ["electricity" ]["spinsAllowed " ]) if "electricity" in spins and "spinsAllowed " in spins ["electricity" ] else 0 ,
1768+ int (spins ["gas" ]["spinsAllowed " ]) if "gas" in spins and "spinsAllowed " in spins ["gas" ] else 0
17691769 )
17701770 else :
17711771 _LOGGER .error ("Failed to retrieve wheel of fortune spins" )
@@ -1783,20 +1783,20 @@ async def async_spin_wheel_of_fortune(self, account_id: str, is_electricity: boo
17831783 try :
17841784 request_context = "spin-wheel-of-fortune"
17851785 client = self ._create_client_session ()
1786- url = f'{ self ._base_url } /v1/graphql/'
1787- payload = { "query" : wheel_of_fortune_mutation .format (account_id = account_id , supply_type = "ELECTRICITY" if is_electricity == True else "GAS" ) }
1788- headers = { "Authorization" : f"JWT { self ._graphql_token } " , integration_context_header : request_context }
1786+ url = f'{ self ._backend_base_url } /v1/graphql/'
1787+ payload = { "query" : wheel_of_fortune_mutation .format (account_id = account_id , fuel_type = "ELECTRICITY" if is_electricity == True else "GAS" ) }
1788+ headers = { "Authorization" : f"{ self ._graphql_token } " , integration_context_header : request_context }
17891789 async with client .post (url , json = payload , headers = headers ) as response :
17901790 response_body = await self .__async_read_response__ (response , url )
17911791 _LOGGER .debug (f'async_spin_wheel_of_fortune: { response_body } ' )
17921792
17931793 if (response_body is not None and
17941794 "data" in response_body and
17951795 "spinWheelOfFortune" in response_body ["data" ] and
1796- "spinResult " in response_body ["data" ]["spinWheelOfFortune" ] and
1797- "prizeAmount " in response_body ["data" ]["spinWheelOfFortune" ]["spinResult " ]):
1796+ "prize " in response_body ["data" ]["spinWheelOfFortune" ] and
1797+ "value " in response_body ["data" ]["spinWheelOfFortune" ]["prize " ]):
17981798
1799- return int (response_body ["data" ]["spinWheelOfFortune" ]["spinResult " ]["prizeAmount " ])
1799+ return int (response_body ["data" ]["spinWheelOfFortune" ]["prize " ]["value " ])
18001800 else :
18011801 _LOGGER .error ("Failed to spin wheel of fortune" )
18021802
0 commit comments