Skip to content

Commit

Permalink
Fixed a bug when the session was expired the login wasn't awaited.
Browse files Browse the repository at this point in the history
  • Loading branch information
guerrerotook committed Feb 26, 2022
1 parent 20b991f commit d336e3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions custom_components/securitas/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ async def get_arm_state(self):

async def set_arm_state(self, state, attempts=3):
"""Send set arm state command."""
arm_status: ArmStatus = {}
if state == "DARM1":
response = await self.client.session.disarm_alarm(
self.installation, self._get_proto_status()
Expand All @@ -138,7 +139,7 @@ async def set_arm_state(self, state, attempts=3):
# check arming status
await asyncio.sleep(1)
count = 1
arm_status: ArmStatus = await self.client.session.check_disarm_status(
arm_status = await self.client.session.check_disarm_status(
self.installation,
response[1],
ArmType.TOTAL,
Expand All @@ -159,7 +160,6 @@ async def set_arm_state(self, state, attempts=3):
self._attr_extra_state_attributes[
"response_data"
] = arm_status.protomResponseData
self._state = state
self._force_update = True
else:
_LOGGER.error(response[1])
Expand All @@ -171,7 +171,7 @@ async def set_arm_state(self, state, attempts=3):
# check arming status
await asyncio.sleep(1)
count = 1
arm_status: ArmStatus = await self.client.session.check_arm_status(
arm_status = await self.client.session.check_arm_status(
self.installation,
response[1],
state,
Expand All @@ -192,11 +192,20 @@ async def set_arm_state(self, state, attempts=3):
self._attr_extra_state_attributes[
"response_data"
] = arm_status.protomResponseData
self._state = state
self._force_update = True
else:
_LOGGER.error(response[1])
self.schedule_update_ha_state()
self.update_status_alarm(
CheckAlarmStatus(
arm_status.operation_status,
arm_status.message,
arm_status.status,
arm_status.InstallationNumer,
arm_status.protomResponse,
arm_status.protomResponseData,
)
)
# self.schedule_update_ha_state()
# hub.update_overview(no_throttle=True)

@property
Expand Down Expand Up @@ -268,11 +277,13 @@ def update_status_alarm(self, status: CheckAlarmStatus = None):

async def async_update(self):
"""Update the status of the alarm based on the configuration."""
alarm_status: CheckAlarmStatus = await self.client.update_overview(
self.installation, self._force_update
)
self._force_update = False
self.update_status_alarm(alarm_status)
if not self._force_update:
alarm_status: CheckAlarmStatus = await self.client.update_overview(
self.installation, self._force_update
)
self.update_status_alarm(alarm_status)
else:
self._force_update = False

async def async_alarm_disarm(self, code=None):
"""Send disarm command."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def _execute_request(self, content) -> ClientResponse:
_LOGGER.debug(response_text)
error_login: bool = await self._check_errros(response_text)
if error_login:
return self._execute_request(content)
return await self._execute_request(content)

return response

Expand Down

0 comments on commit d336e3f

Please sign in to comment.