mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 00:27:19 +00:00
Simplify
This commit is contained in:
parent
864882750d
commit
0dd090ba20
@ -151,7 +151,11 @@ async def test_dhcp_flow(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test the DHCP discovery flow."""
|
"""Test the DHCP discovery flow."""
|
||||||
|
|
||||||
result = await dhcp_service_info.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
data=dhcp_service_info,
|
||||||
|
context={"source": config_entries.SOURCE_DHCP},
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
|
@ -11,6 +11,7 @@ from aioairzone.exceptions import (
|
|||||||
SystemOutOfRange,
|
SystemOutOfRange,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.airzone.config_flow import short_mac
|
from homeassistant.components.airzone.config_flow import short_mac
|
||||||
from homeassistant.components.airzone.const import DOMAIN
|
from homeassistant.components.airzone.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER, ConfigEntryState
|
from homeassistant.config_entries import SOURCE_USER, ConfigEntryState
|
||||||
@ -202,7 +203,11 @@ async def test_dhcp_flow(hass: HomeAssistant) -> None:
|
|||||||
"homeassistant.components.airzone.AirzoneLocalApi.get_version",
|
"homeassistant.components.airzone.AirzoneLocalApi.get_version",
|
||||||
return_value=HVAC_VERSION_MOCK,
|
return_value=HVAC_VERSION_MOCK,
|
||||||
):
|
):
|
||||||
result = await DHCP_SERVICE_INFO.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
data=DHCP_SERVICE_INFO,
|
||||||
|
context={"source": config_entries.SOURCE_DHCP},
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "discovered_connection"
|
assert result["step_id"] == "discovered_connection"
|
||||||
@ -256,7 +261,11 @@ async def test_dhcp_flow_error(hass: HomeAssistant) -> None:
|
|||||||
"homeassistant.components.airzone.AirzoneLocalApi.get_version",
|
"homeassistant.components.airzone.AirzoneLocalApi.get_version",
|
||||||
side_effect=AirzoneError,
|
side_effect=AirzoneError,
|
||||||
):
|
):
|
||||||
result = await DHCP_SERVICE_INFO.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
data=DHCP_SERVICE_INFO,
|
||||||
|
context={"source": config_entries.SOURCE_DHCP},
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "cannot_connect"
|
assert result["reason"] == "cannot_connect"
|
||||||
@ -269,7 +278,11 @@ async def test_dhcp_connection_error(hass: HomeAssistant) -> None:
|
|||||||
"homeassistant.components.airzone.AirzoneLocalApi.get_version",
|
"homeassistant.components.airzone.AirzoneLocalApi.get_version",
|
||||||
return_value=HVAC_VERSION_MOCK,
|
return_value=HVAC_VERSION_MOCK,
|
||||||
):
|
):
|
||||||
result = await DHCP_SERVICE_INFO.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
data=DHCP_SERVICE_INFO,
|
||||||
|
context={"source": config_entries.SOURCE_DHCP},
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "discovered_connection"
|
assert result["step_id"] == "discovered_connection"
|
||||||
@ -341,7 +354,11 @@ async def test_dhcp_invalid_system_id(hass: HomeAssistant) -> None:
|
|||||||
"homeassistant.components.airzone.AirzoneLocalApi.get_version",
|
"homeassistant.components.airzone.AirzoneLocalApi.get_version",
|
||||||
return_value=HVAC_VERSION_MOCK,
|
return_value=HVAC_VERSION_MOCK,
|
||||||
):
|
):
|
||||||
result = await DHCP_SERVICE_INFO.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
data=DHCP_SERVICE_INFO,
|
||||||
|
context={"source": config_entries.SOURCE_DHCP},
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "discovered_connection"
|
assert result["step_id"] == "discovered_connection"
|
||||||
|
@ -25,12 +25,6 @@ from .mock_data import MOCK_CONFIG, NETWORK_INFO, ROBOROCK_RRUID, USER_DATA, USE
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
from tests.service_info import MockDhcpServiceInfo
|
from tests.service_info import MockDhcpServiceInfo
|
||||||
|
|
||||||
DNCP_SERVICE_INFO = MockDhcpServiceInfo(
|
|
||||||
ip=NETWORK_INFO.ip,
|
|
||||||
macaddress=NETWORK_INFO.mac,
|
|
||||||
hostname="roborock-vacuum-a72",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cleanup_map_storage():
|
def cleanup_map_storage():
|
||||||
@ -352,7 +346,15 @@ async def test_discovery_not_setup(
|
|||||||
with (
|
with (
|
||||||
patch("homeassistant.components.roborock.async_setup_entry", return_value=True),
|
patch("homeassistant.components.roborock.async_setup_entry", return_value=True),
|
||||||
):
|
):
|
||||||
result = await DNCP_SERVICE_INFO.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_DHCP},
|
||||||
|
data=MockDhcpServiceInfo(
|
||||||
|
ip=NETWORK_INFO.ip,
|
||||||
|
macaddress=NETWORK_INFO.mac,
|
||||||
|
hostname="roborock-vacuum-a72",
|
||||||
|
),
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
with patch(
|
with patch(
|
||||||
@ -389,7 +391,15 @@ async def test_discovery_already_setup(
|
|||||||
"""Handle aborting if the device is already setup."""
|
"""Handle aborting if the device is already setup."""
|
||||||
await hass.config_entries.async_setup(mock_roborock_entry.entry_id)
|
await hass.config_entries.async_setup(mock_roborock_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
result = await DNCP_SERVICE_INFO.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_DHCP},
|
||||||
|
data=MockDhcpServiceInfo(
|
||||||
|
ip=NETWORK_INFO.ip,
|
||||||
|
macaddress=NETWORK_INFO.mac,
|
||||||
|
hostname="roborock-vacuum-a72",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
@ -5,7 +5,7 @@ from unittest.mock import AsyncMock, patch
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from homeassistant.components.wmspro.const import DOMAIN
|
from homeassistant.components.wmspro.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER, ConfigEntryState
|
from homeassistant.config_entries import SOURCE_DHCP, SOURCE_USER, ConfigEntryState
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -52,7 +52,9 @@ async def test_config_flow_from_dhcp(
|
|||||||
info = MockDhcpServiceInfo(
|
info = MockDhcpServiceInfo(
|
||||||
ip="1.2.3.4", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
ip="1.2.3.4", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
||||||
)
|
)
|
||||||
result = await info.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_DHCP}, data=info
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
@ -109,7 +111,9 @@ async def test_config_flow_from_dhcp_add_mac(
|
|||||||
info = MockDhcpServiceInfo(
|
info = MockDhcpServiceInfo(
|
||||||
ip="1.2.3.4", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
ip="1.2.3.4", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
||||||
)
|
)
|
||||||
result = await info.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_DHCP}, data=info
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
assert hass.config_entries.async_entries(DOMAIN)[0].unique_id == "00:11:22:33:44:55"
|
assert hass.config_entries.async_entries(DOMAIN)[0].unique_id == "00:11:22:33:44:55"
|
||||||
@ -124,7 +128,9 @@ async def test_config_flow_from_dhcp_ip_update(
|
|||||||
info = MockDhcpServiceInfo(
|
info = MockDhcpServiceInfo(
|
||||||
ip="1.2.3.4", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
ip="1.2.3.4", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
||||||
)
|
)
|
||||||
result = await info.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_DHCP}, data=info
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
@ -150,7 +156,9 @@ async def test_config_flow_from_dhcp_ip_update(
|
|||||||
info = MockDhcpServiceInfo(
|
info = MockDhcpServiceInfo(
|
||||||
ip="5.6.7.8", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
ip="5.6.7.8", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
||||||
)
|
)
|
||||||
result = await info.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_DHCP}, data=info
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
assert hass.config_entries.async_entries(DOMAIN)[0].unique_id == "00:11:22:33:44:55"
|
assert hass.config_entries.async_entries(DOMAIN)[0].unique_id == "00:11:22:33:44:55"
|
||||||
@ -166,7 +174,9 @@ async def test_config_flow_from_dhcp_no_update(
|
|||||||
info = MockDhcpServiceInfo(
|
info = MockDhcpServiceInfo(
|
||||||
ip="1.2.3.4", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
ip="1.2.3.4", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
||||||
)
|
)
|
||||||
result = await info.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_DHCP}, data=info
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
@ -192,7 +202,9 @@ async def test_config_flow_from_dhcp_no_update(
|
|||||||
info = MockDhcpServiceInfo(
|
info = MockDhcpServiceInfo(
|
||||||
ip="5.6.7.8", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
ip="5.6.7.8", hostname="webcontrol", macaddress="00:11:22:33:44:55"
|
||||||
)
|
)
|
||||||
result = await info.start_discovery_flow(hass, DOMAIN)
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_DHCP}, data=info
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
assert hass.config_entries.async_entries(DOMAIN)[0].unique_id == "00:11:22:33:44:55"
|
assert hass.config_entries.async_entries(DOMAIN)[0].unique_id == "00:11:22:33:44:55"
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant import config_entries
|
|
||||||
from homeassistant.config_entries import ConfigFlowResult
|
|
||||||
from homeassistant.core import HomeAssistant
|
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
|
from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
|
||||||
|
|
||||||
@ -22,11 +19,3 @@ class MockDhcpServiceInfo(DhcpServiceInfo):
|
|||||||
hostname=hostname,
|
hostname=hostname,
|
||||||
macaddress=dr.format_mac(macaddress).replace(":", ""),
|
macaddress=dr.format_mac(macaddress).replace(":", ""),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def start_discovery_flow(
|
|
||||||
self, hass: HomeAssistant, domain: str
|
|
||||||
) -> ConfigFlowResult:
|
|
||||||
"""Start a reauthentication flow."""
|
|
||||||
return await hass.config_entries.flow.async_init(
|
|
||||||
domain, context={"source": config_entries.SOURCE_DHCP}, data=self
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user