-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Use "device_id" instead of "slave" in modbus integration #150200
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
Conversation
epenet
left a comment
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.
Also... tests are failing
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
codecoverage is unhappy even i improved the grade adding a new test. Dont know why ? |
|
A good needed fix, it was fixed in my version quite a while ago (device_id have been available since Pymodbus v3.8). Coverage probably due to the fact that you changed tests, and thus coverage starts counting. |
|
@janiversen : i changed the tests because codecoverage asked me to 😀 so i thought it would be gratefull as i tried to cover the lines pointed as uncovered. But i maybe misunderstood |
tests/components/modbus/test_init.py
Outdated
| async def test_pb_service_return_None( | ||
| hass: HomeAssistant, | ||
| do_write, | ||
| caplog: pytest.LogCaptureFixture, | ||
| mock_modbus_with_pymodbus, | ||
| ) -> None: | ||
| """Run test when pymodbus returns None.""" | ||
| func_name = { |
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.
Okay so what does this actually test? Like it returns None, but what does the user notice from this?
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.
It is called code coverage !!!
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.
No this is touching code, I am asking what it is testing, because okay cool pymodbus returns None, but what else should it return? What behavior do we expect when it returns None or what do we expect when it does not return None?
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.
it should return a modbus message cf https://github.com/pymodbus-dev/pymodbus/blob/9e22049439240a89f159a2aafe65137121201ce7/pymodbus/pdu/pdu.py#L12
not sure it can return None in practise, because if there is no gateway, there is an exception returned
cf https://www.simplymodbus.ca/exceptions.htm
actually it was to cover those lines :
| if not result: |
but I removed this "unfortunate" test
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.
Oh I am not saying it's bad to test this, I think we have to look a bit deeper on what happens when that happens, the function you now link also returns None when this code path is taken. But what will happen if that returns None?
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.
well, I think it never return None in fact, but I am not sure.
Codecoverage is tricky, you introduced a new attribute, and that changes the coverage calculation. I believe the whole PR would have caused less problems if you just had changed the text in const.py, and not made a new attribute....it might not be the cleanest way, but since the modbus integration still have a lot of slave references it is also not wrong. |
|
ATTR_* is normally reserved for service call attributes, so the service calls should be adjusted accordingly. |
|
This is by far the easiest solution: |
|
We can also just do |
Yes I actually did that, but defined the const in modbus.py in order not to "upset" coverage etc. |
crug80
left a comment
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.
Ugly, but needed to have a modbus component working again, bypassing code coverage.
|
Changing _ATTR_SLAVE was an ironic joke from my side !!! I am sorry that it was taken seriously !! I honestly thought people changing the code, would look at the consequences. Clearly changing _ATTR_SLAVE is a VERY breaking change ! every service call needs to be changed !! The right move it is to make a constant for "device_id", but ONLY for communication with the Pymodbus library, later the service calls etc could be changed, but that is a breaking change, so ABSOLUTELY not for now. Had it not been for the disapproval of my work as a developer, I had already submitted a PR remedying the problem (which is very serious). This repo https://github.com/pymodbus-dev/homeassistant_modbus contains a HACS version which works and currently have solved a number of the other outstanding bugs. I expect within a couple of weeks to have solved all outstanding issues, which are not related to wrong configurations. |
Breaking change
Proposed change
As pymodbus version has been bumped to 3.11.0, slave is not accepted as a argument and has to be replaced ,by device_id
see https://github.com/pymodbus-dev/pymodbus/blob/dev/API_changes.rst
Type of change
Additional information
Checklist
ruff format 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.To help with the load of incoming pull requests: