Skip to content

Add test coverage for modbus switch (coil part)#40696

Merged
ctalkington merged 4 commits intohome-assistant:devfrom
janiversen:test2_modbus
Oct 1, 2020
Merged

Add test coverage for modbus switch (coil part)#40696
ctalkington merged 4 commits intohome-assistant:devfrom
janiversen:test2_modbus

Conversation

@janiversen
Copy link
Copy Markdown
Member

Breaking change

Proposed change

Add test cases for modbus switch (coil), this includes making the test harness ready for
more complex devices.

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)
  • [x ] Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • [ x] The code change is tested and works locally.
  • [ x] Local tests pass. Your PR cannot be merged unless tests pass
  • [ x] There is no commented out code in this PR.
  • [ x] I have followed the development checklist
  • [x ] The code has been formatted using Black (black --fast homeassistant tests)
  • [ x] 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:

push entity_id to conftest, to make it common for all devices.

Add device to base_setup.
@probot-home-assistant
Copy link
Copy Markdown

Hey there @adamchengtkc, @vzahradnik, 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)

@janiversen
Copy link
Copy Markdown
Member Author

@vzahradnik This PR is the reason I did not ask for test cases in your latest PR (light/fan), I tested with your PR and did not see any conflicts.

I am working on a more extensive test of switch (with verify etc), but currently it conflicts with your PR, so I isolated this part.

I look forward to the moment where we have test cases for all devices.

@vzahradnik
Copy link
Copy Markdown
Contributor

@janiversen I look forward to the moment, where we have:

  • Reasonable configuration structure on a single place
  • Asynchronous Pymodbus
  • Extensive test coverage
  • Support for Data Entry Flow, e.g., defining Modbus entities over GUI
  • At least a bronze certification

Lots of work ahead of us.

@janiversen
Copy link
Copy Markdown
Member Author

janiversen commented Sep 28, 2020

Yes, but together we will manage. I had your list apart from the data flow on my list.

If you want to and have time, please continue with the configuration and make a “reasonable central configuration”.

Async modbus now works for tcp (both normal and rtuovertcp) but there are still problems with serial. I will shortly bump the pymodbus version (2.3.0 -> 2.4.0) as a preparation.

Btw. Bronze no longer exist, but we are close on Silver https://developers.home-assistant.io/docs/integration_quality_scale_index/

@vzahradnik
Copy link
Copy Markdown
Contributor

vzahradnik commented Sep 28, 2020

make a “reasonable central configuration”

OK, after I get my open PRs merged, I will continue with that. My idea was already proposed as a breaking change inside Cover.

My idea is to have a structure like this:

modbus:
  hubs:
    - name: hub1
      type: tcp
      host: 127.0.0.1
      port: 5020

  covers:
    - name: Door1
      slave: 1
      ...

  sensors:
    - name: Sensor1
      ...

  binary_sensors:
    - name: BinarySensor1
      ...

  climates:
    - name: Climate1
      ...

  fans:
    - name: Fan1
      ...

  lights:
    - name: Light1
      ...

This way, we'll list all the Covers, etc., on a single place. At the moment, you have to define a list for each Modbus hub separately. Also, while at it, I'll review the defaults, and change some of them. Like I discussed in PR #37546, hub name should be a mandatory parameter. Now we have problems because of this.

@janiversen
Copy link
Copy Markdown
Member Author

I like that config, however I am not sure I understand how you will manage to list e.g. all Covers in one place, if you have multiple hubs ??

Change defaults is something I have wanted for a while, especially hub name, so please go ahead.

@janiversen
Copy link
Copy Markdown
Member Author

@vzahradnik I have opened issue #40705, so lets continue the discussion there.

Can you please review this PR.

@vzahradnik
Copy link
Copy Markdown
Contributor

Sure, I'll try to do it tomorrow.

@ctalkington ctalkington self-requested a review September 29, 2020 03:51
@vzahradnik
Copy link
Copy Markdown
Contributor

@janiversen your code looks good to me. In theory, we should be able to re-use switch tests for Fan and Light.

One question: how does the scan_interval code work? After we change the config to new format, I'll need to rework all components to handle scan_interval internally (see Cover as an example). Anyway, it shouldn't be difficult to adapt if necessary.

@ctalkington
Copy link
Copy Markdown
Contributor

@janiversen the coverage could be improved if we want to enable testing of coverage. Im seeing that your tests only cover about 47% of switch code.

https://codecov.io/gh/home-assistant/core/pull/40696/tree/homeassistant/components/modbus

@janiversen
Copy link
Copy Markdown
Member Author

It is correct, which is why the title states (coil) the whole register part is coming. I pushed this part of the test coverage to enable the new devices cover/fan/light to easily add some test cases.

I am working on the rest and hope to push a new PR with that in cerca 2 weeks.

@ctalkington
Copy link
Copy Markdown
Contributor

ctalkington commented Oct 1, 2020

ok i see. Ive disabled switch coverags until round 2. Ill merge this once tests finish from that change.

@janiversen
Copy link
Copy Markdown
Member Author

Thanks a lot I saw your commit, which is why I did not add the same commit.

@ctalkington ctalkington merged commit 639c864 into home-assistant:dev Oct 1, 2020
@janiversen janiversen deleted the test2_modbus branch October 1, 2020 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants