8000 Add zwave js services get_lock_usercode and get_lock_usercodes by holocronweaver · Pull Request #119714 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Add zwave js services get_lock_usercode and g 8000 et_lock_usercodes #119714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

holocronweaver
Copy link
@holocronweaver holocronweaver 8000 commented Jun 14, 2024

Proposed change

This resolves a feature request to add Z-wave JS services for retrieving lock usercodes.

A good use case for these services is creating a Z-wave lock management dashboard card like this:

lock management widget

In the 'Code Slot' section of this card, selecting a code slot index automatically updates the lock code to the current value for that slot (via an automation using get_lock_usercode). This can help remind you of the code currently at that slot and possibly avoiding accidental overwrite/clear of a slot you forgot was in use.

Further down the card in the 'All Codes' section, all usercodes from the main lock are shown (via get_lock_usercodes) which is handy when reviewing all usercodes at a glance, especially when you have 10+ slots that may not be set sequentially.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@holocronweaver holocronweaver requested a review from a team as a code owner June 14, 2024 20:56
Copy link
@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @holocronweaver

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link

Hey there @home-assistant/z-wave, mind taking a look at this pull request as it has been labeled with an integration (zwave_js) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of zwave_js can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign zwave_js Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Comment on lines 62 to 63
"get_lock_usercode": "mdi:lock-percent-outline",
"get_lock_usercodes": "mdi:lock-percent",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggled to find an appropriate icon. If you know of something more intuitive or uniform with other icons in the app, let me know!

@holocronweaver holocronweaver force-pushed the zwave-get-lock-usercodes branch from 759d880 to 5c7d10c Compare June 27, 2024 15:34
@holocronweaver
Copy link
Author

This review could use some eyes from Home Assistant dev team, maybe @home-assistant/z-wave

@DHowett
Copy link
DHowett commented Aug 29, 2024

I just tested this with HA Core 2024.08.04, and it still works great. No merge conflicts.

Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Oct 29, 2024
and ATTR_USERCODE in code_slot
and code_slot.get(ATTR_USERCODE)
}
return {"usercodes": usercodes}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we just return the usercodes?

"User code at slot %s on lock %s retrieved", code_slot, self.entity_id
)
usercode: str | None = code_slot_obj.get(ATTR_USERCODE) # type: ignore[assignment]
return {"usercode": usercode}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we return just the user code?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Makes more sense to return the code vs an object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raman325 I did this to avoid breaking changes in the future if additional metadata is added. As is, adding a new key-value pair would not break any existing code, but switching from a single object to a dict in the future would. Since this project is used by many users, each of which would have do update their code for any breaking changes, I err slightly on the side of future-proofing over simplicity.

I based this on other HA modules that used a similar pattern, but I submitted this PR back in early June but wasn't reviewed until almost November, so I no longer recall which modules I studied.

I'll go ahead and make the change to expedite getting this PR out, but in the future I suggest avoiding holding up PRs over minor nitpicks, especially if the review cycle is around 5 months.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@holocronweaver thanks for giving me additional context. I see your point about future compatibility, but I am not sure that we want these services to change in the future, their scope is extremely limited. Are there future features that you are thinking about in particular?

As for whether this change should block this PR from being merged, it's not a minor nitpick because once we merge it, we can't change the return signature without a lot of extra work and time to deprecate etc. It would be nice to shorten the review cycle, but that's a resourcing problem (not enough reviewers), not a minor nitpicking problem, and we don't lower the quality bar to speed up velocity.

@home-assistant home-assistant bot marked this pull request as draft October 29, 2024 17:34
@github-actions github-actions bot removed the stale label Oct 30, 2024
@tony-gutierrez
Copy link

@holocronweaver any progress on the small requested change?

@holocronweaver holocronweaver force-pushed the zwave-get-lock-usercodes branch from 5c7d10c to 9d9c763 Compare January 16, 2025 16:19
@holocronweaver holocronweaver force-pushed the zwave-get-lock-usercodes branch from 9d9c763 to 840896c Compare January 16, 2025 16:45
Comment on lines +328 to +335
if action_type == SERVICE_GET_LOCK_USERCODE:
return {
"extra_fields": vol.Schema(
{
vol.Required(ATTR_CODE_SLOT): cv.string,
}
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'd have to update the device action tests to cover this. There are multiple tests that likely need to be updated in the test_device_action model to cover this additional service

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also pull out the device action changes instead and submit separately, I don't think we are a 6D47 ctually at parity with the new services for device actions so you could include those other ones. Just a thought, not a requirement

@holocronweaver holocronweaver force-pushed the zwave-get-lock-usercodes branch from 8f7aaaa to 2e4c914 Compare January 16, 2025 19:19
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Mar 18, 2025
@holocronweaver
Copy link
Author

I will get around to finishing this in a few weeks, sorry for the delay.

@github-actions github-actions bot removed the stale label Mar 19, 2025
@@ -302,6 +304,21 @@
},
"name": "Clear lock user code"
},
"get_lock_usercode": {
"description": "Get a user code for a lock.",
Copy link
Contributor
@NoRi2909 NoRi2909 Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other actions please change to:

  • "Retrieves a user code for a lock."

and for the other action:

  • "Retrieves all user codes for a lock."

Using descriptive wording also helps in getting consistent translations.

@flyize
Copy link
Contributor
flyize commented Mar 29, 2025

I will get around to finishing this in a few weeks, sorry for the delay.

Any chance you could also make a forum post showing how you created the Lovelace view in the OP?

Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label May 29, 2025
@flyize
Copy link
Contributor
flyize commented May 30, 2025

I cherrypicked this a while back and have been running it for months. It works great.

@github-actions github-actions bot removed the stale label May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
0