Skip to content

Enable Modbus Climate / HVAC on/off to use the coil instead of the register(s)#135657

Merged
bdraco merged 12 commits intohome-assistant:devfrom
illia-piskurov:coil_onoff_support
Feb 1, 2025
Merged

Enable Modbus Climate / HVAC on/off to use the coil instead of the register(s)#135657
bdraco merged 12 commits intohome-assistant:devfrom
illia-piskurov:coil_onoff_support

Conversation

@illia-piskurov
Copy link
Copy Markdown
Contributor

@illia-piskurov illia-piskurov commented Jan 15, 2025

Proposed change

The changes are necessary to add support for a range of devices such as the Haier range of air conditioners. For example, the Modbus Haier YCJ-A002 uses coil to turn on and off:

image

Also, there has already been an attempt and need for another person to add this functionality at this point: #121680

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:

@illia-piskurov
Copy link
Copy Markdown
Contributor Author

Now I haven't written tests and documentation yet, because I want more experienced people to tell me if the code I wrote will work in this form. It has already been working for half a year in my production.

Copy link
Copy Markdown
Contributor

@crug80 crug80 left a comment

Choose a reason for hiding this comment

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

Preliminary review.
If I have correctly understood the need, this code is not able to check possible conflicts among the actual configuration (using the registers) and the new one (with coils).
As it is, an user can set a register value for both of the parameters, causing 2 simultaneous writes. the first one will use the function code 0x06 or 0x10 and in case coil is enable, it will fail. The second one will use the function code 0x1.
You have the same behaviour for a reading.

@illia-piskurov
Copy link
Copy Markdown
Contributor Author

Preliminary review. If I have correctly understood the need, this code is not able to check possible conflicts among the actual configuration (using the registers) and the new one (with coils). As it is, an user can set a register value for both of the parameters, causing 2 simultaneous writes. the first one will use the function code 0x06 or 0x10 and in case coil is enable, it will fail. The second one will use the function code 0x1. You have the same behaviour for a reading.

I think that the old configurations will not be broken because I have not changed anything in the existing code for the registers. I used vol.Exclusive to make it impossible to specify a register and a coil at the same time.

@crug80
Copy link
Copy Markdown
Contributor

crug80 commented Jan 19, 2025

I think that the old configurations will not be broken because I have not changed anything in the existing code for the registers. I used vol.Exclusive to make it impossible to specify a register and a coil at the same time.

My bad, I didn't see Exclusive.
Please add and run local tests to encourage a full review.

@illia-piskurov illia-piskurov requested a review from crug80 January 20, 2025 14:58
@illia-piskurov
Copy link
Copy Markdown
Contributor Author

I think that the old configurations will not be broken because I have not changed anything in the existing code for the registers. I used vol.Exclusive to make it impossible to specify a register and a coil at the same time.

My bad, I didn't see Exclusive. Please add and run local tests to encourage a full review.

Added tests

@crug80
Copy link
Copy Markdown
Contributor

crug80 commented Jan 24, 2025

Please:

  1. align the PR with current dev branch (possible conflicts)
  2. write the documentation and link it to the PR
  3. Uncheck the following fields. No changes on those files in this PR
    immagine

@illia-piskurov
Copy link
Copy Markdown
Contributor Author

Please:

  1. align the PR with current dev branch (possible conflicts)
  2. write the documentation and link it to the PR
  3. Uncheck the following fields. No changes on those files in this PR
    immagine

Docs: home-assistant/home-assistant.io#37082

@illia-piskurov
Copy link
Copy Markdown
Contributor Author

Please:

  1. align the PR with current dev branch (possible conflicts)
  2. write the documentation and link it to the PR
  3. Uncheck the following fields. No changes on those files in this PR
    immagine

All done

Comment thread homeassistant/components/modbus/climate.py
Copy link
Copy Markdown
Contributor

@crug80 crug80 left a comment

Choose a reason for hiding this comment

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

It seems missing a test to validate the climate update using on/off by coil.

@illia-piskurov illia-piskurov requested a review from crug80 January 27, 2025 09:41
@illia-piskurov
Copy link
Copy Markdown
Contributor Author

It seems missing a test to validate the climate update using on/off by coil.

Done

Comment thread tests/components/modbus/test_climate.py
@illia-piskurov illia-piskurov requested a review from crug80 January 27, 2025 17:40
Comment thread homeassistant/components/modbus/climate.py Outdated
Comment thread homeassistant/components/modbus/climate.py
Comment thread homeassistant/components/modbus/climate.py
@bdraco bdraco added the smash Indicator this PR is close to finish for merging or closing label Feb 1, 2025
@bdraco bdraco merged commit 4cab773 into home-assistant:dev Feb 1, 2025
@bdraco
Copy link
Copy Markdown
Member

bdraco commented Feb 1, 2025

Thanks @illia-piskurov

zxdavb pushed a commit to zxdavb/hass that referenced this pull request Feb 2, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed integration: modbus new-feature Quality Scale: No score smash Indicator this PR is close to finish for merging or closing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants