Add WS outbound config to Shelly diagnostics (#124654)
Add WS Outbound config to diagnostics
This commit is contained in:
parent
7334fb0125
commit
b960ebeb8b
2 changed files with 36 additions and 1 deletions
|
@ -11,6 +11,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import format_mac
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
|
|
||||||
from .coordinator import ShellyConfigEntry
|
from .coordinator import ShellyConfigEntry
|
||||||
|
from .utils import get_rpc_ws_url
|
||||||
|
|
||||||
TO_REDACT = {CONF_USERNAME, CONF_PASSWORD}
|
TO_REDACT = {CONF_USERNAME, CONF_PASSWORD}
|
||||||
|
|
||||||
|
@ -73,6 +74,12 @@ async def async_get_config_entry_diagnostics(
|
||||||
device_settings = {
|
device_settings = {
|
||||||
k: v for k, v in rpc_coordinator.device.config.items() if k in ["cloud"]
|
k: v for k, v in rpc_coordinator.device.config.items() if k in ["cloud"]
|
||||||
}
|
}
|
||||||
|
ws_config = rpc_coordinator.device.config["ws"]
|
||||||
|
device_settings["ws_outbound_enabled"] = ws_config["enable"]
|
||||||
|
if ws_config["enable"]:
|
||||||
|
device_settings["ws_outbound_server_valid"] = bool(
|
||||||
|
ws_config["server"] == get_rpc_ws_url(hass)
|
||||||
|
)
|
||||||
device_status = {
|
device_status = {
|
||||||
k: v
|
k: v
|
||||||
for k, v in rpc_coordinator.device.status.items()
|
for k, v in rpc_coordinator.device.status.items()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""Tests for Shelly diagnostics platform."""
|
"""Tests for Shelly diagnostics platform."""
|
||||||
|
|
||||||
|
from copy import deepcopy
|
||||||
from unittest.mock import ANY, Mock, PropertyMock
|
from unittest.mock import ANY, Mock, PropertyMock
|
||||||
|
|
||||||
from aioshelly.ble.const import BLE_SCAN_RESULT_EVENT
|
from aioshelly.ble.const import BLE_SCAN_RESULT_EVENT
|
||||||
|
@ -151,7 +152,7 @@ async def test_rpc_config_entry_diagnostics(
|
||||||
"model": MODEL_25,
|
"model": MODEL_25,
|
||||||
"sw_version": "some fw string",
|
"sw_version": "some fw string",
|
||||||
},
|
},
|
||||||
"device_settings": {},
|
"device_settings": {"ws_outbound_enabled": False},
|
||||||
"device_status": {
|
"device_status": {
|
||||||
"sys": {
|
"sys": {
|
||||||
"available_updates": {
|
"available_updates": {
|
||||||
|
@ -164,3 +165,30 @@ async def test_rpc_config_entry_diagnostics(
|
||||||
},
|
},
|
||||||
"last_error": "DeviceConnectionError()",
|
"last_error": "DeviceConnectionError()",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("ws_outbound_server", "ws_outbound_server_valid"),
|
||||||
|
[("ws://10.10.10.10:8123/api/shelly/ws", True), ("wrong_url", False)],
|
||||||
|
)
|
||||||
|
async def test_rpc_config_entry_diagnostics_ws_outbound(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
mock_rpc_device: Mock,
|
||||||
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
|
ws_outbound_server: str,
|
||||||
|
ws_outbound_server_valid: bool,
|
||||||
|
) -> None:
|
||||||
|
"""Test config entry diagnostics for rpc device with websocket outbound."""
|
||||||
|
config = deepcopy(mock_rpc_device.config)
|
||||||
|
config["ws"] = {"enable": True, "server": ws_outbound_server}
|
||||||
|
monkeypatch.setattr(mock_rpc_device, "config", config)
|
||||||
|
|
||||||
|
entry = await init_integration(hass, 2, sleep_period=60)
|
||||||
|
|
||||||
|
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
result["device_settings"]["ws_outbound_server_valid"]
|
||||||
|
== ws_outbound_server_valid
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue