core icon indicating copy to clipboard operation
core copied to clipboard

Refactor some zwave code and add test coverage

Open raman325 opened this issue 2 years ago • 2 comments

Proposed change

Slowly working on improving test coverage. You'll notice that I made some changes to the code of the modules. These changes should be no-op from a user perspective as described below. Note that this should probably be merged before https://github.com/home-assistant/core/pull/92223 and https://github.com/home-assistant/core/pull/90248 so I can rebase those to accommodate the logic changes in the sensor platform.

device_action:

  • The if statement logic was wrong so corrected (we want to skip an entity if it doesn't have a state so it is disabled or gone, or it's state is unknown)
  • Combined statements

fan:

  • Rather than guarding for no target value in each service, we guard during initialization since a fan without a target value is not controllable.
  • Removed speed_count property. It is unused in ZwaveFan because percentage_step is hardcoded to 1 (speed_count is used in FanEntity to calculate percentage_step)
  • Refactored ValueMappingZwaveFan.percentage_to_zwave_speed to accomplish the same thing while reducing code branches

light:

  • fixed turn_on logic for ZwaveBlackIsOffLight to only set the colors to turn on the light if colors are sent in the service call.

sensor:

  • The classes were built for specific use cases but there was a way to combine them into a single base sensor class so we can eliminate the number of different class types
  • Removed dupe/redundant logic across classes
  • Meter sensor state attributes were unnecessarily guarded
  • If endpoint is missing for meter sensor, default to 0

trigger:

  • Currently all trigger platforms have async_validate_trigger_config so there is no need for conditional logic, we can add it back in later if/when needed

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

  • [ ] 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 Black (black --fast 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:

raman325 avatar Apr 30 '23 06:04 raman325

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[bot] avatar Apr 30 '23 06:04 home-assistant[bot]

even though this fails on patch coverage, this improves coverage in the component.

With this PR:

---------- coverage: platform darwin, python 3.11.3-final-0 ----------
Name                                                             Stmts   Miss  Cover   Missing
TOTAL                                                             5081     36    99%

Without this PR:

---------- coverage: platform darwin, python 3.11.3-final-0 ----------
Name                                                             Stmts   Miss  Cover   Missing
TOTAL                                                             5135     87    98%

raman325 avatar Apr 30 '23 19:04 raman325

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

Learn more about our pull request process.

home-assistant[bot] avatar May 17 '23 11:05 home-assistant[bot]

opened separate PRs

raman325 avatar May 19 '23 04:05 raman325