guerrerotook / securitas-direct-new-api

This repository contains the new securitas direct API that can be integrated in Home Assistant
Apache License 2.0
73 stars 30 forks source link

Cannot configure integration #212

Closed Uozzon closed 4 months ago

Uozzon commented 5 months ago

Working since two years, yesterday started not working any more with an error on protom_response. Installed the very last version 2.7.2.0 but with no success in resolving the error.

Decided to uninstall the Securitas component and reinstall (using HACS), but now I cannot configure the integration: After input of the 2FA I always get (stripping the full stack):

... File "/usr/local/lib/python3.12/site-packages/jwt/api_jws.py", line 254, in _load raise DecodeError(f"Invalid token type. Token must be a {bytes}") jwt.exceptions.DecodeError: Invalid token type. Token must be a <class 'bytes'>

The above exception was the direct cause of the following exception:

... File "/config/custom_components/securitas/config_flow.py", line 110, in finish_setup await self.securitas.login() File "/config/custom_components/securitas/init.py", line 362, in login await self.session.login() File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 339, in login raise SecuritasDirectError( custom_components.securitas.securitas_direct_new_api.exceptions.SecuritasDirectError: Failed to decode authentication token None

cantupaz commented 5 months ago

When you setup the integration, can you skip the 2FA step (there's a checkbox for that) and see if that works?

Uozzon commented 5 months ago

Yes I tried but I get the exact same error. Thanks for your help

cantupaz commented 5 months ago

I'm trying a few random things to replicate this, but I cannot. Can you enable logging, try again without the 2FA, and paste the logs?

Uozzon commented 5 months ago

Ok, the configuration problem is solved (my fault: I did not use the primary login, but a secondary login, sorry for that). Now I have another problem, the one I had when I decided to reinstall from scratch.

This is the sequence:

2024-02-23 18:05:28.315 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] Authentication token expires 2024-02-23 18:20:26 and now is 2024-02-23 18:05:28.315792 2024-02-23 18:05:28.315 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] Capabilities token expires 2024-02-23 18:20:26 and now is 2024-02-23 18:05:28.315931 2024-02-23 18:05:28.317 ERROR (MainThread) [homeassistant.components.alarm_control_panel] Error while setting up securitas platform for alarm_control_panel Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 344, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/securitas/alarm_control_panel.py", line 80, in async_setup_entry current_state: CheckAlarmStatus = await client.update_overview( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/securitas/init.py", line 425, in update_overview alarm_status = await self.session.check_alarm_status( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 536, in check_alarm_status self.protom_response = raw_data["protomResponse"]


KeyError: 'protomResponse'

Some more info:
- I use the very last version 2.7.3.0.
- eventually reenabling the PIN succeded in reloading securitas, but it was erratical, i tried serveral times with some succesful reloding but more often getting the exception. Finally succeded in reloading without the PIN and unchecking "Check alarm panel's status in every request (not recommended)".

As a side info, the update scan interval does not work for me, I wanted 3600 secs to have a reload every hour, but again the check was made every minute. So I ended up removing the polling on the system configuration for securitas, i'll check with an automation.

Tanks again for the help
cantupaz commented 5 months ago

Securitas is erratic. Depending on the day of the week and the mood of the API gods, we may get a response or not and it may be correct or not. The integration should handle these cases, but honestly there is a lot of error handling that is missing. We'll be adding some as we go.

Did you try deleting and reinstalling the integration or were you just changing parameters with the "Configure" option of the integration?

Uozzon commented 5 months ago

I was just changing parameters and saving, with automatic reaload of the integration. Thought it was connected with the parameters, but i'ts more likely your explanation :)

cantupaz commented 4 months ago

I missed this comment: "the update scan interval does not work for me, I wanted 3600 secs to have a reload every hour, but again the check was made every minute." I introduced a bug that should be fixed in the next release.

Closing this issue