1 """ZHA repairs for common environmental and device problems."""
3 from __future__
import annotations
8 from universal_silabs_flasher.const
import ApplicationType
9 from universal_silabs_flasher.flasher
import Flasher
12 hardware
as skyconnect_hardware,
15 RADIO_DEVICE
as YELLOW_RADIO_DEVICE,
16 hardware
as yellow_hardware,
22 from ..const
import DOMAIN
24 _LOGGER = logging.getLogger(__name__)
28 """The device is already running EZSP firmware."""
32 """Detected Zigbee hardware type."""
34 SKYCONNECT =
"skyconnect"
39 DISABLE_MULTIPAN_URL = {
40 HardwareType.YELLOW: (
41 "https://yellow.home-assistant.io/guides/disable-multiprotocol/#flash-the-silicon-labs-radio-firmware"
43 HardwareType.SKYCONNECT: (
44 "https://skyconnect.home-assistant.io/procedures/disable-multiprotocol/#step-flash-the-silicon-labs-radio-firmware"
46 HardwareType.OTHER:
None,
49 ISSUE_WRONG_SILABS_FIRMWARE_INSTALLED =
"wrong_silabs_firmware_installed"
53 """Identify the radio hardware with the given serial port."""
55 yellow_hardware.async_info(hass)
56 except HomeAssistantError:
59 if device == YELLOW_RADIO_DEVICE:
60 return HardwareType.YELLOW
63 info = skyconnect_hardware.async_info(hass)
64 except HomeAssistantError:
67 for hardware_info
in info:
68 for entry_id
in hardware_info.config_entries
or []:
69 entry = hass.config_entries.async_get_entry(entry_id)
71 if entry
is not None and entry.data[
"device"] == device:
72 return HardwareType.SKYCONNECT
74 return HardwareType.OTHER
78 device: str, *, probe_methods: ApplicationType |
None =
None
79 ) -> ApplicationType |
None:
80 """Probe the running firmware on a Silabs device."""
83 **({
"probe_methods": probe_methods}
if probe_methods
else {}),
87 await flasher.probe_app_type()
89 _LOGGER.debug(
"Failed to probe application type", exc_info=
True)
91 return flasher.app_type
95 """Create a repair issue if the wrong type of SiLabs firmware is detected."""
97 if device.startswith(
"socket://"):
106 if app_type == ApplicationType.EZSP:
109 raise AlreadyRunningEZSP
112 ir.async_create_issue(
115 issue_id=ISSUE_WRONG_SILABS_FIRMWARE_INSTALLED,
118 learn_more_url=DISABLE_MULTIPAN_URL[hardware_type],
119 severity=ir.IssueSeverity.ERROR,
121 ISSUE_WRONG_SILABS_FIRMWARE_INSTALLED
122 + (
"_nabucasa" if hardware_type != HardwareType.OTHER
else "_other")
124 translation_placeholders={
"firmware_type": app_type.name},
bool warn_on_wrong_silabs_firmware(HomeAssistant hass, str device)
HardwareType _detect_radio_hardware(HomeAssistant hass, str device)
ApplicationType|None probe_silabs_firmware_type(str device, *ApplicationType|None probe_methods=None)