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

Enable config flow for html5 #112806

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from

Conversation

alexyao2015
Copy link
Contributor

@alexyao2015 alexyao2015 commented Mar 9, 2024

Breaking change

Proposed change

This converts HTML5 to use config flow. In the process, this also removes the need for the user to manually obtain a VAPID key as it is now automatically generated.

This also removes the long deprecated GCM configuration method.

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:

Copy link
Contributor

@sdb9696 sdb9696 left a comment

Choose a reason for hiding this comment

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

This looks really good to me. I've looked at a number of other integrations using config flow with the notify platform (i.e. google_mail) and the approach seems consistent.

The notifications are consistent with the following architecture policy: https://github.com/home-assistant/architecture/blob/master/adr/0021-YAML-integration-configuration-deprecation-policy.md

The removal of the gcm_api_deprecated makes sense to be included in this PR as it's part of the old config and shouldn't be carried over to the config flow.

The tests look good with 100% coverage.

A few suggestions and one question about the parameters passed to async_load_platform below. Also I'm not sure it makes sense to make the service async for the reason below.

homeassistant/components/html5/notify.py Outdated Show resolved Hide resolved
homeassistant/components/html5/issues.py Outdated Show resolved Hide resolved
homeassistant/components/html5/issues.py Outdated Show resolved Hide resolved
homeassistant/components/html5/__init__.py Show resolved Hide resolved
homeassistant/components/html5/notify.py Show resolved Hide resolved
homeassistant/components/html5/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/html5/notify.py Outdated Show resolved Hide resolved
Copy link
Contributor

@sdb9696 sdb9696 left a comment

Choose a reason for hiding this comment

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

One item left which is to revert the get_service back to a sync function unless I'm somehow missing why it was necessary.

homeassistant/components/html5/notify.py Outdated Show resolved Hide resolved
@alexyao2015
Copy link
Contributor Author

The get_service call just got converted to an async function. #116068

@bdraco
Copy link
Member

bdraco commented Apr 26, 2024

Its not thread-safe to call hass.http.register_view or hass.services.async_register in the executor. It should have been an an async function all along

@sdb9696
Copy link
Contributor

sdb9696 commented Apr 26, 2024

Its not thread-safe to call hass.http.register_view or hass.services.async_register in the executor. It should have been an an async function all along

Ah ok, my bad I didn't know that, thanks @bdraco. This is all good from me, thanks @alexyao2015!

Copy link
Contributor

@sdb9696 sdb9696 left a comment

Choose a reason for hiding this comment

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

LGTM!

alexyao2015 and others added 6 commits May 4, 2024 08:57
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: J. Nick Koston <nick@koston.org>

# Iterate all entries for notify to only get HTML5
for entry in config.get(Platform.NOTIFY, {}):
if entry[CONF_PLATFORM] == DOMAIN:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if entry[CONF_PLATFORM] == DOMAIN:
if entry[CONF_PLATFORM] != DOMAIN:
continue

Than outdent below

@bdraco
Copy link
Member

bdraco commented May 12, 2024

testing....

Screenshot 2024-05-12 at 2 10 41 PM Screenshot 2024-05-12 at 2 10 57 PM

@bdraco
Copy link
Member

bdraco commented May 12, 2024

Screenshot 2024-05-12 at 2 16 52 PM

dismiss service is there

@bdraco
Copy link
Member

bdraco commented May 12, 2024

notify.html5 service is missing though

@alexyao2015
Copy link
Contributor Author

Issue is fixed

@bdraco
Copy link
Member

bdraco commented May 15, 2024

I did some testing. Some observations:

  • After enabling the notifications, I still have to restart for the new service to appear
  • Sending a notification via the new service after restart didn't work in firefox or chrome

@alexyao2015
Copy link
Contributor Author

I retested this again.

  • Having to restart appears to be the status quo. Services are loaded in using the legacy notify platform which controls the need for a restart. This aspect was not changed.
  • Sending notifications after restarting works from notify.html5, notify.notify, and notify.html5_mydevice. The service worker must be activated for notifications to function.

@bdraco
Copy link
Member

bdraco commented May 22, 2024

It seems like it defeats the purpose of converting to a config flow if you have to restart for the service to exist. We could use the discovery helper to discover the new service immediately.

@alexyao2015
Copy link
Contributor Author

defeats the purpose of converting to a config flow

This mainly helps with setup so users don't have to manually obtain vapid keys since they are now automatically generated.

the discovery helper to discover the new service immediately

Do you have an example of how to do that?

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.

None yet

4 participants