Skip to content

Commit

Permalink
handle _app_wallbox_num_max after login caused by requests
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 committed Jan 2, 2024
1 parent 5b5adb9 commit 97cfdf1
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions custom_components/senec/pysenec_ha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,11 @@ async def app_get_wallbox_data(self, wallbox_num: int = 1, retry: bool = True):
else:
if retry:
await self.app_authenticate()
await self.app_get_wallbox_data(wallbox_num=wallbox_num, retry=False)
if self._app_wallbox_num_max >= wallbox_num:
await self.app_get_wallbox_data(wallbox_num=wallbox_num, retry=False)
else:
_LOGGER.debug(
f"APP-API cancel 'app_get_wallbox_data' since after login the max '{self._app_wallbox_num_max}' is < then '{wallbox_num}' (wallbox number to request)")

async def app_update_wallboxes(self):
_LOGGER.debug(f"APP-API app_update_wallboxes for '{self._app_wallbox_num_max}' wallboxes")
Expand All @@ -2525,25 +2529,25 @@ async def app_update_wallboxes(self):
# this wallbox again...
if self._app_wallbox_num_max > 0:
await self.app_get_wallbox_data(wallbox_num=1)
if self._app_raw_wallbox[0] is None:
if self._app_raw_wallbox[0] is None and self._app_wallbox_num_max > 0:
_LOGGER.debug("APP-API set _app_wallbox_num_max to 0")
self._app_wallbox_num_max = 0

if self._app_wallbox_num_max > 1:
await self.app_get_wallbox_data(wallbox_num=2)
if self._app_raw_wallbox[1] is None:
if self._app_raw_wallbox[1] is None and self._app_wallbox_num_max > 1:
_LOGGER.debug("APP-API set _app_wallbox_num_max to 1")
self._app_wallbox_num_max = 1

if self._app_wallbox_num_max > 2:
await self.app_get_wallbox_data(wallbox_num=3)
if self._app_raw_wallbox[2] is None:
if self._app_raw_wallbox[2] is None and self._app_wallbox_num_max > 2:
_LOGGER.debug("APP-API set _app_wallbox_num_max to 2")
self._app_wallbox_num_max = 2

if self._app_wallbox_num_max > 3:
await self.app_get_wallbox_data(wallbox_num=4)
if self._app_raw_wallbox[3] is None:
if self._app_raw_wallbox[3] is None and self._app_wallbox_num_max > 3:
_LOGGER.debug("APP-API set _app_wallbox_num_max to 3")
self._app_wallbox_num_max = 3

Expand Down Expand Up @@ -2625,8 +2629,12 @@ async def app_set_wallbox_mode(self, mode_to_set_in_lc: str, wallbox_num: int =
else:
if retry:
await self.app_authenticate()
await self.app_set_wallbox_mode(mode_to_set_in_lc=mode_to_set_in_lc, wallbox_num=wallbox_num, sync=sync,
retry=False)
if self._app_wallbox_num_max >= wallbox_num:
await self.app_set_wallbox_mode(mode_to_set_in_lc=mode_to_set_in_lc, wallbox_num=wallbox_num,
sync=sync, retry=False)
else:
_LOGGER.debug(
f"APP-API cancel 'set_wallbox_mode' since after login the max '{self._app_wallbox_num_max}' is < then '{wallbox_num}' (wallbox number to request)")

async def app_set_wallbox_icmax(self, value_to_set: float, wallbox_num: int = 1, sync: bool = True,
retry: bool = True):
Expand Down Expand Up @@ -2655,8 +2663,12 @@ async def app_set_wallbox_icmax(self, value_to_set: float, wallbox_num: int = 1,
else:
if retry:
await self.app_authenticate()
await self.app_set_wallbox_icmax(value_to_set=value_to_set, wallbox_num=wallbox_num, sync=sync,
retry=False)
if self._app_wallbox_num_max >= wallbox_num:
await self.app_set_wallbox_icmax(value_to_set=value_to_set, wallbox_num=wallbox_num,
sync=sync, retry=False)
else:
_LOGGER.debug(
f"APP-API cancel 'app_set_wallbox_icmax' since after login the max '{self._app_wallbox_num_max}' is < then '{wallbox_num}' (wallbox number to request)")

async def app_set_allow_intercharge(self, value_to_set: bool, wallbox_num: int = 1, sync: bool = True,
retry: bool = True) -> bool:
Expand Down Expand Up @@ -2686,8 +2698,13 @@ async def app_set_allow_intercharge(self, value_to_set: bool, wallbox_num: int =
else:
if retry:
await self.app_authenticate()
return await self.app_set_allow_intercharge(value_to_set=value_to_set, wallbox_num=wallbox_num,
sync=sync, retry=False)
if self._app_wallbox_num_max >= wallbox_num:
return await self.app_set_allow_intercharge(value_to_set=value_to_set, wallbox_num=wallbox_num,
sync=sync, retry=False)
else:
_LOGGER.debug(
f"APP-API cancel 'set_wallbox_mode' since after login the max '{self._app_wallbox_num_max}' is < then '{wallbox_num}' (wallbox number to request)")
return False
else:
return False

Expand All @@ -2696,25 +2713,25 @@ async def app_set_allow_intercharge_all(self, value_to_set: bool, sync: bool = T

if self._app_wallbox_num_max > 0:
res = await self.app_set_allow_intercharge(value_to_set=value_to_set, wallbox_num=1, sync=sync)
if not res:
if not res and self._app_wallbox_num_max > 0:
_LOGGER.debug("APP-API set _app_wallbox_num_max to 0")
self._app_wallbox_num_max = 0

if self._app_wallbox_num_max > 1:
res = await self.app_set_allow_intercharge(value_to_set=value_to_set, wallbox_num=2, sync=sync)
if not res:
if not res and self._app_wallbox_num_max > 1:
_LOGGER.debug("APP-API set _app_wallbox_num_max to 2")
self._app_wallbox_num_max = 1

if self._app_wallbox_num_max > 2:
res = await self.app_set_allow_intercharge(value_to_set=value_to_set, wallbox_num=3, sync=sync)
if not res:
if not res and self._app_wallbox_num_max > 2:
_LOGGER.debug("APP-API set _app_wallbox_num_max to 2")
self._app_wallbox_num_max = 2

if self._app_wallbox_num_max > 3:
res = await self.app_set_allow_intercharge(value_to_set=value_to_set, wallbox_num=4, sync=sync)
if not res:
if not res and self._app_wallbox_num_max > 3:
_LOGGER.debug("APP-API set _app_wallbox_num_max to 3")
self._app_wallbox_num_max = 3

Expand Down

0 comments on commit 97cfdf1

Please sign in to comment.