Code quality improvements at Home Connect
Breaking change
Proposed change
- Added types to all arguments and return values to all functions
- Defined class members and its types outside the constructor
- Improved logic at binary sensor
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
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:
- [ ] 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:
- [ ] I have reviewed two other open pull requests in this repository.
Hey there @davidmstraub, mind taking a look at this pull request as it has been labeled with an integration (home_connect) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of home_connect 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 home_connectRemoves 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.
@joostlek These are all the things I found that I think they need quality improvements, do you know any tool or command that can help me find any other code quality issues?
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks :+1:
We want our functions completely typed in general. Instance variables are usually inferred when set (unless mypy complains, then you add one). So we don't have to overwrite every instance variable with a type outside of the constructor
I noticed that in some components, the entity description tuples are placed at the end of the file This might be a good idea to apply because entity descriptions can be quite large, and if they are placed before classes and logic, classes and logic will be be at the end of the file, which means you have to scroll all the way down to get to the code, which is quite inconvenient and sensor. (And also specifying the type of the tuples might not be necessary) https://github.com/home-assistant/core/blob/9189af7e84a36e2deafb88cabad58ab231008c9f/homeassistant/components/home_connect/binary_sensor.py#L52-L65 https://github.com/home-assistant/core/blob/9189af7e84a36e2deafb88cabad58ab231008c9f/homeassistant/components/home_connect/light.py#L52-L63 https://github.com/home-assistant/core/blob/9189af7e84a36e2deafb88cabad58ab231008c9f/homeassistant/components/home_connect/sensor.py#L53-L90 https://github.com/home-assistant/core/blob/9189af7e84a36e2deafb88cabad58ab231008c9f/homeassistant/components/home_connect/switch.py#L40-L54
Also, I had a question that this PR might be the place to be answered to then make the necessary changes and add them to this PR.
At strings.json, is there any specified order for the first level keys?
I've been setting them always alphabetically ordered, but right now in this component, entity object is at the end of the file, should we move it?
Usually the order in the file is
Entity definitions Setup logic Entity classes
@joostlek regarding the strings.json file, does it require a particular order? I'm asking because on the dev branch, assuming alphabetical sorting is used, the entity object seems to be misplaced in this component.
We don't really enforce an order in the strings.json, but it usually starts with the config flow and then the rest
Cool, good to know, I will leave the current order then in the other PRs, thanks!