Skip to content

Add Modbus fan integration#48558

Merged
janiversen merged 3 commits intohome-assistant:devfrom
Lutemi:feature/modbus-fan
May 21, 2021
Merged

Add Modbus fan integration#48558
janiversen merged 3 commits intohome-assistant:devfrom
Lutemi:feature/modbus-fan

Conversation

@vzahradnik
Copy link
Copy Markdown
Contributor

Proposed change

This PR adds the Modbus Fan entity, which is based on Modbus Switch. At the moment, it supports only the turn_on() and turn_off() methods, but it can be extended.

We've discussed this feature in PR #33551. Feel free to take a look for reference.

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
modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502

    fans:
      - name: Fan1
        slave: 1
        coil: 13
      - name: Fan2
        slave: 2
        coil: 14
        scan_interval: 1
      - name: Fan3
        slave: 1
        register: 11

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

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link
Copy Markdown

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

Copy link
Copy Markdown
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 approve, but I hope you will still do something about the few comments I have.

Comment thread .coveragerc Outdated
Comment thread tests/components/modbus/test_modbus_fan.py Outdated
Comment thread homeassistant/components/modbus/fan.py Outdated
@vzahradnik
Copy link
Copy Markdown
Contributor Author

Update:

  • ModbusCoilFan and ModbusRegisterFan simplified even more; all functionality is handled by the Switch component
  • Unit tests extended; code coverage is on acceptable level now
  • When discovery_info is None, we print an error informing user to check the docs and fix the config

@janiversen, @yury-sannikov please take another look when you'll have some time. Thanks!

Copy link
Copy Markdown
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.

All good, one small adjustment it is all green.

Comment thread homeassistant/components/modbus/fan.py Outdated
@janiversen
Copy link
Copy Markdown
Member

And look how fast you got a review :-) just thinking a bit about #48544

@vzahradnik
Copy link
Copy Markdown
Contributor Author

@janiversen I got you one comment, which is still pending. Comment on that and I'll approve the change.

Copy link
Copy Markdown
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 like this one, that is a much needed feature.

Copy link
Copy Markdown
Contributor

@yury-sannikov yury-sannikov 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 to me.
I would add some tests that the fan is actually turning on/off, like here, however, it's up to you, since this PR just uses Coil and Register switch

@vzahradnik
Copy link
Copy Markdown
Contributor Author

I think that covering the Switch.py logic would be sufficient. And if we have those tests, we can always copy here.

@janiversen
Copy link
Copy Markdown
Member

I agree with @vzahradnik. Our test cases should in principle only test untested code, we do not want to duplicate test cases just to show fan have the same tests as switch.

@janiversen I got you one comment, which is still pending. Comment on that and I'll approve the change.

?? I think I missed something here, there are no comments on #48544

@vzahradnik
Copy link
Copy Markdown
Contributor Author

Code updated to reflect latest Switch changes.

Comment thread homeassistant/components/modbus/fan.py Outdated
@vzahradnik
Copy link
Copy Markdown
Contributor Author

Fan code decoupled from Switch. The code is almost exact replica of Switch, including unit tests.

Copy link
Copy Markdown
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.

Looks good to me.

Copy link
Copy Markdown
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.

Looks good to me.

Comment thread homeassistant/components/modbus/fan.py
Comment thread homeassistant/components/modbus/fan.py Outdated
Comment thread homeassistant/components/modbus/fan.py Outdated
Comment thread homeassistant/components/modbus/fan.py Outdated
Comment thread homeassistant/components/modbus/const.py Outdated
@janiversen
Copy link
Copy Markdown
Member

@vzahradnik when you update, you will see that class modbusHub have changed, you now need to call async_pymodbus_call(.... CALL_TYPE*) see e.g. cover.py
The other update is that all platforms are now async.
If you do the rebase to resolve the merge conflict, and resolve the requests open, I can give you a hand, to get this ready.

@janiversen janiversen self-assigned this May 20, 2021
Copy link
Copy Markdown
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!

Comment thread homeassistant/components/modbus/fan.py Outdated
Comment thread homeassistant/components/modbus/fan.py Outdated
@janiversen janiversen merged commit c979101 into home-assistant:dev May 21, 2021
@github-actions github-actions Bot locked and limited conversation to collaborators May 22, 2021
@vzahradnik vzahradnik deleted the feature/modbus-fan branch May 22, 2021 10:34
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.

5 participants