Skip to content

Commit

Permalink
#67 set value issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuen Lee committed Sep 13, 2023
1 parent 962ec9c commit d97551b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions custom_components/alfen_wallbox/alfen.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,24 @@ async def logout(self):
_LOGGER.error("Unexpected error on LOGOUT %s", str(e))
return None

async def _update_value(self, api_param, value) -> ClientResponse | None:
async def _update_value(self, api_param, value, allowed_login=True) -> ClientResponse | None:
try:
self.wait = True
response = await self._post(cmd=PROP, payload={api_param: {
ID: api_param, VALUE: str(value)}})
resp = await response.json(content_type=None)
_LOGGER.debug(f"Set {api_param} value {value} response {resp}")
self.wait = False
return resp
async with self._session.post(
url=self.__get_url(PROP),
json={api_param: {ID: api_param, VALUE: str(value)}},
headers=POST_HEADER_JSON,
timeout=TIMEOUT,
ssl=self.ssl) as response:
if response.status == 401 and allowed_login:
_LOGGER.debug("POST(Update) with login")
await self.login()
return await self._update_value(api_param, value, False)
self.wait = False
return response
except Exception as e: # pylint: disable=broad-except
_LOGGER.error("Unexpected error on UPDATE VALUE %s", str(e))
self.wait = False
return None

async def _get_value(self, api_param):
Expand Down

0 comments on commit d97551b

Please sign in to comment.