-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
Reimplement Cloudflare using coordinator #156817
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
base: dev
Are you sure you want to change the base?
Conversation
Signed-off-by: David Rapan <[email protected]>
|
Hey there @ludeeus, @ctalkington, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
| _LOCATION_PATCH_TARGET = ( | ||
| "homeassistant.components.cloudflare.coordinator.async_detect_location_info" | ||
| ) | ||
| _LOCATION_PATCH_VALUE = LocationInfo( | ||
| "0.0.0.0", | ||
| "US", | ||
| "USD", | ||
| "CA", | ||
| "California", | ||
| "San Diego", | ||
| "92122", | ||
| "America/Los_Angeles", | ||
| 32.8594, | ||
| -117.2073, | ||
| True, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to make this a fixture (with patch... yield) in conftest.py, in conjunction with @pytest.mark.usefixtures(xyz).
|
Impeccable timing 👌🏻 |
Signed-off-by: David Rapan <[email protected]>
Signed-off-by: David Rapan <[email protected]>
Signed-off-by: David Rapan <[email protected]>
|
|
||
|
|
||
| @pytest.fixture | ||
| def location_info() -> Generator: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def location_info() -> Generator: | |
| def location_info() -> Generator[None]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was just thinking about it.. 😆
Signed-off-by: David Rapan <[email protected]>
| f"Error updating zone {self.config_entry.data[CONF_ZONE]}" | ||
| ) from e | ||
|
|
||
| async def init(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this method. It doesn't add much value and makes the code logic harder to follow. One of the common things that's checked is whether the async_setup_entry method is executing the async_config_entry_first_refresh method , and now that's not done explicitly, but through this additional method. This should be moved to async_setup_entry.
https://developers.home-assistant.io/docs/core/integration-quality-scale/rules/test-before-setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's also _async_setup in the coordinator for one time setup tasks automatically called during async_config_entry_first_refresh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I do use _async_setup 😉 I'm just wrapping async_config_entry_first_refresh together w/ return self so I can "one-line it" in async_setup_entry.
It's coming from my template which I use when creating custom components, etc. (and changes in this PR are semi-based on it too) But sure, I can remove it. :)
|
👀 -> Cloudflare had a major outage today |
Today is a major outage day, I see.. |
|
I'm not sure if this PR works as indended. The coordinator doesn't refresh automatically if we don't have any listeners connected, and the Cloudflare integration doesn't provide any entities, so we don't have listeners as listeners are registered by BaseCoordinatorEntity |
Signed-off-by: David Rapan <[email protected]>
|
Oh yeah, you're right, we were missing a key part for the entityless coordinator. :) I'm not sure if there's a better approach than the one I'm using though.. |
Just use listeners and don't bother with the coordinator? |
Signed-off-by: David Rapan <[email protected]>
Signed-off-by: David Rapan <[email protected]>
0cf6424 to
07cc995
Compare
Proposed change
Reimplement using coordinator to better align w/ the current HA architecture and avoid
async_track_time_interval.+ Fixes missing after setup update thanks to
async_config_entry_first_refresh.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: