axis icon indicating copy to clipboard operation
axis copied to clipboard

Support for Access control?

Open robby-d opened this issue 4 years ago • 22 comments

Hi, just found this library. I have a A1001 door controller and tested the current state of the HomeAssistant integration. It appears that I can get a few states off of it, but no lock control (e.g. as switch entities) came across. It would be wonderful to be able to both discover and control the door lock state(s) for configured doors (as well as doors configured on additional connected/linked door controllers). Is this a planned feature? If not, I can look into adding it once I have some spare time.

(I also connected to an A8207VE MkII keypad/cam device, which was integrated via VAPIX to the aforementioned door controller -- I can see more information, including PIR state, camera feed and door status, however, I cannot operate the door lock through that as well. Being able to operate the door directly through a connection to the door controller(s) themselves would be optimal.)

robby-d avatar Sep 05 '20 01:09 robby-d

Hi @robby-dermody! I do have plans to add support for this, but I can not promise when that would be. Feel free to open PRs to support these devices functionality.

Kane610 avatar Sep 05 '20 09:09 Kane610

Sounds good, thank you!

robby-d avatar Sep 05 '20 11:09 robby-d

@Kane610 - Didn't want to open up a new issue, so I'm commenting here. I've been reading through your code and am interested in doing some work and submitting a PR to support A1001, but I'm newer to Python (I'm a .NET turned Java guy) and haven't been able to find good tutorials/documentation related to VAPIX. Do you have any recommended resources on VAPIX or guidance on where to start that would let me create a CLI app that uses this library as a dependency so I can get started to add in lock controls and door lock states? I've gotten as a far as installing PyCharm as I'm a JetBrains fanatic.

Thanks!

drewclauson avatar May 13 '21 20:05 drewclauson

Hey!

Awesome! When I'm adding a new API I usually augment the main function so I can just run everything from the commandline directly, ideally the main function would be a bit more advanced to offer some more CLI friendly controls.

Regarding documentation you have the official API documentation here https://www.axis.com/vapix-library/subjects/t10067552/section/t10068742/display

But in my experience you really need a device to try it out with, that also helps adding tests to improve iterating on it once you've got the basics implemented. Make sure to base your implementation on the latest firmware available, the API documentation typically only reflects the latest released version of the API.

I just wrapped up keypad support for the deCONZ integration a couple of weeks back so I'm also eager to get something similar running with the Axis integration.

Right now I'm finishing up my libraries to make sure dependencies and CI tools are helping out with verification and will also add proper typing before I go back to adding additional functionality.

Don't hesitate to ping me, we can also iterate quicker over discord should you prefer.

Reopening this issue in the mean time.

Kane610 avatar May 14 '21 14:05 Kane610

Thanks! I have access to two A1001s and I'm hoping to spend some time looking into it this weekend.

drewclauson avatar May 14 '21 14:05 drewclauson

Awesome! I will look into the different access control APIs as well

Kane610 avatar May 14 '21 19:05 Kane610

So, I've got the code connecting to my A1001 and -D is showing me params, but I'm getting a 404 when it tries to

POST http://<mydeviceip>/axis-cgi/apidiscovery.cgi

I haven't gotten too far, but I'm guessing that's a pretty integral part of the process, being able to discover what APIs are supported? It doesn't seem to exist when looking through the device's cgi scripts, but I can get params.cgi.

drewclauson avatar May 19 '21 17:05 drewclauson

404s are expected to exist when talking to different devices with different feature sets. Older devices don't support API Discovery so its completely fine.

https://github.com/Kane610/axis/blob/f3e8b9304d3629eac4633b32da86aaf3d99ae1bf/axis/errors.py#L39 https://github.com/Kane610/axis/blob/f3e8b9304d3629eac4633b32da86aaf3d99ae1bf/axis/vapix.py#L132

Kane610 avatar May 19 '21 17:05 Kane610

Great, thanks. I've been able to do some figuring out of how to perform actions through VAPIX to get the basics of what I'm after (unlocking a door via button and getting door lock/unlock status). There's more than that available, but I at least have a good idea on how to make the right requests via Postman. Just need to figure out how to bring those actions into this code.

I see how you're capturing events through VAPIX. I don't see anything where the library issues actions through VAPIX. Does that sound accurate?

drewclauson avatar May 19 '21 19:05 drewclauson

Awesome! Exciting to see what you come up with!

There are loads of examples controlling different parts of the device through Vapix

Enable MQTT service in device https://github.com/Kane610/axis/blob/f3e8b9304d3629eac4633b32da86aaf3d99ae1bf/axis/mqtt.py#L108

Activate a specific light https://github.com/Kane610/axis/blob/f3e8b9304d3629eac4633b32da86aaf3d99ae1bf/axis/light_control.py#L55

Set state of port (new API) https://github.com/Kane610/axis/blob/f3e8b9304d3629eac4633b32da86aaf3d99ae1bf/axis/port_management.py#L163

Set state of port (old API) https://github.com/Kane610/axis/blob/f3e8b9304d3629eac4633b32da86aaf3d99ae1bf/axis/port_cgi.py#L92

I'm up for general suggestions on how to improve the library as a whole. I'm trying to reflect changes in a way so my libraries for both deCONZ and UniFi are similar. I've done a lot of refactorings and improvements over the year where I've learned something with one of the libraries and then try to reflect the same changes in the other ones.

Kane610 avatar May 19 '21 20:05 Kane610

Thanks - sorry to be the newbie on this code, but it's my foray into a real Python library. 🤦‍♂️

I only thought that it wasn't using VAPIX because this URL was calling a cgi script where the A1001 would be calling /vapix/doorcontrol I'll have more time later this week to look through it more.

https://github.com/Kane610/axis/blob/f3e8b9304d3629eac4633b32da86aaf3d99ae1bf/axis/light_control.py#L11

I'm not the best person from an architecture perspective, but I'll make any suggestions if I come up with some. (I've been working as a DBA for the past 3 years, which has left a bunch of coding experience more stagnant than I'd like)

drewclauson avatar May 19 '21 20:05 drewclauson

No worries, I'm excited to have you just experimenting :)

Everything is Vapix, it's the branding of the APIs of Axis devices.

Kane610 avatar May 19 '21 20:05 Kane610

I made some progress on putting together the basics for defining API calls that I think will be useful and also associated tests.

If you have a minute, take a look at progress so far, I'm not sure of exact next steps, but I think I need to understand how to help HA discover the available services.

https://github.com/Kane610/axis/compare/master...drewclauson:add-door-control

drewclauson avatar May 27 '21 19:05 drewclauson

Hey! Looked at it and the documentation a bit, overall it looks good! Awesome job!

I do have comments, but nothing major. E.g. door_control in param_cgi.py is superfluous since you have the api discovery mechanism stated, so one can always look in api discovery or check if door_control is None to see if it is supported. Big groups of properties inside of a dict (device and door capabilities) should probably be clarified with global strings to avoid manually specifying keys in home assistant or other places the library is used.

I'm contemplating if this should be put under a /access_control folder similar to applications

Once I'm finished with the typing PR you will need to rebase and follow the additional tests performed (nothing major)

Kane610 avatar May 28 '21 19:05 Kane610

E.g. door_control in param_cgi.py is superfluous since you have the api discovery mechanism stated, so one can always look in api discovery or check if door_control is None to see if it is supported.

Thanks, I wasn't quite clear on that, but decided to mimic stuff that I was seeing in light_control.

Big groups of properties inside of a dict (device and door capabilities) should probably be clarified with global strings to avoid manually specifying keys in home assistant or other places the library is used.

Definitely had that in the back of my head and will do that. Would that look something like below on the door class for each capability that we want to be able to use?

image

drewclauson avatar May 28 '21 20:05 drewclauson

Definitely had that in the back of my head and will do that. Would that look something like below on the door class for each capability that we want to be able to use?

I'm not sure, haven't had many capabilities like this before. What do you think?

It would either be class methods like you post or globals like https://github.com/Kane610/axis/blob/5c1d9a2d8006fe8797ce6c3c106941b1a2c8814b/axis/ptz.py#L16

Kane610 avatar May 28 '21 20:05 Kane610

Oh I see what you mean. I like the globals better, I'll work on that. Although there are a lot of capabilities, there's only a select few that will likely be useful for users. "Access" is probably the most used one, in order to allow a user to just unlock the door temporarily. That's actually the only one that I can think of currently that I need for my use case, but thought it good to just build the other ones out as other people might want them in the future.

drewclauson avatar May 28 '21 20:05 drewclauson

Feel free to publish your PR, it might be better to contain this discussion to that rather than in this issue

Kane610 avatar May 28 '21 20:05 Kane610

Published #90

drewclauson avatar Jun 03 '21 13:06 drewclauson

I'm wondering what would be the best path forward in trying to get support added for the Axis A1001? I have access to one for testing and have done some programming in python.

darkdecoy avatar Mar 26 '24 21:03 darkdecoy

I'm wondering what would be the best path forward in trying to get support added for the Axis A1001? I have access to one for testing and have done some programming in python.

I want to do this some time in the future as Drew couldn't complete it. But right now I'm focused on other things than access control. So if you can adapt Drew's or to work with latest version of the library world be a good start. If you have the patience I will help you move forward

Kane610 avatar Mar 26 '24 21:03 Kane610

Hi - my apologies! - yes I totally lost track of this due to life circumstances and ended up directly using a command line integration in HA and curl command to accomplish what I needed. I was also pretty new to Python at the time. I’d offer to pick it back up, but I have little time for side projects right now. All my progress should be clear in my PR, I didn’t have any modifications that I didn’t push to that.

drewclauson avatar Mar 26 '24 22:03 drewclauson