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
Add modbus sensor string data_type #35269
Conversation
Adds support for a string data_type. This allows the reading of holding registers that contain ascii string data
modbus sensor: string data_type
Hi @bradkeifer, 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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changed files are incorrectly placed.
The modbus sensor module is here:
https://github.com/home-assistant/core/blob/dev/homeassistant/components/modbus/sensor.py
Thanks Martin. I am new to both GitHub and Home Assistant. How do I move the changed files to the correct location in the repository? |
Copy the changed files on top of the existing files and commit the changes. Then remove the files here and commit again. Then push. |
Fingers crossed that I am putting these file in the correct location this time
Thanks Martin. I have done that and I think all is good for review now. Sorry for my mistake. |
@janiversen do you have time to review? |
Hey there @adamchengtkc, @janiversen, mind taking a look at this pull request as its been labeled with a integration ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I miss tests in core/tests/components/modbus.
self._value = str(val) | ||
if self._precision > 0: | ||
self._value += "." + "0" * self._precision | ||
if self._data_type != DATA_TYPE_STRING: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems complicated especially since “int” is the most common form.
Now that we have data_type it should be used instead of isinstance() please.
Sorry for the comment edits, I managed to confuse myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @janiversen - Thanks for your prompt review. Is there anything you would like me to action at the moment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do the change of isinstance() but it would be real nice to have test cases for the string type. See core/tests/component/modbus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great to me. I am new to python, HA and GitHub, so I might make some mistakes along the way. I'll read up about test cases and give it a go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a commit for a test of the new string data_type
@MartinHjelmare review done, are there a reason why #34679 and #34678 which both fixes issues are hanging ? |
No special reason, we just have too many PRs and too little time to always triage effectively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Codeowner should approve before we merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding tests.
All looks good to me.
One small detail:
for future PR, please do not merge dev, when catching up, please follow this way:
https://developers.home-assistant.io/docs/development_catching_up/
(this is common for most opwn source projects)
Thanks for the work.
Proposed change
This change enables a string data_type to provide support for reading holding registers that contain ascii text. The length of text to be read is based on the count of holding registers read.
Type of change
Example entry for
configuration.yaml
:Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale: