mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 07:51:46 -05:00
Report UniFi WAN latency as unknown when a monitor is unresponsive (#181809)
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Ariel Ebersberger <ariel@ebersberger.io>
This commit is contained in:
co-authored by
Claude Opus 5
Ariel Ebersberger
parent
10cd542566
commit
81bf0fef2e
@@ -263,7 +263,7 @@ def async_device_wan_latency_value_fn(
|
||||
# Checked by async_device_wan_latency_supported_fn
|
||||
assert target
|
||||
|
||||
return target.get("latency_average", 0)
|
||||
return target.get("latency_average")
|
||||
|
||||
|
||||
@callback
|
||||
|
||||
@@ -812,7 +812,7 @@
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0',
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_entity_and_device_data[wlan_payload0-device_payload0-client_payload0-config_entry_options0][sensor.mock_name_cloudflare_wan_latency-entry]
|
||||
@@ -928,7 +928,7 @@
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0',
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_entity_and_device_data[wlan_payload0-device_payload0-client_payload0-config_entry_options0][sensor.mock_name_google_wan_latency-entry]
|
||||
@@ -1044,7 +1044,7 @@
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0',
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_entity_and_device_data[wlan_payload0-device_payload0-client_payload0-config_entry_options0][sensor.mock_name_microsoft_wan_latency-entry]
|
||||
|
||||
@@ -1710,14 +1710,22 @@ async def test_device_uptime(
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("monitor_id", "state", "updated_state", "index_to_update"),
|
||||
("monitor_id", "state", "index_to_update", "monitor_update", "updated_state"),
|
||||
[
|
||||
# Microsoft
|
||||
("microsoft_wan", "56", "20", 0),
|
||||
# Google
|
||||
("google_wan", "53", "90", 1),
|
||||
# Cloudflare
|
||||
("cloudflare_wan", "30", "80", 2),
|
||||
pytest.param(
|
||||
"microsoft_wan", "56", 0, {"latency_average": 20}, "20", id="microsoft"
|
||||
),
|
||||
pytest.param("google_wan", "53", 1, {"latency_average": 90}, "90", id="google"),
|
||||
pytest.param(
|
||||
"cloudflare_wan", "30", 2, {"latency_average": 80}, "80", id="cloudflare"
|
||||
),
|
||||
pytest.param(
|
||||
"microsoft_wan", "56", 0, {}, STATE_UNKNOWN, id="microsoft_no_response"
|
||||
),
|
||||
pytest.param("google_wan", "53", 1, {}, STATE_UNKNOWN, id="google_no_response"),
|
||||
pytest.param(
|
||||
"cloudflare_wan", "30", 2, {}, STATE_UNKNOWN, id="cloudflare_no_response"
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("config_entry_setup")
|
||||
@@ -1728,8 +1736,9 @@ async def test_wan_monitor_latency(
|
||||
device_payload: list[dict[str, Any]],
|
||||
monitor_id: str,
|
||||
state: str,
|
||||
updated_state: str,
|
||||
index_to_update: int,
|
||||
monitor_update: dict[str, Any],
|
||||
updated_state: str,
|
||||
) -> None:
|
||||
"""Verify that wan latency sensors are working as expected."""
|
||||
entity_id = f"sensor.mock_name_{monitor_id}_latency"
|
||||
@@ -1757,14 +1766,14 @@ async def test_wan_monitor_latency(
|
||||
# Verify sensor state
|
||||
assert hass.states.get(entity_id).state == state
|
||||
|
||||
# Verify state update
|
||||
device = device_payload[0]
|
||||
device["uptime_stats"]["WAN"]["monitors"][index_to_update]["latency_average"] = (
|
||||
updated_state
|
||||
)
|
||||
|
||||
# Update state
|
||||
device = deepcopy(device_payload[0])
|
||||
monitor = device["uptime_stats"]["WAN"]["monitors"][index_to_update]
|
||||
monitor.pop("latency_average")
|
||||
monitor.update(monitor_update)
|
||||
mock_websocket_message(message=MessageKey.DEVICE, data=device)
|
||||
|
||||
# Verify state update
|
||||
assert hass.states.get(entity_id).state == updated_state
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user