core
core copied to clipboard
Refactor NUT commands to use objects instead of strings
Proposed change
This is part 1 of a 2 part PR for adding support for NUT commands with parameters. This PR does the initial work of refactoring the nut commands to be objects with an optional parameter object instead of just strings. The next PR will implement the logic to handle the parameter within Home Assistant.
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)
- [X] Code quality improvements to existing code or addition of tests
Additional information
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request:
Checklist
- [X] The code change is tested and works locally.
- [X] Local tests pass. Your PR cannot be merged unless tests pass
- [X] There is no commented out code in this PR.
- [X] I have followed the development checklist
- [X] I have followed the perfect PR recommendations
- [X] The code has been formatted using Ruff (
ruff format homeassistant tests) - [X] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for www.home-assistant.io
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 runningpython3 -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.
To help with the load of incoming pull requests:
- [X] I have reviewed two other open pull requests in this repository.
Hey there @bdraco, @ollo69, @pestevez, mind taking a look at this pull request as it has been labeled with an integration (nut) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of nut can trigger bot actions by commenting:
@home-assistant closeCloses the pull request.@home-assistant rename Awesome new titleRenames the pull request.@home-assistant reopenReopen the pull request.@home-assistant unassign nutRemoves the current integration label and assignees on the pull request, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.
So why are these device actions and not normal service actions to begin with?
So why are these device actions and not normal service actions to begin with?
This is my first time working with the NUT component, so Nick prob has more background on that than I do, but I was assuming it was because each device only supports a subset of the commands listed above. You need to query the device, and you get back a supported set of commands, which is different for each ups. Then we match up the supported commands the UPS sends to us with the ones we know we support in the above list to expose the specific list of actions supported per device.
Because when I look at the code now I would maybe consider just creating entities out of the functionality. There are probably some things that can be changed into buttons and switches from looking at the names. Are there reasons before or against that?
For other things we can use actions calls if needed, but they have to be registered in async_setup, and thus are always available, no matter if the device supports or not, which requires a bit of extra validation
There are probably some things that can be changed into buttons and switches from looking at the names. Are there reasons before or against that?
Many of them are capable of taking parameters so it was decided not to implement them as buttons in the original PR since it would be confusing to have buttons for some and actions for others that take parameters
Device automations should only be a device layer on top of core interfaces.
There needs to be service actions, either entity based or integration based that perform the same actions as a foundation.
@eclair4151 In the phase 2 PR, could you add retries to the connection polling. I have 1 UPS connected to a RPi Zero 2 and well Wifi...
I believe we would be best served to move some of the device_actions into buttons, switches, etc. This will allow users to initiate them from the GUI as well as invoke them through automations.
I believe we would be best served to move some of the device_actions into buttons, switches, etc. This will allow users to initiate them from the GUI as well as invoke them through automations.
I agree, and looks like Martin does as well from the 👍 above
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!