Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions tests/components/apple_tv/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
import pytest

from homeassistant import config_entries, data_entry_flow
from homeassistant.components import zeroconf
from homeassistant.components.apple_tv.const import CONF_START_OFF, DOMAIN

from tests.common import MockConfigEntry

DMAP_SERVICE = {
"type": "_touch-able._tcp.local.",
"name": "dmapid.something",
"properties": {"CtlN": "Apple TV"},
}
DMAP_SERVICE = zeroconf.HaServiceInfo(
type="_touch-able._tcp.local.",
name="dmapid.something",
properties={"CtlN": "Apple TV"},
)


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -399,10 +400,10 @@ async def test_zeroconf_unsupported_service_aborts(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data={
"type": "_dummy._tcp.local.",
"properties": {},
},
data=zeroconf.HaServiceInfo(
type="_dummy._tcp.local.",
properties={},
),
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "unknown"
Expand All @@ -413,10 +414,10 @@ async def test_zeroconf_add_mrp_device(hass, mrp_device, pairing):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data={
"type": "_mediaremotetv._tcp.local.",
"properties": {"UniqueIdentifier": "mrpid", "Name": "Kitchen"},
},
data=zeroconf.HaServiceInfo(
type="_mediaremotetv._tcp.local.",
properties={"UniqueIdentifier": "mrpid", "Name": "Kitchen"},
),
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["description_placeholders"] == {"name": "MRP Device"}
Expand Down
65 changes: 33 additions & 32 deletions tests/components/axis/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import respx

from homeassistant import data_entry_flow
from homeassistant.components import zeroconf
from homeassistant.components.axis import config_flow
from homeassistant.components.axis.const import (
CONF_EVENTS,
Expand Down Expand Up @@ -292,17 +293,17 @@ async def test_reauth_flow_update_configuration(hass):
),
(
SOURCE_ZEROCONF,
{
"host": DEFAULT_HOST,
"port": 80,
"hostname": f"axis-{MAC.lower()}.local.",
"type": "_axis-video._tcp.local.",
"name": f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
"properties": {
zeroconf.HaServiceInfo(
host=DEFAULT_HOST,
port=80,
hostname=f"axis-{MAC.lower()}.local.",
type="_axis-video._tcp.local.",
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
properties={
"_raw": {"macaddress": MAC.encode()},
"macaddress": MAC,
},
},
),
),
],
)
Expand Down Expand Up @@ -362,12 +363,12 @@ async def test_discovery_flow(hass, source: str, discovery_info: dict):
),
(
SOURCE_ZEROCONF,
{
CONF_HOST: DEFAULT_HOST,
CONF_PORT: 80,
"name": f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
"properties": {"macaddress": MAC},
},
zeroconf.HaServiceInfo(
host=DEFAULT_HOST,
port=80,
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
properties={"macaddress": MAC},
),
),
],
)
Expand Down Expand Up @@ -410,12 +411,12 @@ async def test_discovered_device_already_configured(
),
(
SOURCE_ZEROCONF,
{
CONF_HOST: "2.3.4.5",
CONF_PORT: 8080,
"name": f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
"properties": {"macaddress": MAC},
},
zeroconf.HaServiceInfo(
host="2.3.4.5",
port=8080,
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
properties={"macaddress": MAC},
),
8080,
),
],
Expand Down Expand Up @@ -478,12 +479,12 @@ async def test_discovery_flow_updated_configuration(
),
(
SOURCE_ZEROCONF,
{
CONF_HOST: "",
CONF_PORT: 0,
"name": "",
"properties": {"macaddress": "01234567890"},
},
zeroconf.HaServiceInfo(
host="",
port=0,
name="",
properties={"macaddress": "01234567890"},
),
),
],
)
Expand Down Expand Up @@ -516,12 +517,12 @@ async def test_discovery_flow_ignore_non_axis_device(
),
(
SOURCE_ZEROCONF,
{
CONF_HOST: "169.254.3.4",
CONF_PORT: 80,
"name": f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
"properties": {"macaddress": MAC},
},
zeroconf.HaServiceInfo(
host="169.254.3.4",
port=80,
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
properties={"macaddress": MAC},
),
),
],
)
Expand Down
45 changes: 26 additions & 19 deletions tests/components/bond/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from aiohttp import ClientConnectionError, ClientResponseError

from homeassistant import config_entries, core
from homeassistant.components import zeroconf
from homeassistant.components.bond.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST
Expand Down Expand Up @@ -196,7 +197,9 @@ async def test_zeroconf_form(hass: core.HomeAssistant):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data={"name": "test-bond-id.some-other-tail-info", "host": "test-host"},
data=zeroconf.HaServiceInfo(
name="test-bond-id.some-other-tail-info", host="test-host"
),
)
assert result["type"] == "form"
assert result["errors"] == {}
Expand Down Expand Up @@ -226,7 +229,9 @@ async def test_zeroconf_form_token_unavailable(hass: core.HomeAssistant):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data={"name": "test-bond-id.some-other-tail-info", "host": "test-host"},
data=zeroconf.HaServiceInfo(
name="test-bond-id.some-other-tail-info", host="test-host"
),
)
await hass.async_block_till_done()
assert result["type"] == "form"
Expand Down Expand Up @@ -259,7 +264,9 @@ async def test_zeroconf_form_with_token_available(hass: core.HomeAssistant):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data={"name": "test-bond-id.some-other-tail-info", "host": "test-host"},
data=zeroconf.HaServiceInfo(
name="test-bond-id.some-other-tail-info", host="test-host"
),
)
await hass.async_block_till_done()
assert result["type"] == "form"
Expand Down Expand Up @@ -295,10 +302,10 @@ async def test_zeroconf_already_configured(hass: core.HomeAssistant):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data={
"name": "already-registered-bond-id.some-other-tail-info",
"host": "updated-host",
},
data=zeroconf.HaServiceInfo(
name="already-registered-bond-id.some-other-tail-info",
host="updated-host",
),
)

assert result["type"] == "abort"
Expand Down Expand Up @@ -336,10 +343,10 @@ async def test_zeroconf_already_configured_refresh_token(hass: core.HomeAssistan
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data={
"name": "already-registered-bond-id.some-other-tail-info",
"host": "updated-host",
},
data=zeroconf.HaServiceInfo(
name="already-registered-bond-id.some-other-tail-info",
host="updated-host",
),
)
await hass.async_block_till_done()

Expand Down Expand Up @@ -369,10 +376,10 @@ async def test_zeroconf_already_configured_no_reload_same_host(
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data={
"name": "already-registered-bond-id.some-other-tail-info",
"host": "stored-host",
},
data=zeroconf.HaServiceInfo(
name="already-registered-bond-id.some-other-tail-info",
host="stored-host",
),
)
await hass.async_block_till_done()

Expand All @@ -386,10 +393,10 @@ async def test_zeroconf_form_unexpected_error(hass: core.HomeAssistant):
await _help_test_form_unexpected_error(
hass,
source=config_entries.SOURCE_ZEROCONF,
initial_input={
"name": "test-bond-id.some-other-tail-info",
"host": "test-host",
},
initial_input=zeroconf.HaServiceInfo(
name="test-bond-id.some-other-tail-info",
host="test-host",
),
user_input={CONF_ACCESS_TOKEN: "test-token"},
error=Exception(),
)
Expand Down
31 changes: 16 additions & 15 deletions tests/components/bosch_shc/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from boschshcpy.information import SHCInformation

from homeassistant import config_entries
from homeassistant.components import zeroconf
from homeassistant.components.bosch_shc.config_flow import write_tls_asset
from homeassistant.components.bosch_shc.const import CONF_SHC_CERT, CONF_SHC_KEY, DOMAIN

Expand All @@ -19,13 +20,13 @@
"name": "Test name",
"device": {"mac": "test-mac", "hostname": "test-host"},
}
DISCOVERY_INFO = {
"host": ["169.1.1.1", "1.1.1.1"],
"port": 0,
"hostname": "shc012345.local.",
"type": "_http._tcp.local.",
"name": "Bosch SHC [test-mac]._http._tcp.local.",
}
DISCOVERY_INFO = zeroconf.HaServiceInfo(
host=["169.1.1.1", "1.1.1.1"],
port=0,
hostname="shc012345.local.",
type="_http._tcp.local.",
name="Bosch SHC [test-mac]._http._tcp.local.",
)


async def test_form_user(hass, mock_zeroconf):
Expand Down Expand Up @@ -527,13 +528,13 @@ async def test_zeroconf_cannot_connect(hass, mock_zeroconf):

async def test_zeroconf_link_local(hass, mock_zeroconf):
"""Test we get the form."""
DISCOVERY_INFO_LINK_LOCAL = {
"host": ["169.1.1.1"],
"port": 0,
"hostname": "shc012345.local.",
"type": "_http._tcp.local.",
"name": "Bosch SHC [test-mac]._http._tcp.local.",
}
DISCOVERY_INFO_LINK_LOCAL = zeroconf.HaServiceInfo(
host=["169.1.1.1"],
port=0,
hostname="shc012345.local.",
type="_http._tcp.local.",
name="Bosch SHC [test-mac]._http._tcp.local.",
)

with patch(
"boschshcpy.session.SHCSession.mdns_info", side_effect=SHCConnectionError
Expand All @@ -551,7 +552,7 @@ async def test_zeroconf_not_bosch_shc(hass, mock_zeroconf):
"""Test we filter out non-bosch_shc devices."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
data={"host": "1.1.1.1", "name": "notboschshc"},
data=zeroconf.HaServiceInfo(host="1.1.1.1", name="notboschshc"),
context={"source": config_entries.SOURCE_ZEROCONF},
)
assert result["type"] == "abort"
Expand Down
25 changes: 16 additions & 9 deletions tests/components/brother/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from brother import SnmpError, UnsupportedModel

from homeassistant import data_entry_flow
from homeassistant.components import zeroconf
from homeassistant.components.brother.const import DOMAIN
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.const import CONF_HOST, CONF_TYPE
Expand Down Expand Up @@ -143,7 +144,9 @@ async def test_zeroconf_snmp_error(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "name": "Brother Printer"},
data=zeroconf.HaServiceInfo(
hostname="example.local.", name="Brother Printer"
),
)

assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
Expand All @@ -156,11 +159,11 @@ async def test_zeroconf_unsupported_model(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={
"hostname": "example.local.",
"name": "Brother Printer",
"properties": {"product": "MFC-8660DN"},
},
data=zeroconf.HaServiceInfo(
hostname="example.local.",
name="Brother Printer",
properties={"product": "MFC-8660DN"},
),
)

assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
Expand All @@ -181,7 +184,9 @@ async def test_zeroconf_device_exists_abort(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "name": "Brother Printer"},
data=zeroconf.HaServiceInfo(
hostname="example.local.", name="Brother Printer"
),
)

assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
Expand All @@ -196,7 +201,7 @@ async def test_zeroconf_no_probe_existing_device(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "localhost", "name": "Brother Printer"},
data=zeroconf.HaServiceInfo(hostname="localhost", name="Brother Printer"),
)
await hass.async_block_till_done()

Expand All @@ -215,7 +220,9 @@ async def test_zeroconf_confirm_create_entry(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "name": "Brother Printer"},
data=zeroconf.HaServiceInfo(
hostname="example.local.", name="Brother Printer"
),
)

assert result["step_id"] == "zeroconf_confirm"
Expand Down
Loading