guerrerotook / securitas-direct-new-api

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

Separate the Securitas API manager from the HA integration #184

Closed cantupaz closed 8 months ago

cantupaz commented 8 months ago

First, thanks @guerrerotook for all your work in this integration. Being able to use HA instead of the official app makes me extremely happy. Second, I'm probably 80% done on what I'm proposing to do here, so I'm not trying to add a lot of work. Let's discuss.

What: I'm proposing to separate the HA integration from the internal dealings of Securitas' API, so all the API logic is encapsulated and abstracted into its own, instead of having little bits of API logic in HA.

Why: As a customer of Securitas, I'd like to be able to send commands directly to my alarm system without having to use HA. And, as a user of HA, I'd like to debug the integration without having to worry about API details. This is a common pattern in many HA integrations, probably because it helps speed up testing.

What does "done" mean?

"Done" does not mean...

If someone wants to see WIP and give suggestions: https://github.com/cantupaz/securitas-direct-new-api/tree/exceptions

guerrerotook commented 8 months ago

Hey, thanks very much for the suggestion. Of course we can do that. How would you like to do those changes? I can give you contributions access to the repository if you want, so you can work on those changes?

Thoughts?

cantupaz commented 8 months ago

Thanks. I was thinking about sending you pull requests, so you can review things and incorporate them as you see fit. But contribution access would also work. Whatever you prefer.

In any case, I'd recommend that you integrate the open PR first, so there are not many changes coming in at once, and that PR also has a few small bug fixes.

Feliz Navidad.

cantupaz commented 8 months ago

I'm almost done with this, but I'd like to test it for a few days in my system.

I also noticed that the API changed in the past couple of days. Now you need to add 'auth': '{"loginTimestamp": 1704209695413 ....} and for many operations also add X-capabilities to headers: headers["X-Capabilities"] = installation.capabilities

See https://github.com/cantupaz/securitas-direct-new-api/blob/exceptions/custom_components/securitas/securitas_direct_new_api/apimanager.py

elfredo commented 8 months ago

Hi and Feliz Año Nuevo! Is it now possible to use the API without HA integration ? Thank you !

cantupaz commented 8 months ago

It is not a separate package that you could install on its own, but the files in securitas_direct_new_api are an API wrapper that you can use without HA. For example, see the file basic_operations.py in the examples folder (also be aware of the hack to set the path at the start of that file, you may have to change it).

Separating the API wrapper its own repository makes sense, but for now you have to clone the whole repo and ignore the HA part.