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

Fix slave id equal to 0 #136263

Merged
merged 6 commits into from
Jan 23, 2025
Merged

Fix slave id equal to 0 #136263

merged 6 commits into from
Jan 23, 2025

Conversation

crug80
Copy link
Contributor

@crug80 crug80 commented Jan 22, 2025

Breaking change

Possible breaking change:
The configuration where the slave id or the device_address was not set, now assume a default value equal to 1 (instead of 0).
The situation can be easily fixed by an explicit declaration of the parameter.
Please note that the current bug has already broken those situations.

Proposed change

After having bumped pymodbus 3.7.x an hidden bug belonging the case where the slave id is set to 0 or not set at all became visible.
Before of that change, the underlying library pymodbus in case of missing slave id used a default value equal to 0. From the version 3.7.x, pymodbus changed the defaul slave it to 1, enforcing the fact that the slave id 0 is defined as broadcast according with the ModBus protocol.
This change within the library highlighted a previously hidden bug in the integration where a condition to check if the slave ID was None, actually intercepted even a slave id set to 0,
Fixing the bug, we align also the integration with the Modbus spec and with the pymodbus library setting the default value for the slave id to 1, instead of 0.

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:

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Can we add a test for this case?

../Frenck

@bdraco
Copy link
Member

bdraco commented Jan 23, 2025

Looks like the test was accidentally reverted in 8ac274f

@crug80
Copy link
Contributor Author

crug80 commented Jan 23, 2025

Looks like the test was accidentally reverted in 8ac274f

The test was based on the extra_attribute, so that test is not valid anymore after removing that attribute.

@bdraco
Copy link
Member

bdraco commented Jan 23, 2025

Looks like the test was accidentally reverted in 8ac274f

The test was based on the extra_attribute, so that test is not valid anymore after removing that attribute.

Got it. We should still be able to patch the lib to see whats its sending though instead of verifying the attribute

@frenck frenck added this to the 2025.1.4 milestone Jan 23, 2025
@bdraco
Copy link
Member

bdraco commented Jan 23, 2025

I'm a little behind here, but I think we don't need the milestone unless pymodus was already bumped in 2025.1

@crug80 is this issue only present on dev or does it affect stable?

@frenck
Copy link
Member

frenck commented Jan 23, 2025

I'm a little behind here, but I think we don't need the milestone unless pymodus was already bumped in 2025.1

@crug80 is this issue only present on dev or does it affect stable?

The linked issue report was against Home Assistant 2025.1, hence me considering this an patch worthy issue.

Ref: #134665

If unsure, we can wait, we are close to beta.

@bdraco
Copy link
Member

bdraco commented Jan 23, 2025

Chatted with @crug80

It looks like we need to adjust flexit with the same/similar change as well since it uses the modbus code path and it already has the issue since we bumped to pymodbus 3.8.3, however that can be a separate PR and this one should be ok to tag for a patch.

vol.Required(CONF_SLAVE): vol.All(int, vol.Range(min=0, max=32)),

modbus_slave = config.get(CONF_SLAVE)

@crug80
Copy link
Contributor Author

crug80 commented Jan 23, 2025

Chatted with @crug80

It looks like we need to adjust flexit with the same/similar change as well since it uses the modbus code path and it already has the issue since we bumped to pymodbus 3.8.3, however that can be a separate PR and this one should be ok to tag for a patch.

vol.Required(CONF_SLAVE): vol.All(int, vol.Range(min=0, max=32)),

modbus_slave = config.get(CONF_SLAVE)

Flexit is ok. CONF_ADDRESS is Required and it can assume only values from 0 to 32, so with this fix on modbus we made safe also for flexit use the 0 as slave.

@bdraco
Copy link
Member

bdraco commented Jan 23, 2025

FAILED tests/components/emulated_roku/test_binding.py::test_events_fired_properly - AssertionError: assert 'keypress' == 'keyup'

Test failure is unrelated

@bdraco bdraco merged commit 5e34bab into home-assistant:dev Jan 23, 2025
41 of 42 checks passed
@frenck
Copy link
Member

frenck commented Jan 23, 2025

Thanks both!

I'll ship this one tomorrow.

../Frenck

frenck pushed a commit that referenced this pull request Jan 24, 2025
@frenck frenck mentioned this pull request Jan 24, 2025
frenck added a commit that referenced this pull request Jan 24, 2025
Co-authored-by: Robert Resch <[email protected]>
Co-authored-by: J. Nick Koston <[email protected]>
Co-authored-by: Matt Doran <[email protected]>
Co-authored-by: G Johansson <[email protected]>
Co-authored-by: Makrit <[email protected]>
Co-authored-by: Claudio Ruggeri - CR-Tech <[email protected]>
Co-authored-by: Simon Lamon <[email protected]>
Co-authored-by: Yuxin Wang <[email protected]>
Co-authored-by: Åke Strandberg <[email protected]>
Co-authored-by: Paul Bottein <[email protected]>
Co-authored-by: Joost Lekkerkerker <[email protected]>
Co-authored-by: Klaas Schoute <[email protected]>
Fix slave id equal to 0 (#136263)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2025
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 Error for Slave ID 0 After Upgrade to Home Assistant 2025.1
3 participants