Skip to content

Add DSMR config options for EasyMeter/Q3D#63669

Merged
frenck merged 6 commits into
home-assistant:devfrom
Aeroid:configQ3D
Jan 10, 2022
Merged

Add DSMR config options for EasyMeter/Q3D#63669
frenck merged 6 commits into
home-assistant:devfrom
Aeroid:configQ3D

Conversation

@Aeroid
Copy link
Copy Markdown
Contributor

@Aeroid Aeroid commented Jan 8, 2022

Proposed change

Adding support dsmr EasyMeter Q3D
(re-submitting expired PR #60088, apologies)

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

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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • 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 @RobBie1221, @frenck, mind taking a look at this pull request as it has been labeled with an integration (dsmr) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@RobBie1221
Copy link
Copy Markdown
Contributor

As mentioned in the comment of #60088 you need to add tests for the config flow because it requires 100% coverage. It would also be good to add a smoke test to test_sensor.py to test setup with the new option.

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

As per comment above, please add tests 👍

@RobBie1221
Copy link
Copy Markdown
Contributor

#63529 contains a good example of how to extend tests if you need some guidance.

@MartinHjelmare MartinHjelmare changed the title Adding DSMR config options for EasyMeter/Q3D Add DSMR config options for EasyMeter/Q3D Jan 8, 2022
@Aeroid
Copy link
Copy Markdown
Contributor Author

Aeroid commented Jan 8, 2022

Added a test for a Q3D telegram. Given the very minimal changes expanding the protocol version just by one entry, the test is not really improving coverage. But this was my first test ever written. So I hope it's sufficient. Otherwise I would appreciate details of how I may improve the PR to an acceptable level.

@RobBie1221
Copy link
Copy Markdown
Contributor

The test you added is fine for the smoke test. It doesn't improve coverage that much, but it ensures setting up the integration with the new option will work (and will keep working).

The config flow actually needs 100% coverage, lines 49 and 50 you added in config_flow.py are untested.

To test these, you can reuse a lot. So add in below file/function a statement to add for Q3D the equipment identifier :

async def connection_factory(*args, **kwargs):
"""Return mocked out Asyncio classes."""
if args[1] == "5L":
protocol.telegram = {
LUXEMBOURG_EQUIPMENT_IDENTIFIER: CosemObject(
[{"value": "12345678", "unit": ""}]
),
EQUIPMENT_IDENTIFIER_GAS: CosemObject(
[{"value": "123456789", "unit": ""}]
),
}
if args[1] == "5S":
protocol.telegram = {
P1_MESSAGE_TIMESTAMP: CosemObject([{"value": "12345678", "unit": ""}]),
}
return (transport, protocol)

Then copy below function, name it something like test_setup_q3d and change dsmr_version to Q3D, that will test the the missing lines above.

async def test_setup_serial(com_mock, hass, dsmr_connection_send_validate_fixture):

@RobBie1221
Copy link
Copy Markdown
Contributor

RobBie1221 commented Jan 8, 2022

@frenck I noticed coverage of config_flow.py dropped below 100% here: #61008. The import test was actually testing also connection validation for Luxembourgh and Swedish meters. We probably need to fix that in another pull?
Anyway, just with adding tests for the added code here, we won't reach 100% coverage.

@Aeroid
Copy link
Copy Markdown
Contributor Author

Aeroid commented Jan 9, 2022

The test you added is fine for the smoke test. It doesn't improve coverage that much, but it ensures setting up the integration with the new option will work (and will keep working).

The config flow actually needs 100% coverage, lines 49 and 50 you added in config_flow.py are untested.

To test these, you can reuse a lot. So add in below file/function a statement to add for Q3D the equipment identifier :

async def connection_factory(*args, **kwargs):
"""Return mocked out Asyncio classes."""
if args[1] == "5L":
protocol.telegram = {
LUXEMBOURG_EQUIPMENT_IDENTIFIER: CosemObject(
[{"value": "12345678", "unit": ""}]
),
EQUIPMENT_IDENTIFIER_GAS: CosemObject(
[{"value": "123456789", "unit": ""}]
),
}
if args[1] == "5S":
protocol.telegram = {
P1_MESSAGE_TIMESTAMP: CosemObject([{"value": "12345678", "unit": ""}]),
}
return (transport, protocol)

Then copy below function, name it something like test_setup_q3d and change dsmr_version to Q3D, that will test the the missing lines above.

async def test_setup_serial(com_mock, hass, dsmr_connection_send_validate_fixture):

I actually tried something like that yesterday, playing around with the version in the existing test_setup functions. Following your tipps I'm running into the same problem where I gave up yesterday: As soon as config_flow lines 48 (for 5L) or 50 (for Q3D) get coverage I get AssertionErrors: assert 'form' == 'create_entry' in the final assertation. Gone when I change back to "5", "5S", or "2.2".

Couldn't get to the bottom of it. Should I commit the half baked code for visibility?

@RobBie1221
Copy link
Copy Markdown
Contributor

Couldn't get to the bottom of it. Should I commit the half baked code for visibility?

Yes, I'll check what's wrong.

Copy link
Copy Markdown
Contributor

@RobBie1221 RobBie1221 left a comment

Choose a reason for hiding this comment

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

This should fix it. Don't forget to add import in conftest.py.

Just a general question looking at the obis references, what is the difference between Q3_EQUIPMENT_IDENTIFIER and Q3_EQUIPMENT_SERIALNUMBER? Is the equipment identifier unique for your device? Or should we actually use here serial number?

Furthermore, you need to add a documentation pull request. I saw you had it in your initial PR. You can reopen that one or make a new one (maybe easier because the original needs to be rebased on next).

Comment thread tests/components/dsmr/conftest.py Outdated
Comment on lines +129 to +132
entry_data = {
"port": port.device,
"dsmr_version": "Q3D",
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
entry_data = {
"port": port.device,
"dsmr_version": "Q3D",
}
entry_data = {
"port": port.device,
"dsmr_version": "Q3D",
"serial_id": "12345678",
"serial_id_gas": None,
}

Comment thread tests/components/dsmr/test_config_flow.py Outdated
@Aeroid
Copy link
Copy Markdown
Contributor Author

Aeroid commented Jan 9, 2022

They are more or less the same. S/N has a prefix.

Q3D_EQUIPMENT_IDENTIFIER = r'\d-\d:0.0.0.+?\r\n' # Logical device name
Q3D_EQUIPMENT_SERIALNUMBER = r'\d-\d:96.1.255.+?\r\n' # Device Serialnumber

telegram: /ESY5Q3DA1004 V3.04

1-0:0.0.0255(1336001560)
1-0:1.8.0
255(00032653.9579389kWh)
1-0:21.7.0
255(000050.56W)
1-0:41.7.0
255(000000.00W)
1-0:61.7.0
255(000000.00W)
1-0:1.7.0
255(000050.56W)
1-0:96.5.5
255(80)
0-0:96.1.255*255(1ESY1336001560)
!

Aeroid and others added 3 commits January 9, 2022 13:11
Co-authored-by: Rob Bierbooms <mail@robbierbooms.nl>
Co-authored-by: Rob Bierbooms <mail@robbierbooms.nl>
@Aeroid
Copy link
Copy Markdown
Contributor Author

Aeroid commented Jan 9, 2022

Happy to add doc.

The test should be working now and also included a 5L test to bump up converage by another %.

@Aeroid
Copy link
Copy Markdown
Contributor Author

Aeroid commented Jan 9, 2022

Doc PR is home-assistant/home-assistant.io#21113

Please let me know if I can do anything else.

@RobBie1221
Copy link
Copy Markdown
Contributor

The link points to wrong repo, you should copy the link from home-assistant.io github repo. Also, add it to the PR description in the template.

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

Nice! Thanks, @Aeroid 👍

@frenck frenck merged commit 0f2e2ae into home-assistant:dev Jan 10, 2022
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 11, 2022
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.

4 participants