Add diagnostics to Starlink (#86328)
This commit is contained in:
parent
0630b7b962
commit
c33ca4f664
6 changed files with 202 additions and 7 deletions
|
@ -8,7 +8,7 @@ from homeassistant.core import HomeAssistant
|
|||
from .const import DOMAIN
|
||||
from .coordinator import StarlinkUpdateCoordinator
|
||||
|
||||
PLATFORMS: list[Platform] = [
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.BUTTON,
|
||||
Platform.SENSOR,
|
||||
|
|
21
homeassistant/components/starlink/diagnostics.py
Normal file
21
homeassistant/components/starlink/diagnostics.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
"""Fetches diagnostic data for Starlink systems."""
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics.util import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import StarlinkUpdateCoordinator
|
||||
|
||||
TO_REDACT = {"id"}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for Starlink config entries."""
|
||||
coordinator: StarlinkUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
return async_redact_data(asdict(coordinator.data), TO_REDACT)
|
70
tests/components/starlink/fixtures/status_data_success.json
Normal file
70
tests/components/starlink/fixtures/status_data_success.json
Normal file
|
@ -0,0 +1,70 @@
|
|||
[
|
||||
{
|
||||
"id": "ut00000000-00000000-000000aa",
|
||||
"hardware_version": "rev3_proto2",
|
||||
"software_version": "191e4dfa-d63a-46b1-a73b-9fa907733864.uterm.release",
|
||||
"state": "CONNECTED",
|
||||
"uptime": 804138,
|
||||
"snr": null,
|
||||
"seconds_to_first_nonempty_slot": 0.0,
|
||||
"pop_ping_drop_rate": 0.0,
|
||||
"downlink_throughput_bps": 10108.2724609375,
|
||||
"uplink_throughput_bps": 11802.771484375,
|
||||
"pop_ping_latency_ms": 30.285715103149414,
|
||||
"alerts": 0,
|
||||
"fraction_obstructed": 0.0,
|
||||
"currently_obstructed": false,
|
||||
"seconds_obstructed": null,
|
||||
"obstruction_duration": null,
|
||||
"obstruction_interval": null,
|
||||
"direction_azimuth": -179.00344848632812,
|
||||
"direction_elevation": 68.67173767089844,
|
||||
"is_snr_above_noise_floor": true
|
||||
},
|
||||
{
|
||||
"wedges_fraction_obstructed[]": [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
],
|
||||
"raw_wedges_fraction_obstructed[]": [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
],
|
||||
"valid_s": 803872.0
|
||||
},
|
||||
{
|
||||
"alert_motors_stuck": false,
|
||||
"alert_thermal_throttle": false,
|
||||
"alert_thermal_shutdown": false,
|
||||
"alert_mast_not_near_vertical": false,
|
||||
"alert_unexpected_location": false,
|
||||
"alert_slow_ethernet_speeds": false,
|
||||
"alert_roaming": false,
|
||||
"alert_install_pending": false,
|
||||
"alert_is_heating": false,
|
||||
"alert_power_supply_thermal_throttle": false,
|
||||
"alert_is_power_save_idle": false,
|
||||
"alert_moving_while_not_mobile": false,
|
||||
"alert_moving_fast_while_not_aviation": false
|
||||
}
|
||||
]
|
|
@ -1,7 +1,8 @@
|
|||
"""General Starlink patchers."""
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from starlink_grpc import StatusDict
|
||||
from tests.common import load_fixture
|
||||
|
||||
SETUP_ENTRY_PATCHER = patch(
|
||||
"homeassistant.components.starlink.async_setup_entry", return_value=True
|
||||
|
@ -9,11 +10,7 @@ SETUP_ENTRY_PATCHER = patch(
|
|||
|
||||
COORDINATOR_SUCCESS_PATCHER = patch(
|
||||
"homeassistant.components.starlink.coordinator.status_data",
|
||||
return_value=[
|
||||
StatusDict(id="1", software_version="1", hardware_version="1"),
|
||||
{},
|
||||
{},
|
||||
],
|
||||
return_value=json.loads(load_fixture("status_data_success.json", "starlink")),
|
||||
)
|
||||
|
||||
DEVICE_FOUND_PATCHER = patch(
|
||||
|
|
73
tests/components/starlink/snapshots/test_diagnostics.ambr
Normal file
73
tests/components/starlink/snapshots/test_diagnostics.ambr
Normal file
|
@ -0,0 +1,73 @@
|
|||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'alert': dict({
|
||||
'alert_install_pending': False,
|
||||
'alert_is_heating': False,
|
||||
'alert_is_power_save_idle': False,
|
||||
'alert_mast_not_near_vertical': False,
|
||||
'alert_motors_stuck': False,
|
||||
'alert_moving_fast_while_not_aviation': False,
|
||||
'alert_moving_while_not_mobile': False,
|
||||
'alert_power_supply_thermal_throttle': False,
|
||||
'alert_roaming': False,
|
||||
'alert_slow_ethernet_speeds': False,
|
||||
'alert_thermal_shutdown': False,
|
||||
'alert_thermal_throttle': False,
|
||||
'alert_unexpected_location': False,
|
||||
}),
|
||||
'obstruction': dict({
|
||||
'raw_wedges_fraction_obstructed[]': list([
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
]),
|
||||
'valid_s': 803872.0,
|
||||
'wedges_fraction_obstructed[]': list([
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
]),
|
||||
}),
|
||||
'status': dict({
|
||||
'alerts': 0,
|
||||
'currently_obstructed': False,
|
||||
'direction_azimuth': -179.00344848632812,
|
||||
'direction_elevation': 68.67173767089844,
|
||||
'downlink_throughput_bps': 10108.2724609375,
|
||||
'fraction_obstructed': 0.0,
|
||||
'hardware_version': 'rev3_proto2',
|
||||
'id': '**REDACTED**',
|
||||
'is_snr_above_noise_floor': True,
|
||||
'obstruction_duration': None,
|
||||
'obstruction_interval': None,
|
||||
'pop_ping_drop_rate': 0.0,
|
||||
'pop_ping_latency_ms': 30.285715103149414,
|
||||
'seconds_obstructed': None,
|
||||
'seconds_to_first_nonempty_slot': 0.0,
|
||||
'snr': None,
|
||||
'software_version': '191e4dfa-d63a-46b1-a73b-9fa907733864.uterm.release',
|
||||
'state': 'CONNECTED',
|
||||
'uplink_throughput_bps': 11802.771484375,
|
||||
'uptime': 804138,
|
||||
}),
|
||||
})
|
||||
# ---
|
34
tests/components/starlink/test_diagnostics.py
Normal file
34
tests/components/starlink/test_diagnostics.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
"""Tests for Starlink diagnostics."""
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.starlink.const import DOMAIN
|
||||
from homeassistant.const import CONF_IP_ADDRESS
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .patchers import COORDINATOR_SUCCESS_PATCHER
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test generating diagnostics for a config entry."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_IP_ADDRESS: "1.2.3.4:0000"},
|
||||
)
|
||||
|
||||
with COORDINATOR_SUCCESS_PATCHER:
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
diag = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||
|
||||
assert diag == snapshot
|
Loading…
Add table
Reference in a new issue