core icon indicating copy to clipboard operation
core copied to clipboard

Generic Hygrostat: Do not log warning if the hygrostat is already not active

Open Shulyaka opened this issue 2 years ago • 4 comments

Proposed change

Only log warning if the sensor update failed when the hygrostat is already active. When it is not active, only log a debug message. This helps preventing polluting the log with warnings. One common use case is that the warning is emitted when the generic_hygrostat component is loaded before the platform that provides the sensor.

Type of change

  • [ ] Dependency upgrade
  • [x] 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

  • This PR fixes or closes issue: fixes #102053
  • 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 Black (black --fast homeassistant tests)
  • [x] 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:

Shulyaka avatar Oct 24 '23 14:10 Shulyaka

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 Nov 25 '23 15:11 home-assistant[bot]

Is it possible to raise UpdateFailed instead? That should only log once.

As far as I understand the issue, even one log of error is not desirable

Actually, I see that it's also the first one you are trying to catch. Is it possible to change the integration load order using manifest.json dependencies or after_dependencies?

Nope, that wouldn't work, we don't know in advance what integration would provide the sensor configured by user.

Shulyaka avatar Nov 25 '23 16:11 Shulyaka

The PR looks like it meets what you are intending to do, but is there a reason this should not be raising an error?

If you want to mask/downgrade errors that might be generated during an out-of-sequence startup, could you just apply the logic during startup, then after that raise UpdateFailed? Then you could let UpdateFailed manage limiting to a single log entry.

davet2001 avatar Dec 01 '23 21:12 davet2001

I don't think UpdateFailed is applicable in this context. Also I can imagine a situation when HA has already started, but some of the integrations did not load yet (takes time to connect, etc). I don't think that we need to raise the error in this case.

Shulyaka avatar Jan 14 '24 20:01 Shulyaka