Filter IPv6 addresses from AppleTV zeroconf discovery (#68530)
This commit is contained in:
parent
050600375d
commit
6fd4355314
4 changed files with 25 additions and 5 deletions
|
@ -19,6 +19,7 @@ from homeassistant.const import CONF_ADDRESS, CONF_NAME, CONF_PIN
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
from homeassistant.util.network import is_ipv6_address
|
||||||
|
|
||||||
from .const import CONF_CREDENTIALS, CONF_IDENTIFIERS, CONF_START_OFF, DOMAIN
|
from .const import CONF_CREDENTIALS, CONF_IDENTIFIERS, CONF_START_OFF, DOMAIN
|
||||||
|
|
||||||
|
@ -166,6 +167,8 @@ class AppleTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
) -> data_entry_flow.FlowResult:
|
) -> data_entry_flow.FlowResult:
|
||||||
"""Handle device found via zeroconf."""
|
"""Handle device found via zeroconf."""
|
||||||
host = discovery_info.host
|
host = discovery_info.host
|
||||||
|
if is_ipv6_address(host):
|
||||||
|
return self.async_abort(reason="ipv6_not_supported")
|
||||||
self._async_abort_entries_match({CONF_ADDRESS: host})
|
self._async_abort_entries_match({CONF_ADDRESS: host})
|
||||||
service_type = discovery_info.type[:-1] # Remove leading .
|
service_type = discovery_info.type[:-1] # Remove leading .
|
||||||
name = discovery_info.name.replace(f".{service_type}.", "")
|
name = discovery_info.name.replace(f".{service_type}.", "")
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
|
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
|
"ipv6_not_supported": "IPv6 is not supported.",
|
||||||
"no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]",
|
"no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]",
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||||
"device_did_not_pair": "No attempt to finish pairing process was made from the device.",
|
"device_did_not_pair": "No attempt to finish pairing process was made from the device.",
|
||||||
|
|
|
@ -2,13 +2,12 @@
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "Device is already configured",
|
"already_configured": "Device is already configured",
|
||||||
"already_configured_device": "Device is already configured",
|
|
||||||
"already_in_progress": "Configuration flow is already in progress",
|
"already_in_progress": "Configuration flow is already in progress",
|
||||||
"backoff": "Device does not accept pairing requests at this time (you might have entered an invalid PIN code too many times), try again later.",
|
"backoff": "Device does not accept pairing requests at this time (you might have entered an invalid PIN code too many times), try again later.",
|
||||||
"device_did_not_pair": "No attempt to finish pairing process was made from the device.",
|
"device_did_not_pair": "No attempt to finish pairing process was made from the device.",
|
||||||
"device_not_found": "Device was not found during discovery, please try adding it again.",
|
"device_not_found": "Device was not found during discovery, please try adding it again.",
|
||||||
"inconsistent_device": "Expected protocols were not found during discovery. This normally indicates a problem with multicast DNS (Zeroconf). Please try adding the device again.",
|
"inconsistent_device": "Expected protocols were not found during discovery. This normally indicates a problem with multicast DNS (Zeroconf). Please try adding the device again.",
|
||||||
"invalid_config": "The configuration for this device is incomplete. Please try adding it again.",
|
"ipv6_not_supported": "IPv6 is not supported.",
|
||||||
"no_devices_found": "No devices found on the network",
|
"no_devices_found": "No devices found on the network",
|
||||||
"reauth_successful": "Re-authentication was successful",
|
"reauth_successful": "Re-authentication was successful",
|
||||||
"setup_failed": "Failed to set up device.",
|
"setup_failed": "Failed to set up device.",
|
||||||
|
@ -18,7 +17,6 @@
|
||||||
"already_configured": "Device is already configured",
|
"already_configured": "Device is already configured",
|
||||||
"invalid_auth": "Invalid authentication",
|
"invalid_auth": "Invalid authentication",
|
||||||
"no_devices_found": "No devices found on the network",
|
"no_devices_found": "No devices found on the network",
|
||||||
"no_usable_service": "A device was found but could not identify any way to establish a connection to it. If you keep seeing this message, try specifying its IP address or restarting your Apple TV.",
|
|
||||||
"unknown": "Unexpected error"
|
"unknown": "Unexpected error"
|
||||||
},
|
},
|
||||||
"flow_title": "{name} ({type})",
|
"flow_title": "{name} ({type})",
|
||||||
|
@ -72,6 +70,5 @@
|
||||||
"description": "Configure general device settings"
|
"description": "Configure general device settings"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"title": "Apple TV"
|
|
||||||
}
|
}
|
|
@ -1066,3 +1066,22 @@ async def test_option_start_off(hass):
|
||||||
assert result2["type"] == "create_entry"
|
assert result2["type"] == "create_entry"
|
||||||
|
|
||||||
assert config_entry.options[CONF_START_OFF]
|
assert config_entry.options[CONF_START_OFF]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_zeroconf_rejects_ipv6(hass):
|
||||||
|
"""Test zeroconf discovery rejects ipv6."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||||
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
|
host="fd00::b27c:63bb:cc85:4ea0",
|
||||||
|
addresses=["fd00::b27c:63bb:cc85:4ea0"],
|
||||||
|
hostname="mock_hostname",
|
||||||
|
port=None,
|
||||||
|
type="_touch-able._tcp.local.",
|
||||||
|
name="dmapid._touch-able._tcp.local.",
|
||||||
|
properties={"CtlN": "Apple TV"},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
|
assert result["reason"] == "ipv6_not_supported"
|
||||||
|
|
Loading…
Add table
Reference in a new issue