Skip to content

Commit 54ad44a

Browse files
bieniufrenck
authored andcommitted
Fix Shelly diagnostics for devices without WebSocket Outbound support (#140501)
* Don't assume that `ws` is always in config * Fix device
1 parent fed4015 commit 54ad44a

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

homeassistant/components/shelly/diagnostics.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ async def async_get_config_entry_diagnostics(
7474
device_settings = {
7575
k: v for k, v in rpc_coordinator.device.config.items() if k in ["cloud"]
7676
}
77-
ws_config = rpc_coordinator.device.config["ws"]
78-
device_settings["ws_outbound_enabled"] = ws_config["enable"]
79-
if ws_config["enable"]:
80-
device_settings["ws_outbound_server_valid"] = bool(
81-
ws_config["server"] == get_rpc_ws_url(hass)
82-
)
77+
if not (ws_config := rpc_coordinator.device.config.get("ws", {})):
78+
device_settings["ws_outbound"] = "not supported"
79+
if (ws_outbound_enabled := ws_config.get("enable")) is not None:
80+
device_settings["ws_outbound_enabled"] = ws_outbound_enabled
81+
if ws_outbound_enabled:
82+
device_settings["ws_outbound_server_valid"] = bool(
83+
ws_config["server"] == get_rpc_ws_url(hass)
84+
)
8385
device_status = {
8486
k: v
8587
for k, v in rpc_coordinator.device.status.items()

tests/components/shelly/test_diagnostics.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,21 @@ async def test_rpc_config_entry_diagnostics_ws_outbound(
194194
result["device_settings"]["ws_outbound_server_valid"]
195195
== ws_outbound_server_valid
196196
)
197+
198+
199+
async def test_rpc_config_entry_diagnostics_no_ws(
200+
hass: HomeAssistant,
201+
hass_client: ClientSessionGenerator,
202+
mock_rpc_device: Mock,
203+
monkeypatch: pytest.MonkeyPatch,
204+
) -> None:
205+
"""Test config entry diagnostics for rpc device which doesn't support ws outbound."""
206+
config = deepcopy(mock_rpc_device.config)
207+
config.pop("ws")
208+
monkeypatch.setattr(mock_rpc_device, "config", config)
209+
210+
entry = await init_integration(hass, 3)
211+
212+
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
213+
214+
assert result["device_settings"]["ws_outbound"] == "not supported"

0 commit comments

Comments
 (0)