mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 00:27:19 +00:00
Move to service_info
This commit is contained in:
parent
594769aa95
commit
864882750d
@ -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
|
||||
)
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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,
|
||||
|
@ -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(
|
||||
|
32
tests/service_info.py
Normal file
32
tests/service_info.py
Normal file
@ -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
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user