-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Add bronze quality scale to DNS IP #169688
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
Phil-Rad
wants to merge
4
commits into
home-assistant:dev
Choose a base branch
from
Phil-Rad:quality-scale/dnsip-bronze
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3cc58b6
Add bronze quality scale to DNS IP
Phil-Rad 6fc0d73
Implement runtime-data and test-before-setup for dnsip
Phil-Rad 7bbf24c
Close DNS resolvers on setup failure and unload
Phil-Rad 58c61fd
Test setup-time DNS error path and IPv6-only setup for dnsip
Phil-Rad 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
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 |
|---|---|---|
| @@ -1,23 +1,83 @@ | ||
| """The DNS IP integration.""" | ||
|
|
||
| import asyncio | ||
| from dataclasses import dataclass | ||
|
|
||
| import aiodns | ||
| from aiodns.error import DNSError | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import CONF_PORT | ||
| from homeassistant.core import _LOGGER, HomeAssistant | ||
| from homeassistant.exceptions import ConfigEntryNotReady | ||
|
|
||
| from .const import ( | ||
| CONF_HOSTNAME, | ||
| CONF_IPV4, | ||
| CONF_IPV6, | ||
| CONF_PORT_IPV6, | ||
| CONF_RESOLVER, | ||
| CONF_RESOLVER_IPV6, | ||
| DEFAULT_PORT, | ||
| PLATFORMS, | ||
| ) | ||
|
|
||
|
|
||
| from .const import CONF_PORT_IPV6, DEFAULT_PORT, PLATFORMS | ||
| @dataclass | ||
| class DnsIPRuntimeData: | ||
| """Runtime data for DNS IP integration.""" | ||
|
|
||
| resolver_ipv4: aiodns.DNSResolver | ||
| resolver_ipv6: aiodns.DNSResolver | ||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
|
|
||
| type DnsIPConfigEntry = ConfigEntry[DnsIPRuntimeData] | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: DnsIPConfigEntry) -> bool: | ||
| """Set up DNS IP from a config entry.""" | ||
|
|
||
| nameserver_ipv4 = entry.options[CONF_RESOLVER] | ||
| nameserver_ipv6 = entry.options[CONF_RESOLVER_IPV6] | ||
| port_ipv4 = entry.options[CONF_PORT] | ||
| port_ipv6 = entry.options[CONF_PORT_IPV6] | ||
|
|
||
| resolver_ipv4 = aiodns.DNSResolver( | ||
| nameservers=[nameserver_ipv4], tcp_port=port_ipv4, udp_port=port_ipv4 | ||
| ) | ||
| resolver_ipv6 = aiodns.DNSResolver( | ||
| nameservers=[nameserver_ipv6], tcp_port=port_ipv6, udp_port=port_ipv6 | ||
| ) | ||
|
|
||
| hostname = entry.data[CONF_HOSTNAME] | ||
| try: | ||
| async with asyncio.timeout(10): | ||
| if entry.data[CONF_IPV4]: | ||
| await resolver_ipv4.query(hostname, "A") | ||
| elif entry.data[CONF_IPV6]: | ||
| await resolver_ipv6.query(hostname, "AAAA") | ||
| except (TimeoutError, DNSError) as err: | ||
| await resolver_ipv4.close() | ||
| await resolver_ipv6.close() | ||
| raise ConfigEntryNotReady(f"DNS lookup failed for {hostname}: {err}") from err | ||
|
|
||
|
Comment on lines
+53
to
+63
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure if this is required. Can add this change if this is needed
Comment on lines
+53
to
+63
|
||
| entry.runtime_data = DnsIPRuntimeData( | ||
| resolver_ipv4=resolver_ipv4, | ||
| resolver_ipv6=resolver_ipv6, | ||
| ) | ||
|
|
||
| await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| async def async_unload_entry(hass: HomeAssistant, entry: DnsIPConfigEntry) -> bool: | ||
| """Unload DNS IP config entry.""" | ||
|
|
||
| return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
| unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
| if unload_ok: | ||
| await entry.runtime_data.resolver_ipv4.close() | ||
| await entry.runtime_data.resolver_ipv6.close() | ||
| return unload_ok | ||
|
|
||
|
|
||
| async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: | ||
|
|
||
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
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,75 @@ | ||
| rules: | ||
| action-setup: | ||
| status: exempt | ||
| comment: Integration does not register custom actions. | ||
| appropriate-polling: done | ||
| brands: done | ||
| common-modules: done | ||
| config-flow-test-coverage: done | ||
| config-flow: done | ||
| dependency-transparency: done | ||
| docs-actions: | ||
| status: exempt | ||
| comment: Integration does not register custom actions. | ||
| docs-high-level-description: done | ||
| docs-installation-instructions: done | ||
| docs-removal-instructions: done | ||
| entity-event-setup: | ||
| status: exempt | ||
| comment: Entities do not subscribe to events; the sensor polls via async_update. | ||
| entity-unique-id: done | ||
| has-entity-name: done | ||
| runtime-data: done | ||
| test-before-configure: done | ||
| test-before-setup: done | ||
| unique-config-entry: done | ||
|
Comment on lines
+22
to
+25
|
||
| action-exceptions: | ||
| status: exempt | ||
| comment: Integration does not register custom actions. | ||
| config-entry-unloading: done | ||
| docs-configuration-parameters: todo | ||
| docs-installation-parameters: todo | ||
| entity-unavailable: todo | ||
| integration-owner: done | ||
| log-when-unavailable: todo | ||
| parallel-updates: todo | ||
| reauthentication-flow: | ||
| status: exempt | ||
| comment: DNS resolution does not require authentication. | ||
| test-coverage: todo | ||
| devices: todo | ||
| diagnostics: todo | ||
| discovery-update-info: | ||
| status: exempt | ||
| comment: DNS resolvers do not support discovery. | ||
| discovery: | ||
| status: exempt | ||
| comment: DNS resolvers do not support discovery. | ||
| docs-data-update: todo | ||
| docs-examples: todo | ||
| docs-known-limitations: todo | ||
| docs-supported-devices: | ||
| status: exempt | ||
| comment: Integration does not represent physical devices. | ||
| docs-supported-functions: todo | ||
| docs-troubleshooting: todo | ||
| docs-use-cases: todo | ||
| dynamic-devices: | ||
| status: exempt | ||
| comment: Integration does not represent physical devices. | ||
| entity-category: todo | ||
| entity-device-class: todo | ||
| entity-disabled-by-default: todo | ||
| entity-translations: todo | ||
| exception-translations: todo | ||
| icon-translations: todo | ||
| reconfiguration-flow: todo | ||
| repair-issues: todo | ||
| stale-devices: | ||
| status: exempt | ||
| comment: Integration does not represent physical devices. | ||
| async-dependency: done | ||
| inject-websession: | ||
| status: exempt | ||
| comment: Integration uses aiodns directly; no shared HTTP websession applies. | ||
| strict-typing: todo | ||
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
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
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
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.
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.
fixed in next push