Skip to content

Load/unload locative entities correctly between component and platform#20498

Merged
fabaff merged 4 commits into
home-assistant:devfrom
rohankapoorcom:locative-unload
Jan 27, 2019
Merged

Load/unload locative entities correctly between component and platform#20498
fabaff merged 4 commits into
home-assistant:devfrom
rohankapoorcom:locative-unload

Conversation

@rohankapoorcom
Copy link
Copy Markdown
Member

@rohankapoorcom rohankapoorcom commented Jan 27, 2019

Description:

  • Move locative device_tracker to be inside the component
  • Switch locative device_tracker platform to use async_setup_entry/async_unload_entry
  • Switch locative component to forward entries to the platform for setup/teardown
  • Add unit test for testing load/unload of the forwarded entries. This test is marked xfail (and will fail) because the device_tracker component does not support unloading entities yet.

Relates to #20237. Like #20448 but for locative.

This came out of a couple of discussions with @MartinHjelmare #20083 (comment) and #20079 (comment).

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

"""Unload a config entry."""
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])

hass.async_create_task(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can await the coroutine directly. We don't need to create a task.

hass.components.webhook.async_register(
DOMAIN, 'Locative', entry.data[CONF_WEBHOOK_ID], handle_webhook)

await hass.config_entries.async_forward_entry_setup(entry, DEVICE_TRACKER)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, wrong line was changed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here we should use create task.

@rohankapoorcom
Copy link
Copy Markdown
Member Author

rohankapoorcom commented Jan 27, 2019

Doing too many things at once, should be the correct coroutine awaited this time. Thanks for catching.

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.

Great!

@MartinHjelmare
Copy link
Copy Markdown
Member

Can be merged when build passes.

@fabaff fabaff merged commit 0c87fb4 into home-assistant:dev Jan 27, 2019
@ghost ghost removed the in progress label Jan 27, 2019
@rohankapoorcom rohankapoorcom deleted the locative-unload branch January 27, 2019 22:50
fredrike pushed a commit to fredrike/home-assistant that referenced this pull request Jan 30, 2019
home-assistant#20498)

* Embed device_tracker in locative

* Load/unload locative entities correctly between component and platform

* Await the coroutine directly

* Await the correct coroutine
@balloob balloob mentioned this pull request Feb 6, 2019
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