Skip to content

Quantum gateway data coordinator #146007

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

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

tamwahba
Copy link
Contributor

@tamwahba tamwahba commented Jun 2, 2025

Breaking change

Proposed change

This PR updates the Quantum Gateway device tracker to use a DataCorrdinator for handling its polling for data. This is another step in the path to updating the Quantum Gateway integration to be setup through the UI.

The main change in the PR is that the Quantum Gateway scanner is now initialized at component setup instead of the device tracker platform setup.

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

n/a

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:

@home-assistant
Copy link

home-assistant bot commented Jun 2, 2025

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

Code owner commands

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

coordinator = QuantumGatewayCoordinator(hass, options)

try:
await coordinator._async_setup() # noqa: SLF001
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way of manually initializing the data coordinator? I'm not using async_config_entry_first_refresh because there's no config entry yet!

Copy link
Member

Choose a reason for hiding this comment

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

async_refresh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, async_refresh doesn't seem to call _async_setup to initialize the coordinator. Do you recommend using a different API for doing initial setup?

@tamwahba tamwahba force-pushed the quantum-gateway-data-coordinator branch 3 times, most recently from 93c3657 to 94d0e3a Compare June 2, 2025 02:47
@tamwahba tamwahba force-pushed the quantum-gateway-data-coordinator branch 3 times, most recently from 4036e2c to ff81336 Compare June 22, 2025 19:31
Comment on lines +14 to +21
CONFIG_SCHEMA = vol.Schema(
{DEVICE_TRACKER_DOMAIN: [PLATFORM_SCHEMA]},
extra=vol.ALLOW_EXTRA,
)


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Quantum Gateway component."""
Copy link
Member

Choose a reason for hiding this comment

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

We should maintain the current entrypoint, so we should use the device_tracker async_setup_platform instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey Joost, I'm not sure what you mean. Should be initializing the coordinator in the device_scanner async_get_scanner by reverting this change?
ff81336#diff-2b177940cc8b47dd3c46b82c10defa53607dd9898e1cdfa4b89291c1edc8b9eaL30-L43

My reasoning for moving the initialization here was to reduce the amount of changes when switching to a config entry, but I'm happy to switch it back if this is what you mean.

coordinator = QuantumGatewayCoordinator(hass, options)

try:
await coordinator._async_setup() # noqa: SLF001
Copy link
Member

Choose a reason for hiding this comment

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

async_refresh


return scanner if scanner.success_init else None
return QuantumGatewayDeviceScanner(hass, coordinator)


class QuantumGatewayDeviceScanner(DeviceScanner):
Copy link
Member

Choose a reason for hiding this comment

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

I think we should need to make this a CoordinatorEntity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey Joost, I've made the update to use a CoordinatorEntity, but I'm a bit confused; isn't this the class representing the scanner itself as opposed to entities it creates for the scanned devices?

@home-assistant home-assistant bot marked this pull request as draft June 22, 2025 21:49
@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.

@tamwahba tamwahba force-pushed the quantum-gateway-data-coordinator branch from ff81336 to 731b4a3 Compare June 29, 2025 02:07
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.

2 participants