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

Add additional tests for Matter update entity #122575

Merged
merged 7 commits into from
Aug 20, 2024

Conversation

agners
Copy link
Member

@agners agners commented Jul 25, 2024

Breaking change

Proposed change

Extend test coverage for Matter update entity. This includes tests for error handling and state store/restore.

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

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

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:

Extend test coverage for Matter update entity. This includes tests for
error handling and state store/restore.
@home-assistant
Copy link

Hey there @home-assistant/matter, mind taking a look at this pull request as it has been labeled with an integration (matter) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of matter can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign matter Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@jvmahon

This comment was marked as off-topic.

)


async def test_update_state_restore(
Copy link
Member

@MartinHjelmare MartinHjelmare Jul 25, 2024

Choose a reason for hiding this comment

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

We have mock_restore_cache_with_extra_data to help test loading of restored state.

Example:

async def test_update_entity_partial_restore_data_2(
hass: HomeAssistant,
client,
climate_radio_thermostat_ct100_plus_different_endpoints,
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test second scenario where update entity has partial restore data."""
mock_restore_cache_with_extra_data(
hass,
[
(
State(
UPDATE_ENTITY,
STATE_ON,
{
ATTR_INSTALLED_VERSION: "10.7",
ATTR_LATEST_VERSION: "10.8",
ATTR_SKIPPED_VERSION: None,
},
),
{"latest_version_firmware": None},
)
],
)
entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"})
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(UPDATE_ENTITY)
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes[ATTR_SKIPPED_VERSION] is None
assert state.attributes[ATTR_LATEST_VERSION] is None

Copy link
Member Author

Choose a reason for hiding this comment

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

I took inspiration from test_restore_sensor_save_state for this test.

From what I can tell mock_restore_cache_with_extra_data would only allow to test the restore side, but not really the saving side (making sure the update information makes it into the extra data).

The way I wrote the test is really what I (the user) is interested in: Make sure the update information survives a restart.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't mean that we should remove this test. But we need to add another test that uses that helper and tests the loading.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, yeah seems sensible to test the loading side only, to make sure this remains compatible/correct.

We don't use much of the extra data currently, essentially we just use it to get the software update integer version to pass it to the update call. I guess it could be debated if the implementation of the Matter update entity should make use more of the extra data directly 🤔 But that would need an update entity change too.

Anyways, the current test really tests what extra data is used now, so IMHO this is already a good step forward in test coverage.

tests/components/matter/test_update.py Outdated Show resolved Hide resolved
tests/components/matter/test_update.py Outdated Show resolved Hide resolved
@MartinHjelmare
Copy link
Member

@jvmahon please open an issue instead.

@MartinHjelmare
Copy link
Member

Looks like two errors and the polling mechanism are still uncovered.

@marcelveldt
Copy link
Member

@jvmahon like Martin already noted: don't start commenting on random/unrelated PR's and/or issue reports, create your own issue report if you find something. I know you are trying to be helpful in these cases but please respect our developer workflow.

To quickly answer your message about that P2 sensor. We are in fact checking (server side) for "software version valid" but Aqara did not set that. They just did on our request so probably your device is now bricked because you updated it right before that. NOTE: Maybe its not bricked and you just need to to reset and recommission it.

@MartinHjelmare MartinHjelmare marked this pull request as draft August 5, 2024 19:30
@agners agners marked this pull request as ready for review August 8, 2024 10:42
tests/components/matter/test_update.py Outdated Show resolved Hide resolved
tests/components/matter/test_update.py Outdated Show resolved Hide resolved
tests/components/matter/test_update.py Outdated Show resolved Hide resolved
tests/components/matter/test_update.py Outdated Show resolved Hide resolved
tests/components/matter/test_update.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft August 18, 2024 13:46
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@agners agners requested a review from joostlek August 20, 2024 09:21
@agners agners marked this pull request as ready for review August 20, 2024 09:21
We check device updates every 12h currently. Use the freezer to skip
time.

Still add a test which uses the service call to make sure this works
too.
@joostlek joostlek merged commit be25561 into home-assistant:dev Aug 20, 2024
26 checks passed
@agners agners deleted the extend-matter-update-entity-tests branch August 20, 2024 10:24
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2024
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