Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android TV Remote: Abort zeroconf if mac address is missing #94026

Merged
merged 1 commit into from
Jun 4, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/androidtv_remote/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ async def async_step_zeroconf(
self.host = discovery_info.host
self.name = discovery_info.name.removesuffix("._androidtvremote2._tcp.local.")
self.mac = discovery_info.properties.get("bt")
assert self.mac
if not self.mac:
return self.async_abort(reason="cannot_connect")
await self.async_set_unique_id(format_mac(self.mac))
self._abort_if_unique_id_configured(
updates={CONF_HOST: self.host, CONF_NAME: self.name}
Expand Down
24 changes: 24 additions & 0 deletions tests/components/androidtv_remote/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,30 @@ async def test_zeroconf_flow_already_configured_host_not_changed_no_reload_entry
assert len(mock_setup_entry.mock_calls) == 0


async def test_zeroconf_flow_abort_if_mac_is_missing(
hass: HomeAssistant,
) -> None:
"""Test when mac is missing in the zeroconf discovery we abort."""
host = "1.2.3.4"
name = "My Android TV"

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.ZeroconfServiceInfo(
host=host,
addresses=[host],
port=6466,
hostname=host,
type="mock_type",
name=name + "._androidtvremote2._tcp.local.",
properties={},
),
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "cannot_connect"


async def test_reauth_flow_success(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
Expand Down