Ignore link local addresses during doorbird ssdp config flow (#33401)

This commit is contained in:
J. Nick Koston 2020-03-31 16:20:29 -05:00 committed by GitHub
parent be99f3bf32
commit a473ae6711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 33 deletions

View File

@ -1,34 +1,36 @@
{ {
"config": { "options" : {
"abort": { "step" : {
"already_configured": "This DoorBird is already configured" "init" : {
}, "data" : {
"error": { "events" : "Comma separated list of events."
"cannot_connect": "Failed to connect, please try again", },
"invalid_auth": "Invalid authentication", "description" : "Add an comma separated event name for each event you wish to track. After entering them here, use the DoorBird app to assign them to a specific event. See the documentation at https://www.home-assistant.io/integrations/doorbird/#events. Example: somebody_pressed_the_button, motion"
"unknown": "Unexpected error" }
}, }
"step": { },
"user": { "config" : {
"data": { "step" : {
"host": "Host (IP Address)", "user" : {
"name": "Device Name", "title" : "Connect to the DoorBird",
"password": "Password", "data" : {
"username": "Username" "password" : "Password",
}, "host" : "Host (IP Address)",
"title": "Connect to the DoorBird" "name" : "Device Name",
"username" : "Username"
} }
}, }
"title": "DoorBird" },
}, "abort" : {
"options": { "already_configured" : "This DoorBird is already configured",
"step": { "link_local_address": "Link local addresses are not supported",
"init": { "not_doorbird_device": "This device is not a DoorBird"
"data": { },
"events": "Comma separated list of events." "title" : "DoorBird",
}, "error" : {
"description": "Add an comma separated event name for each event you wish to track. After entering them here, use the DoorBird app to assign them to a specific event. See the documentation at https://www.home-assistant.io/integrations/doorbird/#events. Example: somebody_pressed_the_button, motion" "invalid_auth" : "Invalid authentication",
} "unknown" : "Unexpected error",
} "cannot_connect" : "Failed to connect, please try again"
} }
} }
}

View File

@ -90,6 +90,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
if macaddress[:6] != DOORBIRD_OUI: if macaddress[:6] != DOORBIRD_OUI:
return self.async_abort(reason="not_doorbird_device") return self.async_abort(reason="not_doorbird_device")
if discovery_info[CONF_HOST].startswith("169.254"):
return self.async_abort(reason="link_local_address")
await self.async_set_unique_id(macaddress) await self.async_set_unique_id(macaddress)

View File

@ -22,7 +22,9 @@
} }
}, },
"abort" : { "abort" : {
"already_configured" : "This DoorBird is already configured" "already_configured" : "This DoorBird is already configured",
"link_local_address": "Link local addresses are not supported",
"not_doorbird_device": "This device is not a DoorBird"
}, },
"title" : "DoorBird", "title" : "DoorBird",
"error" : { "error" : {

View File

@ -140,10 +140,33 @@ async def test_form_zeroconf_wrong_oui(hass):
context={"source": config_entries.SOURCE_ZEROCONF}, context={"source": config_entries.SOURCE_ZEROCONF},
data={ data={
"properties": {"macaddress": "notdoorbirdoui"}, "properties": {"macaddress": "notdoorbirdoui"},
"host": "192.168.1.8",
"name": "Doorstation - abc123._axis-video._tcp.local.", "name": "Doorstation - abc123._axis-video._tcp.local.",
}, },
) )
assert result["type"] == "abort" assert result["type"] == "abort"
assert result["reason"] == "not_doorbird_device"
async def test_form_zeroconf_link_local_ignored(hass):
"""Test we abort when we get a link local address via zeroconf."""
await hass.async_add_executor_job(
init_recorder_component, hass
) # force in memory db
await setup.async_setup_component(hass, "persistent_notification", {})
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data={
"properties": {"macaddress": "1CCAE3DOORBIRD"},
"host": "169.254.103.61",
"name": "Doorstation - abc123._axis-video._tcp.local.",
},
)
assert result["type"] == "abort"
assert result["reason"] == "link_local_address"
async def test_form_zeroconf_correct_oui(hass): async def test_form_zeroconf_correct_oui(hass):