1 """Diagnostics support for Shelly."""
3 from __future__
import annotations
13 from .coordinator
import ShellyConfigEntry
14 from .utils
import get_rpc_ws_url
16 TO_REDACT = {CONF_USERNAME, CONF_PASSWORD}
20 hass: HomeAssistant, entry: ShellyConfigEntry
22 """Return diagnostics for a config entry."""
23 shelly_entry_data = entry.runtime_data
25 device_settings: str | dict =
"not initialized"
26 device_status: str | dict =
"not initialized"
27 bluetooth: str | dict =
"not initialized"
28 last_error: str =
"not initialized"
30 if shelly_entry_data.block:
31 block_coordinator = shelly_entry_data.block
32 assert block_coordinator
34 "name": block_coordinator.name,
35 "model": block_coordinator.model,
36 "sw_version": block_coordinator.sw_version,
38 if block_coordinator.device.initialized:
41 for k, v
in block_coordinator.device.settings.items()
42 if k
in [
"cloud",
"coiot"]
46 for k, v
in block_coordinator.device.status.items()
62 if block_coordinator.device.last_error:
63 last_error = repr(block_coordinator.device.last_error)
66 rpc_coordinator = shelly_entry_data.rpc
67 assert rpc_coordinator
69 "name": rpc_coordinator.name,
70 "model": rpc_coordinator.model,
71 "sw_version": rpc_coordinator.sw_version,
73 if rpc_coordinator.device.initialized:
75 k: v
for k, v
in rpc_coordinator.device.config.items()
if k
in [
"cloud"]
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(
85 for k, v
in rpc_coordinator.device.status.items()
86 if k
in [
"sys",
"wifi"]
89 source =
format_mac(rpc_coordinator.mac).upper()
92 "scanner": await scanner.async_diagnostics(),
95 if rpc_coordinator.device.last_error:
96 last_error = repr(rpc_coordinator.device.last_error)
98 if isinstance(device_status, dict):
103 "device_info": device_info,
104 "device_settings": device_settings,
105 "device_status": device_status,
106 "last_error": last_error,
107 "bluetooth": bluetooth,
BaseHaScanner|None async_scanner_by_source(HomeAssistant hass, str source)
dict async_redact_data(Mapping data, Iterable[Any] to_redact)
dict[str, Any] async_get_config_entry_diagnostics(HomeAssistant hass, ShellyConfigEntry entry)
str|None get_rpc_ws_url(HomeAssistant hass)