Fix manual specification of multiple advertise_ip with HomeKit (#95548)

fixes #95508
This commit is contained in:
J. Nick Koston 2023-06-29 10:35:32 -05:00 committed by GitHub
parent 8e00bd4436
commit e3e1bef376
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 1 deletions

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import asyncio
from typing import Any
from unittest.mock import ANY, AsyncMock, MagicMock, Mock, patch
from uuid import uuid1
@ -24,6 +25,7 @@ from homeassistant.components.homekit.accessories import HomeBridge
from homeassistant.components.homekit.const import (
BRIDGE_NAME,
BRIDGE_SERIAL_NUMBER,
CONF_ADVERTISE_IP,
DEFAULT_PORT,
DOMAIN,
HOMEKIT,
@ -322,6 +324,80 @@ async def test_homekit_setup_ip_address(
)
async def test_homekit_with_single_advertise_ips(
hass: HomeAssistant,
hk_driver,
mock_async_zeroconf: None,
hass_storage: dict[str, Any],
) -> None:
"""Test setup with a single advertise ips."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_NAME: "mock_name", CONF_PORT: 12345, CONF_ADVERTISE_IP: "1.3.4.4"},
source=SOURCE_IMPORT,
)
entry.add_to_hass(hass)
with patch(f"{PATH_HOMEKIT}.HomeDriver", return_value=hk_driver) as mock_driver:
mock_driver.async_start = AsyncMock()
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
mock_driver.assert_called_with(
hass,
entry.entry_id,
ANY,
entry.title,
loop=hass.loop,
address=[None],
port=ANY,
persist_file=ANY,
advertised_address="1.3.4.4",
async_zeroconf_instance=mock_async_zeroconf,
zeroconf_server=ANY,
loader=ANY,
iid_storage=ANY,
)
async def test_homekit_with_many_advertise_ips(
hass: HomeAssistant,
hk_driver,
mock_async_zeroconf: None,
hass_storage: dict[str, Any],
) -> None:
"""Test setup with many advertise ips."""
entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_NAME: "mock_name",
CONF_PORT: 12345,
CONF_ADVERTISE_IP: ["1.3.4.4", "4.3.2.2"],
},
source=SOURCE_IMPORT,
)
entry.add_to_hass(hass)
with patch(f"{PATH_HOMEKIT}.HomeDriver", return_value=hk_driver) as mock_driver:
mock_driver.async_start = AsyncMock()
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
mock_driver.assert_called_with(
hass,
entry.entry_id,
ANY,
entry.title,
loop=hass.loop,
address=[None],
port=ANY,
persist_file=ANY,
advertised_address=["1.3.4.4", "4.3.2.2"],
async_zeroconf_instance=mock_async_zeroconf,
zeroconf_server=ANY,
loader=ANY,
iid_storage=ANY,
)
async def test_homekit_setup_advertise_ips(
hass: HomeAssistant, hk_driver, mock_async_zeroconf: None
) -> None: