44import asyncio
55import socket
66import logging
7- import json
87from datetime import timedelta
98
109import aiohttp
@@ -82,12 +81,10 @@ def __init__(
8281 async def async_request_token (self ) -> any :
8382 """Obtain access token with clientId and secret."""
8483
85- params = {"clientId" : self ._client_id , "clientSecret" : self ._client_secret }
86-
8784 response_json = await self ._api_wrapper (
8885 path = "auth/token" ,
8986 method = "post" ,
90- data = params ,
87+ data = { "clientId" : self . _client_id , "clientSecret" : self . _client_secret } ,
9188 )
9289
9390 return response_json
@@ -136,28 +133,32 @@ async def async_start_charge(self, charge_point_id: int) -> any:
136133 """Start a charge."""
137134 access_token = await self .async_get_access_token ()
138135
136+ _LOGGER .debug ("Trying to start a charge on: %s" , charge_point_id )
137+
139138 response = await self ._api_wrapper (
140139 method = "post" ,
141140 path = "charges" ,
142141 headers = {"authorization" : f"Bearer { access_token } " },
143142 data = {"chargePointId" : charge_point_id },
144143 )
145144
146- _LOGGER .debug ("Started a charge: %s" , json . dumps ( response ) )
145+ _LOGGER .debug ("Started a charge on : %s" , charge_point_id )
147146
148147 return response
149148
150149 async def async_stop_charge (self , charge_id : int ) -> any :
151150 """Start a charge."""
152151 access_token = await self .async_get_access_token ()
153152
153+ _LOGGER .debug ("Trying to stop a charge with id: %s" , charge_id )
154+
154155 response = await self ._api_wrapper (
155156 method = "post" ,
156157 path = f"charges/{ charge_id } /stop" ,
157158 headers = {"authorization" : f"Bearer { access_token } " },
158159 )
159160
160- _LOGGER .debug ("Stopped charge: %s" , json . dumps ( response ) )
161+ _LOGGER .debug ("Stopped charge for chargeId : %s <%s> " , charge_id , response )
161162
162163 return response
163164
@@ -168,15 +169,12 @@ async def async_get_access_token(self) -> str:
168169 await self .async_load_preferences ()
169170
170171 if self ._is_access_token_valid ():
171- _LOGGER .debug ("Token still valid, using it" )
172+ _LOGGER .debug ("Access Token still valid, using it" )
172173 return self ._prefs [STORAGE_ACCESS_TOKEN ]
173174
174175 if self ._is_refresh_token_valid ():
176+ _LOGGER .debug ("Refresh Token still valid, using it" )
175177 params = {"refreshToken" : self ._prefs [STORAGE_REFRESH_TOKEN ]}
176- _LOGGER .debug (
177- "Requesting access token with: %s" ,
178- json .dumps (params ),
179- )
180178
181179 response_json = await self ._api_wrapper (
182180 path = "auth/refresh" ,
@@ -193,6 +191,7 @@ async def async_get_access_token(self) -> str:
193191
194192 return response_json ["accessToken" ]
195193
194+ _LOGGER .debug ("No token is valid, Requesting a new tokens" )
196195 return await self .async_authenticate ()
197196
198197 def _filter_private_information (self , data ):
@@ -309,7 +308,6 @@ def _is_access_token_valid(self):
309308 if isinstance (expire_time , str ):
310309 expire_time = dt_util .parse_datetime (self ._prefs [STORAGE_ACCESS_EXPIRE_TIME ])
311310
312-
313311 preemptive_expire_time = expire_time - timedelta (
314312 seconds = PREEMPTIVE_REFRESH_TTL_IN_SECONDS
315313 )
0 commit comments