Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modbus: Add support for Holding Registers to Binary Sensor #80460

Merged
merged 7 commits into from Oct 18, 2022

Conversation

Nippey
Copy link
Contributor

@Nippey Nippey commented Oct 17, 2022

Breaking change

Proposed change

I have a 32-channel input ("N4DIM32") for modbus. This device exposes its internal states via holding registers.
(If required, I can attach the interface description provided by the seller.)
As binary_sensor currently only supports CALL_TYPE_COIL, CALL_TYPE_DISCRETE:

ADDED: Support for CALL_TYPE_REGISTER_HOLDING.

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
  • 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:

Update handling of binary sensors to support reading from holding registers (command 0x03).
Update prser to accept holding registers as input type for binary sensors
@home-assistant
Copy link

Hi Nippey

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Hey there @adamchengtkc, @janiversen, @vzahradnik, mind taking a look at this pull request as it has been labeled with an integration (modbus) you are listed as a code owner for? Thanks!

@janiversen
Copy link
Member

Will take a look later.

Copy link
Member

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

Test are missing, please amend the relevant test_file with tests that control the new functionality.

@@ -21,6 +21,8 @@
DataUpdateCoordinator,
)

from .const import CALL_TYPE_COIL, CALL_TYPE_DISCRETE, CALL_TYPE_REGISTER_HOLDING
Copy link
Member

Choose a reason for hiding this comment

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

Please solve the pylint/flake8 warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the heads-up!
Removed CALL_TYPE_REGISTER_HOLDING, as not implicitly used.

Comply with pylint output
As for Coil and Discrete, Holding should just evaluate the lowest bit of the register
@Nippey
Copy link
Contributor Author

Nippey commented Oct 17, 2022

Test are missing, please amend the relevant test_file with tests that control the new functionality.

I just found and checked the test file.
It left me rather confused.
Sorry, I will need some time to understand the structure 🙈

@Nippey
Copy link
Contributor Author

Nippey commented Oct 17, 2022

@janiversen:
I think I got it.
But I am not sure, if this is already all, the test should be doing.

Copy link
Member

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

All good apart from the CI error in isort, please solve.

@Nippey Nippey closed this Oct 18, 2022
@Nippey Nippey deleted the patch-1 branch October 18, 2022 07:01
@Nippey Nippey restored the patch-1 branch October 18, 2022 07:02
@Nippey Nippey reopened this Oct 18, 2022
@Nippey
Copy link
Contributor Author

Nippey commented Oct 18, 2022

Sorry, tried to rename the branch to something more meaningful.
But this closed the pull-request.
Keeping "patch-1".

Solved 'isort' error.

Copy link
Member

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

LGTM.

@janiversen janiversen merged commit 0e1fe4e into home-assistant:dev Oct 18, 2022
@Nippey Nippey deleted the patch-1 branch October 18, 2022 10:41
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants