Skip to content

Conversation

ondras12345
Copy link
Contributor

@ondras12345 ondras12345 commented Sep 5, 2025

Proposed change

Sometimes it is useful to be able to read input or holding registers without creating a new entity with polling for them. Examples include peeking at configuration registers that only need to be read once during the commissioning of a new device.

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.

To help with the load of incoming pull requests:

@@ -13,6 +13,7 @@
It uses binary_sensors/sensors to do black box testing of the read calls.
"""

from contextlib import nullcontext as does_not_raise
Copy link
Contributor

Choose a reason for hiding this comment

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

In the past, the use of contextlib was not encouraged. I don't know if this is changed now.

Copy link
Contributor Author

@ondras12345 ondras12345 Sep 6, 2025

Choose a reason for hiding this comment

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

Thanks for reviewing.
As far as I can tell, that comment was specifically about contextlib.suppress.
Here, I am just using contextlib.nullcontext to disable the pytest.raises() if I do not expect the service call to error out. It seemed cleaner than duplicating the hass.services.async_call line.
This pattern seems to be somewhat common in tests, see e.g. https://github.com/home-assistant/core/blob/6a1629d2ed6ea3473544a3e6dc5fd188f97f0445/tests/components/recorder/test_backup.py
However, I am no expert.

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.

2 participants