diff --git a/tests/common.py b/tests/common.py index 9f7e19cf99a..d439021a9df 100644 --- a/tests/common.py +++ b/tests/common.py @@ -98,7 +98,6 @@ from homeassistant.helpers.entity_platform import ( AddEntitiesCallback, ) from homeassistant.helpers.json import JSONEncoder, _orjson_default_encoder, json_dumps -from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import dt as dt_util, ulid as ulid_util, uuid as uuid_util from homeassistant.util.async_ import ( @@ -1954,26 +1953,3 @@ def get_schema_suggested_value(schema: vol.Schema, key: str) -> Any | None: return None return schema_key.description["suggested_value"] return None - - -class MockDhcpServiceInfo(DhcpServiceInfo): - """Mocked DHCP service info.""" - - def __init__(self, ip: str, hostname: str, macaddress: str) -> None: - """Initialize the mock service info.""" - # Historically, the MAC address was formatted without colons - # and since all consumers of this data are expecting it to be - # formatted without colons we will continue to do so - super().__init__( - ip=ip, - hostname=hostname, - 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 - ) diff --git a/tests/components/airthings/test_config_flow.py b/tests/components/airthings/test_config_flow.py index c6124054bb9..68fa677c9d2 100644 --- a/tests/components/airthings/test_config_flow.py +++ b/tests/components/airthings/test_config_flow.py @@ -11,7 +11,8 @@ from homeassistant.const import CONF_ID from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType -from tests.common import MockConfigEntry, MockDhcpServiceInfo +from tests.common import MockConfigEntry +from tests.service_info import MockDhcpServiceInfo TEST_DATA = { CONF_ID: "client_id", diff --git a/tests/components/airzone/test_config_flow.py b/tests/components/airzone/test_config_flow.py index 91cd1fe21db..fa40d04a94d 100644 --- a/tests/components/airzone/test_config_flow.py +++ b/tests/components/airzone/test_config_flow.py @@ -28,7 +28,8 @@ from .util import ( USER_INPUT, ) -from tests.common import MockConfigEntry, MockDhcpServiceInfo +from tests.common import MockConfigEntry +from tests.service_info import MockDhcpServiceInfo DHCP_SERVICE_INFO = MockDhcpServiceInfo( hostname="airzone", diff --git a/tests/components/roborock/test_config_flow.py b/tests/components/roborock/test_config_flow.py index 876b4991f8a..f2e093a49f9 100644 --- a/tests/components/roborock/test_config_flow.py +++ b/tests/components/roborock/test_config_flow.py @@ -22,7 +22,8 @@ from homeassistant.data_entry_flow import FlowResultType from .mock_data import MOCK_CONFIG, NETWORK_INFO, ROBOROCK_RRUID, USER_DATA, USER_EMAIL -from tests.common import MockConfigEntry, MockDhcpServiceInfo +from tests.common import MockConfigEntry +from tests.service_info import MockDhcpServiceInfo DNCP_SERVICE_INFO = MockDhcpServiceInfo( ip=NETWORK_INFO.ip, diff --git a/tests/components/wmspro/test_config_flow.py b/tests/components/wmspro/test_config_flow.py index a82441c6478..39efcb41d65 100644 --- a/tests/components/wmspro/test_config_flow.py +++ b/tests/components/wmspro/test_config_flow.py @@ -12,7 +12,8 @@ from homeassistant.data_entry_flow import FlowResultType from . import setup_config_entry -from tests.common import MockConfigEntry, MockDhcpServiceInfo +from tests.common import MockConfigEntry +from tests.service_info import MockDhcpServiceInfo async def test_config_flow( diff --git a/tests/service_info.py b/tests/service_info.py new file mode 100644 index 00000000000..0ed387e87a6 --- /dev/null +++ b/tests/service_info.py @@ -0,0 +1,32 @@ +"""Service info test helpers.""" + +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.service_info.dhcp import DhcpServiceInfo + + +class MockDhcpServiceInfo(DhcpServiceInfo): + """Mocked DHCP service info.""" + + def __init__(self, ip: str, hostname: str, macaddress: str) -> None: + """Initialize the mock service info.""" + # Historically, the MAC address was formatted without colons + # and since all consumers of this data are expecting it to be + # formatted without colons we will continue to do so + super().__init__( + ip=ip, + hostname=hostname, + 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 + )