-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Add OpenAQ integration #169755
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
Open
jeeftor
wants to merge
15
commits into
home-assistant:dev
Choose a base branch
from
jeeftor:feature/openAQ
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add OpenAQ integration #169755
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
95d50cc
Add OpenAQ integration
jeeftor 5eb85da
Update OpenAQ quality scale docs rules
jeeftor ba1a5cc
Mark OpenAQ brands quality rule done
jeeftor c6571a8
Address OpenAQ review feedback
jeeftor 8b82549
Use reported OpenAQ sensor units
jeeftor 73afa78
Address OpenAQ coordinator review feedback
jeeftor d402209
Improve OpenAQ test coverage
jeeftor aa8645f
Improve OpenAQ monitoring location setup
jeeftor c508639
Cover OpenAQ subentry API errors
jeeftor 28432ec
Remove OpenAQ debug logging
jeeftor b2944b3
Mark OpenAQ as bronze
jeeftor 7de9b1f
Remove future annotations from OpenAQ
jeeftor 0a2077d
Address OpenAQ review feedback
jeeftor c008050
Cache OpenAQ location metadata
jeeftor 807c6d6
MEGA TEST COVERAGE
jeeftor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """The OpenAQ integration.""" | ||
|
|
||
| import asyncio | ||
|
|
||
| from homeassistant.const import CONF_API_KEY, Platform | ||
| from homeassistant.core import HomeAssistant | ||
|
|
||
| from .const import SUBENTRY_TYPE_LOCATION | ||
| from .coordinator import ( | ||
| OpenAQConfigEntry, | ||
| OpenAQDataUpdateCoordinator, | ||
| OpenAQRuntimeData, | ||
| async_create_openaq_client, | ||
| ) | ||
|
|
||
| PLATFORMS: list[Platform] = [Platform.SENSOR] | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: OpenAQConfigEntry) -> bool: | ||
| """Set up OpenAQ from a config entry.""" | ||
| client = await async_create_openaq_client(hass, entry.data[CONF_API_KEY]) | ||
| coordinators: dict[str, OpenAQDataUpdateCoordinator] = {} | ||
|
|
||
| for subentry in entry.get_subentries_of_type(SUBENTRY_TYPE_LOCATION): | ||
| coordinators[subentry.subentry_id] = OpenAQDataUpdateCoordinator( | ||
| hass, entry, subentry, client | ||
| ) | ||
|
|
||
| try: | ||
| await asyncio.gather( | ||
| *( | ||
| coordinator.async_config_entry_first_refresh() | ||
| for coordinator in coordinators.values() | ||
| ) | ||
| ) | ||
| except Exception: | ||
| await client.close() | ||
| raise | ||
|
|
||
| entry.runtime_data = OpenAQRuntimeData(client=client, coordinators=coordinators) | ||
| entry.async_on_unload(entry.add_update_listener(async_update_entry)) | ||
| await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
| return True | ||
|
|
||
|
|
||
| async def async_update_entry(hass: HomeAssistant, entry: OpenAQConfigEntry) -> None: | ||
| """Update the config entry.""" | ||
| await hass.config_entries.async_reload(entry.entry_id) | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, entry: OpenAQConfigEntry) -> bool: | ||
| """Unload a config entry.""" | ||
| unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
| if unload_ok and (runtime_data := getattr(entry, "runtime_data", None)): | ||
| await runtime_data.client.close() | ||
| return unload_ok | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.