Ensure homekit never picks a port that another config entry uses (#45433)
This commit is contained in:
parent
a64ad50b27
commit
463a32819c
6 changed files with 59 additions and 30 deletions
|
@ -49,7 +49,7 @@ async def test_setup_in_bridge_mode(hass):
|
|||
assert result2["step_id"] == "bridge_mode"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.homekit.config_flow.find_next_available_port",
|
||||
"homeassistant.components.homekit.config_flow.async_find_next_available_port",
|
||||
return_value=12345,
|
||||
):
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
|
@ -108,7 +108,7 @@ async def test_setup_in_accessory_mode(hass):
|
|||
assert result2["step_id"] == "accessory_mode"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.homekit.config_flow.find_next_available_port",
|
||||
"homeassistant.components.homekit.config_flow.async_find_next_available_port",
|
||||
return_value=12345,
|
||||
):
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
|
@ -629,7 +629,7 @@ async def test_converting_bridge_to_accessory_mode(hass):
|
|||
assert result2["step_id"] == "bridge_mode"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.homekit.config_flow.find_next_available_port",
|
||||
"homeassistant.components.homekit.config_flow.async_find_next_available_port",
|
||||
return_value=12345,
|
||||
):
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
|
|
|
@ -1020,10 +1020,7 @@ async def test_raise_config_entry_not_ready(hass, mock_zeroconf):
|
|||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.homekit.port_is_available",
|
||||
return_value=False,
|
||||
):
|
||||
with patch(f"{PATH_HOMEKIT}.HomeKit.setup", side_effect=OSError):
|
||||
assert not await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import pytest
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.homekit.const import (
|
||||
BRIDGE_NAME,
|
||||
CONF_FEATURE,
|
||||
CONF_FEATURE_LIST,
|
||||
CONF_LINKED_BATTERY_SENSOR,
|
||||
|
@ -21,11 +22,11 @@ from homeassistant.components.homekit.const import (
|
|||
TYPE_VALVE,
|
||||
)
|
||||
from homeassistant.components.homekit.util import (
|
||||
async_find_next_available_port,
|
||||
cleanup_name_for_homekit,
|
||||
convert_to_float,
|
||||
density_to_air_quality,
|
||||
dismiss_setup_message,
|
||||
find_next_available_port,
|
||||
format_sw_version,
|
||||
port_is_available,
|
||||
show_setup_message,
|
||||
|
@ -43,6 +44,7 @@ from homeassistant.const import (
|
|||
ATTR_CODE,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
CONF_NAME,
|
||||
CONF_PORT,
|
||||
CONF_TYPE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
|
@ -52,7 +54,7 @@ from homeassistant.core import State
|
|||
|
||||
from .util import async_init_integration
|
||||
|
||||
from tests.common import async_mock_service
|
||||
from tests.common import MockConfigEntry, async_mock_service
|
||||
|
||||
|
||||
def test_validate_entity_config():
|
||||
|
@ -251,14 +253,30 @@ async def test_dismiss_setup_msg(hass):
|
|||
|
||||
async def test_port_is_available(hass):
|
||||
"""Test we can get an available port and it is actually available."""
|
||||
next_port = await hass.async_add_executor_job(
|
||||
find_next_available_port, DEFAULT_CONFIG_FLOW_PORT
|
||||
)
|
||||
next_port = await async_find_next_available_port(hass, DEFAULT_CONFIG_FLOW_PORT)
|
||||
|
||||
assert next_port
|
||||
|
||||
assert await hass.async_add_executor_job(port_is_available, next_port)
|
||||
|
||||
|
||||
async def test_port_is_available_skips_existing_entries(hass):
|
||||
"""Test we can get an available port and it is actually available."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_NAME: BRIDGE_NAME, CONF_PORT: DEFAULT_CONFIG_FLOW_PORT},
|
||||
options={},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
next_port = await async_find_next_available_port(hass, DEFAULT_CONFIG_FLOW_PORT)
|
||||
|
||||
assert next_port
|
||||
assert next_port != DEFAULT_CONFIG_FLOW_PORT
|
||||
|
||||
assert await hass.async_add_executor_job(port_is_available, next_port)
|
||||
|
||||
|
||||
async def test_format_sw_version():
|
||||
"""Test format_sw_version method."""
|
||||
assert format_sw_version("soho+3.6.8+soho-release-rt120+10") == "3.6.8"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue