ZHA lock code services and events#47208
Conversation
|
Still need to add tests and documentation and clean up some things, possibly add a couple more function calls to be ready for keymaster support |
|
@Adminiuga @dmulcahey looking for a little discussion on this if you have a minute. |
|
Yeah, there's no good way to return a result of a service call to the user. So making a service call to set/clear the codes is easy, but for reading the code, the solution is going to be cumbersome, like issuing a service call and then generating an event??? Maybe, should not allow reading the pin codes at all? |
|
That's what I was thinking as well. Looking at the zwavejs homeassistant library code, it looks like the read codes functions were included (so custom add-ons like Keymaster can read them), without any service calls. |
|
Does add-on read the code through home assistant api or directly through zwave j's server? |
|
If you add the functionality I can find a way to expose it via the websocket API to the front end |
|
Yeah, it probably makes most sense to be exposed via ws commands, but i have no ideas iv lovelace cards support any. Haven't looked frankly. |
|
My guess is I’ll have to build custom elements for the device page... we’ll see |
|
Okay yeah that makes sense. I'll add a few more of the functions this evening. Understanding enough to get one to work took a day, but now that I got this far, adding get, clear all codes, enable/disable code slot etc will only be a few minutes each |
We use the client library to read the codes. As you mentioned, there's no way to do this through the homeassistant API using existing constructs. We can create a helper method in the component code in lieu of having it in the client library but that's about as far as we can go as far as the custom component (keymaster) is concerned |
@Adminiuga @jcam @dmulcahey Let me know if I can help anyhow. I am a tech person (sysadmin) with some dev skills in a past (perl, php, C) , but unfortunately not in Python. |
|
I picked it up because I have a zigbee lock :D There is no standard API calls for the key lock managers, they were mostly all custom for zwave, but since raman325 and firstof9 both just went through the steps of adding zwave-js to keymanager, everyone's pretty familiar with what'll need to be in place for zigbee. The way they interact will be different because of how each integration stores things and presents things, but underneath it all, it's all just a lock with code slots and pin codes, so a translation function in keymanager won't be hard. |
23d5f22 to
8b32f8c
Compare
| self.zha_send_event( | ||
| command_name, | ||
| { | ||
| "source": args[0].name, |
There was a problem hiding this comment.
@Adminiuga is there a better way to parse the args out? Or is there a better way to do this?
There was a problem hiding this comment.
not really, cause args would change depending on the command_id
| set_pin_code = self.__getattr__("set_pin_code") | ||
| await set_pin_code( | ||
| *( | ||
| code_slot - 1, # start code slots at 1 |
There was a problem hiding this comment.
how come all of these are shifted by 1? Just curious
There was a problem hiding this comment.
I shifted by one in part because I want this to be "people" friendly as opposed to "machine" friendly, so start at 1 instead of 0; and in part because z-wave locks start with slot 1, and I wanted to have consistency with them.
|
This still needs more coverage in the tests. The uncovered lines are tagged in the PR by CI |
Yup definitely still need to build some tests. |
| set_pin_code = self.__getattr__("set_pin_code") | ||
| await set_pin_code( |
There was a problem hiding this comment.
why not just await self.set_pin_code() ?
There was a problem hiding this comment.
is that a thing that will work? If so I can update to that easily
There was a problem hiding this comment.
definitely test it, but it should work.
There was a problem hiding this comment.
I'm still new to python :)
running tox now, will try with my lock in a bit
There was a problem hiding this comment.
Work got crazy for a couple weeks, but I finally was able to test with my door locks. As you suggested, it worked just fine. Updated commit pushed.
There is more that could be done... we can add more API tests and add UI to the device page, but this should be ready for the beta as an MVP.
| set_pin_code = self.__getattr__("set_pin_code") | ||
| await set_pin_code( | ||
| *( | ||
| code_slot - 1, # start code slots at 1, Zigbee internals use 0 | ||
| closures.DoorLock.UserStatus.Enabled, | ||
| closures.DoorLock.UserType.Unrestricted, | ||
| user_code, | ||
| ), | ||
| ) |
There was a problem hiding this comment.
| set_pin_code = self.__getattr__("set_pin_code") | |
| await set_pin_code( | |
| *( | |
| code_slot - 1, # start code slots at 1, Zigbee internals use 0 | |
| closures.DoorLock.UserStatus.Enabled, | |
| closures.DoorLock.UserType.Unrestricted, | |
| user_code, | |
| ), | |
| ) | |
| await self.set_pin_code( | |
| code_slot - 1, # start code slots at 1, Zigbee internals use 0 | |
| closures.DoorLock.UserStatus.Enabled, | |
| closures.DoorLock.UserType.Unrestricted, | |
| user_code, | |
| ) |
|
If there is anything I can do, short of coding, to help here - I'd love to. So excited for this. |
|
Hi! If you're up for it, I'm aiming to have this in place for the beta, and you could test it out in the first beta :) |
|
I'm happy to help in any way that I can. Thanks for taking on this project. |
|
@jcam l'd love to participate in beta testing as well - hopefully without breaking my whole system :) I am thinking about cloning the SD card, switching HA repository to "beta" (how?) on the cloned card. testing and then swapping the card back to the original at the end. Will it work? |
|
You are already doing scheduled backups, right? 😄 |
Proposed change
Type of change
Example entry for
configuration.yaml:# Example configuration.yamlAdditional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: