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

Add modbus sensor string data_type #35269

Merged
merged 10 commits into from May 8, 2020
Merged

Add modbus sensor string data_type #35269

merged 10 commits into from May 8, 2020

Conversation

bradkeifer
Copy link
Contributor

@bradkeifer bradkeifer commented May 5, 2020

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml
# Shows the current date and time. The date and time is updated continuously.
# The clock does not begin counting until a setting different from default has been made in parameter 0-70 Date and Time.
# This is a 16 character string.
    - name: D1 Date Time Readout
      hub: hub1
      slave: 1 
      register: 889
      count: 8
      data_type: string

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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

Adds support for a string data_type. This allows the reading of holding registers that contain ascii string data
@homeassistant
Copy link
Contributor

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!

@probot-home-assistant probot-home-assistant bot added new-feature small-pr PRs with less than 30 lines. labels May 5, 2020
@MartinHjelmare MartinHjelmare changed the title modbus sensor: string data_type Add modbus sensor string data_type May 5, 2020
Copy link
Member

@MartinHjelmare MartinHjelmare left a 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

@bradkeifer
Copy link
Contributor Author

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?

@MartinHjelmare
Copy link
Member

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
@bradkeifer
Copy link
Contributor Author

Thanks Martin. I have done that and I think all is good for review now. Sorry for my mistake.

@MartinHjelmare
Copy link
Member

@janiversen do you have time to review?

@probot-home-assistant
Copy link

Hey there @adamchengtkc, @janiversen, mind taking a look at this pull request as its been labeled with a integration (modbus) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

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.

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:
Copy link
Member

@janiversen janiversen May 6, 2020

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.

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@janiversen
Copy link
Member

@MartinHjelmare review done, are there a reason why #34679 and #34678 which both fixes issues are hanging ?

@MartinHjelmare
Copy link
Member

No special reason, we just have too many PRs and too little time to always triage effectively.

Copy link
Member

@MartinHjelmare MartinHjelmare left a 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.

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.

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.

@MartinHjelmare MartinHjelmare merged commit 4663845 into home-assistant:dev May 8, 2020
@lock lock bot locked and limited conversation to collaborators May 21, 2020
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.

Modbus integration: TypeError when trying to read ascii string with custom data_type
4 participants