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
8 changes: 4 additions & 4 deletions homeassistant/components/zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# Dns label max length
MAX_NAME_LEN = 63

# Attributes for HaServiceInfo
# Attributes for ZeroconfServiceInfo
ATTR_HOST: Final = "host"
ATTR_HOSTNAME: Final = "hostname"
ATTR_NAME: Final = "name"
Expand All @@ -87,7 +87,7 @@
)


class HaServiceInfo(TypedDict):
class ZeroconfServiceInfo(TypedDict):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we could use ZeroconfDiscoveryInfo to match the generic DiscoveryInfoType?

Suggested change
class ZeroconfServiceInfo(TypedDict):
class ZeroconfDiscoveryInfo(TypedDict):

Copy link
Copy Markdown
Member

@frenck frenck Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current suggestion (ZeroconfServiceInfo) is fine. It matches what is represented in Zeroconfig itself.

If anything, I would maybe even call it just "ServiceInfo", as it is already in the Zeroconf package namespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I wait for @bdraco to confirm that he too prefers just ServiceInfo?
I've marked the other PRs as draft until this one gets merged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the ZeroconfServiceInfo name because there are some integrations that have multiple discovery sources and it will easier to differentiate with something like SSDPServiceInfo, DHCPserviceInfo.

Copy link
Copy Markdown
Member

@frenck frenck Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with that :)
Do you approve otherwise @bdraco ?

"""Prepared info from mDNS entries."""

host: str
Expand Down Expand Up @@ -466,7 +466,7 @@ def async_get_homekit_discovery_domain(
return None


def info_from_service(service: AsyncServiceInfo) -> HaServiceInfo | None:
def info_from_service(service: AsyncServiceInfo) -> ZeroconfServiceInfo | None:
"""Return prepared info from mDNS entries."""
properties: dict[str, Any] = {"_raw": {}}

Expand All @@ -493,7 +493,7 @@ def info_from_service(service: AsyncServiceInfo) -> HaServiceInfo | None:
if (host := _first_non_link_local_or_v6_address(addresses)) is None:
return None

return HaServiceInfo(
return ZeroconfServiceInfo(
host=str(host),
port=service.port,
hostname=service.server,
Expand Down
6 changes: 3 additions & 3 deletions tests/components/apple_tv/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from tests.common import MockConfigEntry

DMAP_SERVICE = zeroconf.HaServiceInfo(
DMAP_SERVICE = zeroconf.ZeroconfServiceInfo(
type="_touch-able._tcp.local.",
name="dmapid.something",
properties={"CtlN": "Apple TV"},
Expand Down Expand Up @@ -400,7 +400,7 @@ async def test_zeroconf_unsupported_service_aborts(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
type="_dummy._tcp.local.",
properties={},
),
Expand All @@ -414,7 +414,7 @@ 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=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
type="_mediaremotetv._tcp.local.",
properties={"UniqueIdentifier": "mrpid", "Name": "Kitchen"},
),
Expand Down
10 changes: 5 additions & 5 deletions tests/components/axis/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ async def test_reauth_flow_update_configuration(hass):
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host=DEFAULT_HOST,
port=80,
hostname=f"axis-{MAC.lower()}.local.",
Expand Down Expand Up @@ -363,7 +363,7 @@ async def test_discovery_flow(hass, source: str, discovery_info: dict):
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host=DEFAULT_HOST,
port=80,
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
Expand Down Expand Up @@ -411,7 +411,7 @@ async def test_discovered_device_already_configured(
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host="2.3.4.5",
port=8080,
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
Expand Down Expand Up @@ -479,7 +479,7 @@ async def test_discovery_flow_updated_configuration(
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host="",
port=0,
name="",
Expand Down Expand Up @@ -517,7 +517,7 @@ async def test_discovery_flow_ignore_non_axis_device(
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host="169.254.3.4",
port=80,
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
Expand Down
14 changes: 7 additions & 7 deletions tests/components/bond/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async def test_zeroconf_form(hass: core.HomeAssistant):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="test-bond-id.some-other-tail-info", host="test-host"
),
)
Expand Down Expand Up @@ -229,7 +229,7 @@ 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=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="test-bond-id.some-other-tail-info", host="test-host"
),
)
Expand Down Expand Up @@ -264,7 +264,7 @@ 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=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="test-bond-id.some-other-tail-info", host="test-host"
),
)
Expand Down Expand Up @@ -302,7 +302,7 @@ 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=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="already-registered-bond-id.some-other-tail-info",
host="updated-host",
),
Expand Down Expand Up @@ -343,7 +343,7 @@ 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=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="already-registered-bond-id.some-other-tail-info",
host="updated-host",
),
Expand Down Expand Up @@ -376,7 +376,7 @@ 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=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="already-registered-bond-id.some-other-tail-info",
host="stored-host",
),
Expand All @@ -393,7 +393,7 @@ async def test_zeroconf_form_unexpected_error(hass: core.HomeAssistant):
await _help_test_form_unexpected_error(
hass,
source=config_entries.SOURCE_ZEROCONF,
initial_input=zeroconf.HaServiceInfo(
initial_input=zeroconf.ZeroconfServiceInfo(
name="test-bond-id.some-other-tail-info",
host="test-host",
),
Expand Down
6 changes: 3 additions & 3 deletions tests/components/bosch_shc/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"name": "Test name",
"device": {"mac": "test-mac", "hostname": "test-host"},
}
DISCOVERY_INFO = zeroconf.HaServiceInfo(
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
host=["169.1.1.1", "1.1.1.1"],
port=0,
hostname="shc012345.local.",
Expand Down Expand Up @@ -528,7 +528,7 @@ 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 = zeroconf.HaServiceInfo(
DISCOVERY_INFO_LINK_LOCAL = zeroconf.ZeroconfServiceInfo(
host=["169.1.1.1"],
port=0,
hostname="shc012345.local.",
Expand All @@ -552,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=zeroconf.HaServiceInfo(host="1.1.1.1", name="notboschshc"),
data=zeroconf.ZeroconfServiceInfo(host="1.1.1.1", name="notboschshc"),
context={"source": config_entries.SOURCE_ZEROCONF},
)
assert result["type"] == "abort"
Expand Down
12 changes: 7 additions & 5 deletions tests/components/brother/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async def test_zeroconf_snmp_error(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
hostname="example.local.", name="Brother Printer"
),
)
Expand All @@ -159,7 +159,7 @@ async def test_zeroconf_unsupported_model(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
hostname="example.local.",
name="Brother Printer",
properties={"product": "MFC-8660DN"},
Expand All @@ -184,7 +184,7 @@ async def test_zeroconf_device_exists_abort(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
hostname="example.local.", name="Brother Printer"
),
)
Expand All @@ -201,7 +201,9 @@ async def test_zeroconf_no_probe_existing_device(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(hostname="localhost", name="Brother Printer"),
data=zeroconf.ZeroconfServiceInfo(
hostname="localhost", name="Brother Printer"
),
)
await hass.async_block_till_done()

Expand All @@ -220,7 +222,7 @@ async def test_zeroconf_confirm_create_entry(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
hostname="example.local.", name="Brother Printer"
),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/components/daikin/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async def test_api_password_abort(hass):
@pytest.mark.parametrize(
"source, data, unique_id",
[
(SOURCE_ZEROCONF, zeroconf.HaServiceInfo(host=HOST), MAC),
(SOURCE_ZEROCONF, zeroconf.ZeroconfServiceInfo(host=HOST), MAC),
],
)
async def test_discovery_zeroconf(
Expand Down
8 changes: 5 additions & 3 deletions tests/components/devolo_home_control/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from homeassistant.components import zeroconf

DISCOVERY_INFO = zeroconf.HaServiceInfo(
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
host="192.168.0.1",
port=14791,
hostname="test.local.",
Expand All @@ -19,6 +19,8 @@
},
)

DISCOVERY_INFO_WRONG_DEVOLO_DEVICE = zeroconf.HaServiceInfo(properties={"MT": "2700"})
DISCOVERY_INFO_WRONG_DEVOLO_DEVICE = zeroconf.ZeroconfServiceInfo(
properties={"MT": "2700"}
)

DISCOVERY_INFO_WRONG_DEVICE = zeroconf.HaServiceInfo(properties={"Features": ""})
DISCOVERY_INFO_WRONG_DEVICE = zeroconf.ZeroconfServiceInfo(properties={"Features": ""})
4 changes: 2 additions & 2 deletions tests/components/devolo_home_network/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
}

DISCOVERY_INFO = zeroconf.HaServiceInfo(
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
host=IP,
port=14791,
hostname="test.local.",
Expand All @@ -36,7 +36,7 @@
},
)

DISCOVERY_INFO_WRONG_DEVICE = zeroconf.HaServiceInfo(properties={"MT": "2600"})
DISCOVERY_INFO_WRONG_DEVICE = zeroconf.ZeroconfServiceInfo(properties={"MT": "2600"})

NEIGHBOR_ACCESS_POINTS = {
"neighbor_aps": [
Expand Down
8 changes: 4 additions & 4 deletions tests/components/doorbird/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def test_form_zeroconf_wrong_oui(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"macaddress": "notdoorbirdoui"},
host="192.168.1.8",
name="Doorstation - abc123._axis-video._tcp.local.",
Expand All @@ -98,7 +98,7 @@ async def test_form_zeroconf_link_local_ignored(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"macaddress": "1CCAE3DOORBIRD"},
host="169.254.103.61",
name="Doorstation - abc123._axis-video._tcp.local.",
Expand All @@ -121,7 +121,7 @@ async def test_form_zeroconf_correct_oui(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"macaddress": "1CCAE3DOORBIRD"},
name="Doorstation - abc123._axis-video._tcp.local.",
host="192.168.1.5",
Expand Down Expand Up @@ -180,7 +180,7 @@ async def test_form_zeroconf_correct_oui_wrong_device(hass, doorbell_state_side_
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"macaddress": "1CCAE3DOORBIRD"},
name="Doorstation - abc123._axis-video._tcp.local.",
host="192.168.1.5",
Expand Down
6 changes: 3 additions & 3 deletions tests/components/enphase_envoy/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"serialnum": "1234"},
host="1.1.1.1",
),
Expand Down Expand Up @@ -254,7 +254,7 @@ async def test_zeroconf_serial_already_exists(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"serialnum": "1234"},
host="1.1.1.1",
),
Expand Down Expand Up @@ -289,7 +289,7 @@ async def test_zeroconf_host_already_exists(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"serialnum": "1234"},
host="1.1.1.1",
),
Expand Down
2 changes: 1 addition & 1 deletion tests/components/freebox/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from tests.common import MockConfigEntry

MOCK_ZEROCONF_DATA = zeroconf.HaServiceInfo(
MOCK_ZEROCONF_DATA = zeroconf.ZeroconfServiceInfo(
host="192.168.0.254",
port=80,
hostname="Freebox-Server.local.",
Expand Down
4 changes: 2 additions & 2 deletions tests/components/lookin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from aiolookin import Climate, Device, Remote

from homeassistant.components.zeroconf import HaServiceInfo
from homeassistant.components.zeroconf import ZeroconfServiceInfo

DEVICE_ID = "98F33163"
MODULE = "homeassistant.components.lookin"
Expand All @@ -17,7 +17,7 @@

ZC_NAME = f"LOOKin_{DEVICE_ID}"
ZC_TYPE = "_lookin._tcp."
ZEROCONF_DATA: HaServiceInfo = {
ZEROCONF_DATA: ZeroconfServiceInfo = {
"host": IP_ADDRESS,
"hostname": f"{ZC_NAME.lower()}.local.",
"port": 80,
Expand Down