Fix Shelly diagnostics for devices without WebSocket Outbound support (#140501)

* Don't assume that `ws` is always in config

* Fix device
This commit is contained in:
Maciej Bieniek 2025-03-13 19:58:09 +01:00 committed by GitHub
parent 8ea2d40467
commit fa57d57215
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 6 deletions

View File

@ -79,12 +79,14 @@ async def async_get_config_entry_diagnostics(
device_settings = {
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)
)
if not (ws_config := rpc_coordinator.device.config.get("ws", {})):
device_settings["ws_outbound"] = "not supported"
if (ws_outbound_enabled := ws_config.get("enable")) is not None:
device_settings["ws_outbound_enabled"] = ws_outbound_enabled
if ws_outbound_enabled:
device_settings["ws_outbound_server_valid"] = bool(
ws_config["server"] == get_rpc_ws_url(hass)
)
device_status = {
k: v
for k, v in rpc_coordinator.device.status.items()

View File

@ -194,3 +194,21 @@ async def test_rpc_config_entry_diagnostics_ws_outbound(
result["device_settings"]["ws_outbound_server_valid"]
== ws_outbound_server_valid
)
async def test_rpc_config_entry_diagnostics_no_ws(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test config entry diagnostics for rpc device which doesn't support ws outbound."""
config = deepcopy(mock_rpc_device.config)
config.pop("ws")
monkeypatch.setattr(mock_rpc_device, "config", config)
entry = await init_integration(hass, 3)
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
assert result["device_settings"]["ws_outbound"] == "not supported"