segalion / securitasdirect

Home Assistant integration with Securitas Direct (AKA Verisure EU) and command line tool to interact with.
40 stars 17 forks source link

I created a new Home Assistant integration for Securitas Direct #37

Open guerrerotook opened 2 years ago

guerrerotook commented 2 years ago

Hi everyone,

Here you can find my first attempt of having a functional component for using securitas direct in Home Assistant.

https://github.com/guerrerotook/securitas-direct-new-api

This component is using the same configuration as the old one and it's using the new API that Securitas Direct migrated all users.

Please download the component and tell me what do you think. For now it's functional and you can arm and disarm your alarm and also works with multiple installations in case that you have more that one alarm in you account.

If you have feedback please create a new issue in my repository.

Thanks!

soth78 commented 2 years ago

Link gives a 404 so can't try it, could you check @guerrerotook ?

guerrerotook commented 2 years ago

Sorry I did create as private repository. It's now public.

mvillarejo commented 2 years ago

great work @guerrerotook !

tried with my user (DNI) and it works good, but tried with a dedicated user (with enough permissions to operate the alarm, the same I used to use with previous integration) and I get a 'user not found' error.:

2021-12-01 22:33:43 DEBUG (SyncWorker_4) [custom_components.securitas_direct.securitas_direct_new_api.apimanager] {"errors":[{"message":"El usuario introducido no existe","name":"ApiError","time_thrown":"2021-12-01T22:33:43.669Z","data":{"res":"KO","err":"60057"},"path":["xSLoginToken"]}],"data":{"xSLoginToken":null}}

2021-12-01 22:33:43 ERROR (MainThread) [homeassistant.setup] Error during setup of component securitas_direct
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 255, in _async_setup_component
    result = await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/data/custom_components/securitas_direct/__init__.py", line 64, in setup
    if not HUB.login():
  File "/data/custom_components/securitas_direct/__init__.py", line 94, in login
    succeed: Tuple[bool, str] = self.session.login()
  File "/data/custom_components/securitas_direct/securitas_direct_new_api/apimanager.py", line 103, in login
    self.authentication_token = result_json["data"]["xSLoginToken"]["hash"]
TypeError: 'NoneType' object is not subscriptable

Also, when you execute any arming/disarming operation it throws this error (but sets the mode):

2021-12-01 22:37:14 DEBUG (SyncWorker_0) [custom_components.securitas_direct.securitas_direct_new_api.apimanager] {"errors":[{"message":"Tu Alarma está gestionando una solicitud anterior. Por favor, espera 90 segundos antes de realizar otra petición (5 min si es una petición de imagen).","name":"ApiError","time_thrown":"2021-12-01T22:37:14.400Z","data":{"res":"ERROR","err":"60062"},"path":["xSCheckAlarm"]}],"data":{"xSCheckAlarm":null}}

2021-12-01 22:37:14 ERROR (MainThread) [homeassistant.helpers.entity] Update for alarm_control_panel.2512627 fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 463, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 663, in async_device_update
    raise exc
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/data/custom_components/securitas_direct/alarm_control_panel.py", line 214, in update
    alarmStatus: CheckAlarmStatus = hub.update_overview(
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 253, in wrapper
    result = method(*args, **kwargs)
  File "/data/custom_components/securitas_direct/__init__.py", line 114, in update_overview
    referenceId: str = self.session.checkAlarm(Installation)
  File "/data/custom_components/securitas_direct/securitas_direct_new_api/apimanager.py", line 155, in checkAlarm
    return result_json["data"]["xSCheckAlarm"]["referenceId"]
TypeError: 'NoneType' object is not subscriptable

and also when logging off, the following error is thrown:

021-12-01 22:37:28 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/data/custom_components/securitas_direct/__init__.py", line 66, in <lambda>
    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, lambda event: HUB.logout())
  File "/data/custom_components/securitas_direct/__init__.py", line 104, in logout
    ret = self.session.logout()
AttributeError: 'ApiManager' object has no attribute 'logout'

good start!!

soth78 commented 2 years ago

For me its working perfectly.

I saw that the additional user isn't working on the new api. If I try to create a new user it doesn't work so it's a verisure thing, just use the normal user, but works even better than the old one (faster!)

Thx a lot!!!

DNKROZ commented 2 years ago

Just tested it, it works great!, much faster than previous API and more reliable.

Will do some more tests but you're a lifesaver, thank you for this new integration :)

Regards.

elfredo commented 2 years ago

Hi, Actually, the plugin seems to work as i can see the alarm status but the interface doesn't allow me to change it. Could you please tell me how to do to enable changing alarm status ? Thank you

kookeres commented 1 year ago

What is the difference between this integration and the one from Verisure?