Skip to content

Ignore cloudhook already removed in mobile app#111122

Merged
frenck merged 3 commits into
home-assistant:devfrom
joostlek:mobile-app-webhook
Feb 22, 2024
Merged

Ignore cloudhook already removed in mobile app#111122
frenck merged 3 commits into
home-assistant:devfrom
joostlek:mobile-app-webhook

Conversation

@joostlek
Copy link
Copy Markdown
Member

Proposed change

Ignore cloudhook already removed in mobile app

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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown
Contributor

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

Code owner commands

Code owners of mobile_app 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 mobile_app 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.

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.

Please add a test.

@home-assistant
Copy link
Copy Markdown
Contributor

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.

@home-assistant home-assistant Bot marked this pull request as draft February 22, 2024 07:59
@joostlek joostlek added this to the 2024.2.3 milestone Feb 22, 2024
@joostlek
Copy link
Copy Markdown
Member Author

So I added the test, but there is a try catch in the config_entries, which prohibits me from actually testing the raise:

try:
await component.async_remove_entry(hass, self)
except Exception: # pylint: disable=broad-except
_LOGGER.exception(
"Error calling entry remove callback %s for %s",
self.title,
integration.domain,
)

This means that the following test:

@pytest.mark.parametrize("exception", (None, CloudNotAvailable, ValueError))
async def test_remove_cloudhook(
    hass: HomeAssistant,
    hass_admin_user: MockUser,
    exception: Exception | None,
) -> None:
    """Test removing a cloud hook when config entry is removed."""

    async def additional_steps(
        config_entry: ConfigEntry, mock_create_cloudhook: Mock, cloud_hook: str
    ) -> None:
        webhook_id = config_entry.data[CONF_WEBHOOK_ID]
        assert config_entry.data[CONF_CLOUDHOOK_URL] == cloud_hook
        with patch(
            "homeassistant.components.cloud.async_delete_cloudhook",
            side_effect=exception,
        ) as delete_cloudhook:
            await hass.config_entries.async_remove(config_entry.entry_id)
            await hass.async_block_till_done()
            delete_cloudhook.assert_called_once_with(hass, webhook_id)

    await _test_create_cloud_hook(hass, hass_admin_user, {}, True, additional_steps)

Works both on this branch and on dev, which is incorrect as it should fail on dev.

image

Are there better ways to check if the exception is surpressed, other than using a caplog?

@MartinHjelmare
Copy link
Copy Markdown
Member

No, caplog seems to be the only thing we can use, since nothing happens after the call that will raise.

@joostlek joostlek marked this pull request as ready for review February 22, 2024 09:23
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.

Thanks, @joostlek 👍

../Frenck

@frenck frenck dismissed MartinHjelmare’s stale review February 22, 2024 10:19

Comment addressed

@frenck frenck merged commit 92c8c4b into home-assistant:dev Feb 22, 2024
@joostlek joostlek deleted the mobile-app-webhook branch February 22, 2024 10:26
@frenck frenck mentioned this pull request Feb 22, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 23, 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.

Cannot remove broken device / configuration entry

3 participants