mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Set a request timeout on the nx584 client (#189459)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
Claude Opus 5.5
multica-agent
parent
4fba66ddab
commit
67db1e2eb1
@@ -17,7 +17,7 @@ from homeassistant.helpers import config_validation as cv, issue_registry as ir
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import DEFAULT_NAME, DOMAIN
|
||||
from .const import DEFAULT_NAME, DOMAIN, REQUEST_TIMEOUT
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.platform_only_config_schema(DOMAIN)
|
||||
@@ -41,7 +41,9 @@ type NX584ConfigEntry = ConfigEntry[NX584Data]
|
||||
|
||||
def create_client(host: str, port: int) -> nx584_client.Client:
|
||||
"""Create a client for the NX584 server."""
|
||||
return nx584_client.Client(str(URL.build(scheme="http", host=host, port=port)))
|
||||
return nx584_client.Client(
|
||||
str(URL.build(scheme="http", host=host, port=port)), timeout=REQUEST_TIMEOUT
|
||||
)
|
||||
|
||||
|
||||
def _fetch_zones(client: nx584_client.Client) -> tuple[list[dict[str, Any]], str]:
|
||||
|
||||
@@ -8,3 +8,5 @@ CONF_ZONE_TYPES = "zone_types"
|
||||
DEFAULT_HOST = "localhost"
|
||||
DEFAULT_NAME = "NX584"
|
||||
DEFAULT_PORT = 5007
|
||||
|
||||
REQUEST_TIMEOUT = 10
|
||||
|
||||
@@ -12,6 +12,7 @@ from homeassistant.components.nx584.const import (
|
||||
CONF_EXCLUDE_ZONES,
|
||||
CONF_ZONE_TYPES,
|
||||
DOMAIN,
|
||||
REQUEST_TIMEOUT,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER, ConfigFlowResult
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
|
||||
@@ -84,7 +85,9 @@ async def test_user_flow(hass: HomeAssistant, mock_client: MagicMock) -> None:
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == f"{TEST_HOST}:{TEST_PORT}"
|
||||
assert result["data"] == {CONF_HOST: TEST_HOST, CONF_PORT: TEST_PORT}
|
||||
mock_client.assert_called_with(f"http://{TEST_HOST}:{TEST_PORT}")
|
||||
mock_client.assert_called_with(
|
||||
f"http://{TEST_HOST}:{TEST_PORT}", timeout=REQUEST_TIMEOUT
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
@@ -15,6 +15,7 @@ from homeassistant.components.nx584.const import (
|
||||
CONF_EXCLUDE_ZONES,
|
||||
CONF_ZONE_TYPES,
|
||||
DOMAIN,
|
||||
REQUEST_TIMEOUT,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_HOST, CONF_NAME, CONF_PORT
|
||||
@@ -79,7 +80,9 @@ async def test_setup_and_unload_entry(
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
assert mock_config_entry.runtime_data.client is mock_client.return_value
|
||||
mock_client.assert_called_with(f"http://{TEST_HOST}:{TEST_PORT}")
|
||||
mock_client.assert_called_with(
|
||||
f"http://{TEST_HOST}:{TEST_PORT}", timeout=REQUEST_TIMEOUT
|
||||
)
|
||||
assert hass.states.get("alarm_control_panel.nx584")
|
||||
assert hass.states.get("binary_sensor.front")
|
||||
mock_watcher.return_value.start.assert_called_once()
|
||||
@@ -105,7 +108,9 @@ async def test_setup_entry_ipv6_host(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
mock_client.assert_called_with(f"http://[fe80::1]:{TEST_PORT}")
|
||||
mock_client.assert_called_with(
|
||||
f"http://[fe80::1]:{TEST_PORT}", timeout=REQUEST_TIMEOUT
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user