-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend dhcp discovery flow for ring integration (#126661)
- Loading branch information
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -6,10 +6,12 @@ | |
import ring_doorbell | ||
|
||
from homeassistant import config_entries | ||
from homeassistant.components import dhcp | ||
from homeassistant.components.ring import DOMAIN | ||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.data_entry_flow import FlowResultType | ||
from homeassistant.helpers import device_registry as dr | ||
|
||
from tests.common import MockConfigEntry | ||
|
||
|
@@ -242,3 +244,57 @@ async def test_account_configured( | |
|
||
assert result2["type"] is FlowResultType.ABORT | ||
assert result2["reason"] == "already_configured" | ||
|
||
|
||
async def test_dhcp_discovery( | ||
hass: HomeAssistant, | ||
mock_setup_entry: AsyncMock, | ||
mock_ring_client: Mock, | ||
device_registry: dr.DeviceRegistry, | ||
) -> None: | ||
"""Test discovery by dhcp.""" | ||
mac_address = "1234567890abcd" | ||
hostname = "Ring-90abcd" | ||
ip_address = "127.0.0.1" | ||
username = "[email protected]" | ||
|
||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, | ||
context={"source": config_entries.SOURCE_DHCP}, | ||
data=dhcp.DhcpServiceInfo( | ||
ip=ip_address, macaddress=mac_address, hostname=hostname | ||
), | ||
) | ||
assert result["type"] is FlowResultType.FORM | ||
assert result["errors"] == {} | ||
assert result["step_id"] == "user" | ||
result = await hass.config_entries.flow.async_configure( | ||
result["flow_id"], | ||
{"username": username, "password": "test-password"}, | ||
) | ||
assert result["type"] is FlowResultType.CREATE_ENTRY | ||
assert result["title"] == "[email protected]" | ||
assert result["data"] == { | ||
"username": username, | ||
"token": {"access_token": "mock-token"}, | ||
} | ||
|
||
config_entry = hass.config_entries.async_entry_for_domain_unique_id( | ||
DOMAIN, username | ||
) | ||
assert config_entry | ||
|
||
# Create a device entry under the config entry just created | ||
device_registry.async_get_or_create( | ||
config_entry_id=config_entry.entry_id, | ||
identifiers={(DOMAIN, mac_address)}, | ||
) | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, | ||
context={"source": config_entries.SOURCE_DHCP}, | ||
data=dhcp.DhcpServiceInfo( | ||
ip=ip_address, macaddress=mac_address, hostname=hostname | ||
), | ||
) | ||
assert result["type"] is FlowResultType.ABORT | ||
assert result["reason"] == "already_configured" |