mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Filter IPv6 addresses from doorbird discovery (#68031)
This commit is contained in:
parent
68310a426b
commit
a851921fe6
@ -12,7 +12,7 @@ from homeassistant.components import zeroconf
|
|||||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.util.network import is_link_local
|
from homeassistant.util.network import is_ipv4_address, is_link_local
|
||||||
|
|
||||||
from .const import CONF_EVENTS, DOMAIN, DOORBIRD_OUI
|
from .const import CONF_EVENTS, DOMAIN, DOORBIRD_OUI
|
||||||
from .util import get_mac_address_from_doorstation_info
|
from .util import get_mac_address_from_doorstation_info
|
||||||
@ -103,6 +103,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
return self.async_abort(reason="not_doorbird_device")
|
return self.async_abort(reason="not_doorbird_device")
|
||||||
if is_link_local(ip_address(host)):
|
if is_link_local(ip_address(host)):
|
||||||
return self.async_abort(reason="link_local_address")
|
return self.async_abort(reason="link_local_address")
|
||||||
|
if not is_ipv4_address(host):
|
||||||
|
return self.async_abort(reason="not_ipv4_address")
|
||||||
|
|
||||||
await self.async_set_unique_id(macaddress)
|
await self.async_set_unique_id(macaddress)
|
||||||
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "Device is already configured",
|
"already_configured": "Device is already configured",
|
||||||
"link_local_address": "Link local addresses are not supported",
|
"link_local_address": "Link local addresses are not supported",
|
||||||
"not_doorbird_device": "This device is not a DoorBird"
|
"not_doorbird_device": "This device is not a DoorBird",
|
||||||
|
"not_ipv4_address": "Only IPv4 addresess are supported"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "Failed to connect",
|
"cannot_connect": "Failed to connect",
|
||||||
|
@ -116,6 +116,54 @@ async def test_form_zeroconf_link_local_ignored(hass):
|
|||||||
assert result["reason"] == "link_local_address"
|
assert result["reason"] == "link_local_address"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_form_zeroconf_ipv4_address(hass):
|
||||||
|
"""Test we abort and update the ip address from zeroconf with an ipv4 address."""
|
||||||
|
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
unique_id="1CCAE3AAAAAA",
|
||||||
|
data=VALID_CONFIG,
|
||||||
|
options={CONF_EVENTS: ["event1", "event2", "event3"]},
|
||||||
|
)
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||||
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
|
host="4.4.4.4",
|
||||||
|
addresses=["4.4.4.4"],
|
||||||
|
hostname="mock_hostname",
|
||||||
|
name="Doorstation - abc123._axis-video._tcp.local.",
|
||||||
|
port=None,
|
||||||
|
properties={"macaddress": "1CCAE3AAAAAA"},
|
||||||
|
type="mock_type",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert result["type"] == "abort"
|
||||||
|
assert result["reason"] == "already_configured"
|
||||||
|
assert config_entry.data[CONF_HOST] == "4.4.4.4"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_form_zeroconf_non_ipv4_ignored(hass):
|
||||||
|
"""Test we abort when we get a non ipv4 address via zeroconf."""
|
||||||
|
|
||||||
|
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",
|
||||||
|
name="Doorstation - abc123._axis-video._tcp.local.",
|
||||||
|
port=None,
|
||||||
|
properties={"macaddress": "1CCAE3DOORBIRD"},
|
||||||
|
type="mock_type",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert result["type"] == "abort"
|
||||||
|
assert result["reason"] == "not_ipv4_address"
|
||||||
|
|
||||||
|
|
||||||
async def test_form_zeroconf_correct_oui(hass):
|
async def test_form_zeroconf_correct_oui(hass):
|
||||||
"""Test we can setup from zeroconf with the correct OUI source."""
|
"""Test we can setup from zeroconf with the correct OUI source."""
|
||||||
doorbirdapi = _get_mock_doorbirdapi_return_values(
|
doorbirdapi = _get_mock_doorbirdapi_return_values(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user