Skip to content

Commit b7652c7

Browse files
authored
Add options flow to enable multiprotocol support on sky connect (#82525)
1 parent 16fc297 commit b7652c7

File tree

23 files changed

+962
-95
lines changed

23 files changed

+962
-95
lines changed

homeassistant/components/homeassistant_hardware/silabs_multiprotocol_addon.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ async def _async_zha_physical_discovery(self) -> dict[str, Any]:
9898
being migrated.
9999
"""
100100

101+
@abstractmethod
102+
def _hardware_name(self) -> str:
103+
"""Return the name of the hardware."""
104+
101105
@abstractmethod
102106
def _zha_name(self) -> str:
103107
"""Return the ZHA name."""
@@ -254,6 +258,7 @@ async def async_step_addon_not_installed(
254258
data_schema=vol.Schema(
255259
{vol.Required(CONF_ENABLE_MULTI_PAN, default=False): bool}
256260
),
261+
description_placeholders={"hardware_name": self._hardware_name()},
257262
)
258263
if not user_input[CONF_ENABLE_MULTI_PAN]:
259264
return self.async_create_entry(title="", data={})
@@ -285,10 +290,8 @@ async def async_step_configure_addon(
285290
"name": self._zha_name(),
286291
"port": {
287292
"path": get_zigbee_socket(self.hass, addon_info),
288-
"baudrate": 115200,
289-
"flow_control": "hardware",
290293
},
291-
"radio_type": "efr32",
294+
"radio_type": "ezsp",
292295
},
293296
"old_discovery_info": await self._async_zha_physical_discovery(),
294297
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"silabs_multiprotocol_hardware": {
3+
"options": {
4+
"step": {
5+
"addon_not_installed": {
6+
"title": "Enable multiprotocol support on the IEEE 802.15.4 radio",
7+
"description": "When multiprotocol support is enabled, the {hardware_name}'s IEEE 802.15.4 radio can be used for both Zigbee and Thread (used by Matter) at the same time. If the radio is already used by the ZHA Zigbee integration, ZHA will be reconfigured to use the multiprotocol firmware.\n\nNote: This is an experimental feature.",
8+
"data": {
9+
"enable_multi_pan": "Enable multiprotocol support"
10+
}
11+
},
12+
"addon_installed_other_device": {
13+
"title": "Multiprotocol support is already enabled for another device"
14+
},
15+
"install_addon": {
16+
"title": "The Silicon Labs Multiprotocol add-on installation has started"
17+
},
18+
"show_revert_guide": {
19+
"title": "Multiprotocol support is enabled for this device",
20+
"description": "If you want to change to Zigbee only firmware, please complete the following manual steps:\n\n * Remove the Silicon Labs Multiprotocol addon\n\n * Flash the Zigbee only firmware, follow the guide at https://github.com/NabuCasa/silabs-firmware/wiki/Flash-Silicon-Labs-radio-firmware-manually.\n\n * Reconfigure ZHA to migrate settings to the reflashed radio"
21+
},
22+
"start_addon": {
23+
"title": "The Silicon Labs Multiprotocol add-on is starting."
24+
}
25+
},
26+
"error": {
27+
"unknown": "[%key:common::config_flow::error::unknown%]"
28+
},
29+
"abort": {
30+
"addon_info_failed": "Failed to get Silicon Labs Multiprotocol add-on info.",
31+
"addon_install_failed": "Failed to install the Silicon Labs Multiprotocol add-on.",
32+
"addon_set_config_failed": "Failed to set Silicon Labs Multiprotocol configuration.",
33+
"addon_start_failed": "Failed to start the Silicon Labs Multiprotocol add-on.",
34+
"not_hassio": "The hardware options can only be configured on HassOS installations.",
35+
"zha_migration_failed": "The ZHA migration did not succeed."
36+
},
37+
"progress": {
38+
"install_addon": "Please wait while the Silicon Labs Multiprotocol add-on installation finishes. This can take several minutes.",
39+
"start_addon": "Please wait while the Silicon Labs Multiprotocol add-on start completes. This may take some seconds."
40+
}
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"silabs_multiprotocol_hardware": {
3+
"options": {
4+
"abort": {
5+
"addon_info_failed": "Failed to get Silicon Labs Multiprotocol add-on info.",
6+
"addon_install_failed": "Failed to install the Silicon Labs Multiprotocol add-on.",
7+
"addon_set_config_failed": "Failed to set Silicon Labs Multiprotocol configuration.",
8+
"addon_start_failed": "Failed to start the Silicon Labs Multiprotocol add-on.",
9+
"not_hassio": "The hardware options can only be configured on HassOS installations.",
10+
"zha_migration_failed": "The ZHA migration did not succeed."
11+
},
12+
"error": {
13+
"unknown": "Unexpected error"
14+
},
15+
"progress": {
16+
"install_addon": "Please wait while the Silicon Labs Multiprotocol add-on installation finishes. This can take several minutes.",
17+
"start_addon": "Please wait while the Silicon Labs Multiprotocol add-on start completes. This may take some seconds."
18+
},
19+
"step": {
20+
"addon_installed_other_device": {
21+
"title": "Multiprotocol support is already enabled for another device"
22+
},
23+
"addon_not_installed": {
24+
"data": {
25+
"enable_multi_pan": "Enable multiprotocol support"
26+
},
27+
"description": "When multiprotocol support is enabled, the {hardware_name}'s IEEE 802.15.4 radio can be used for both Zigbee and Thread (used by Matter) at the same time. If the radio is already used by the ZHA Zigbee integration, ZHA will be reconfigured to use the multiprotocol firmware.\n\nNote: This is an experimental feature.",
28+
"title": "Enable multiprotocol support on the IEEE 802.15.4 radio"
29+
},
30+
"install_addon": {
31+
"title": "The Silicon Labs Multiprotocol add-on installation has started"
32+
},
33+
"show_revert_guide": {
34+
"description": "If you want to change to Zigbee only firmware, please complete the following manual steps:\n\n * Remove the Silicon Labs Multiprotocol addon\n\n * Flash the Zigbee only firmware, follow the guide at https://github.com/NabuCasa/silabs-firmware/wiki/Flash-Silicon-Labs-radio-firmware-manually.\n\n * Reconfigure ZHA to migrate settings to the reflashed radio",
35+
"title": "Multiprotocol support is enabled for this device"
36+
},
37+
"start_addon": {
38+
"title": "The Silicon Labs Multiprotocol add-on is starting."
39+
}
40+
}
41+
}
42+
}
43+
}

homeassistant/components/homeassistant_sky_connect/__init__.py

+70-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,63 @@
11
"""The Home Assistant Sky Connect integration."""
22
from __future__ import annotations
33

4+
import logging
5+
46
from homeassistant.components import usb
7+
from homeassistant.components.hassio import (
8+
AddonError,
9+
AddonInfo,
10+
AddonManager,
11+
AddonState,
12+
is_hassio,
13+
)
14+
from homeassistant.components.homeassistant_hardware.silabs_multiprotocol_addon import (
15+
get_addon_manager,
16+
get_zigbee_socket,
17+
)
518
from homeassistant.config_entries import ConfigEntry
619
from homeassistant.core import HomeAssistant
720
from homeassistant.exceptions import ConfigEntryNotReady
821

922
from .const import DOMAIN
23+
from .util import get_usb_service_info
24+
25+
_LOGGER = logging.getLogger(__name__)
26+
27+
28+
async def _multi_pan_addon_info(hass, entry: ConfigEntry) -> AddonInfo | None:
29+
"""Return AddonInfo if the multi-PAN addon is enabled for our SkyConnect."""
30+
if not is_hassio(hass):
31+
return None
32+
33+
addon_manager: AddonManager = get_addon_manager(hass)
34+
try:
35+
addon_info: AddonInfo = await addon_manager.async_get_addon_info()
36+
except AddonError as err:
37+
_LOGGER.error(err)
38+
raise ConfigEntryNotReady from err
39+
40+
# Start the addon if it's not started
41+
if addon_info.state == AddonState.NOT_RUNNING:
42+
await addon_manager.async_start_addon()
43+
44+
if addon_info.state not in (AddonState.NOT_INSTALLED, AddonState.RUNNING):
45+
_LOGGER.debug(
46+
"Multi pan addon in state %s, delaying yellow config entry setup",
47+
addon_info.state,
48+
)
49+
raise ConfigEntryNotReady
50+
51+
if addon_info.state == AddonState.NOT_INSTALLED:
52+
return None
53+
54+
usb_dev = entry.data["device"]
55+
dev_path = await hass.async_add_executor_job(usb.get_serial_by_id, usb_dev)
56+
57+
if addon_info.options["device"] != dev_path:
58+
return None
59+
60+
return addon_info
1061

1162

1263
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@@ -24,19 +75,28 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
2475
# The USB dongle is not plugged in
2576
raise ConfigEntryNotReady
2677

27-
usb_info = usb.UsbServiceInfo(
28-
device=entry.data["device"],
29-
vid=entry.data["vid"],
30-
pid=entry.data["pid"],
31-
serial_number=entry.data["serial_number"],
32-
manufacturer=entry.data["manufacturer"],
33-
description=entry.data["description"],
34-
)
78+
addon_info = await _multi_pan_addon_info(hass, entry)
79+
80+
if not addon_info:
81+
usb_info = get_usb_service_info(entry)
82+
await hass.config_entries.flow.async_init(
83+
"zha",
84+
context={"source": "usb"},
85+
data=usb_info,
86+
)
87+
return True
3588

89+
hw_discovery_data = {
90+
"name": "Sky Connect Multi-PAN",
91+
"port": {
92+
"path": get_zigbee_socket(hass, addon_info),
93+
},
94+
"radio_type": "ezsp",
95+
}
3696
await hass.config_entries.flow.async_init(
3797
"zha",
38-
context={"source": "usb"},
39-
data=usb_info,
98+
context={"source": "hardware"},
99+
data=hw_discovery_data,
40100
)
41101

42102
return True

homeassistant/components/homeassistant_sky_connect/config_flow.py

+46-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
"""Config flow for the Home Assistant Sky Connect integration."""
22
from __future__ import annotations
33

4+
from typing import Any
5+
46
from homeassistant.components import usb
5-
from homeassistant.config_entries import ConfigFlow
7+
from homeassistant.components.homeassistant_hardware import silabs_multiprotocol_addon
8+
from homeassistant.config_entries import ConfigEntry, ConfigFlow
9+
from homeassistant.core import callback
610
from homeassistant.data_entry_flow import FlowResult
711

812
from .const import DOMAIN
13+
from .util import get_usb_service_info
914

1015

1116
class HomeAssistantSkyConnectConfigFlow(ConfigFlow, domain=DOMAIN):
1217
"""Handle a config flow for Home Assistant Sky Connect."""
1318

1419
VERSION = 1
1520

21+
@staticmethod
22+
@callback
23+
def async_get_options_flow(
24+
config_entry: ConfigEntry,
25+
) -> HomeAssistantSkyConnectOptionsFlow:
26+
"""Return the options flow."""
27+
return HomeAssistantSkyConnectOptionsFlow(config_entry)
28+
1629
async def async_step_usb(self, discovery_info: usb.UsbServiceInfo) -> FlowResult:
1730
"""Handle usb discovery."""
1831
device = discovery_info.device
@@ -35,3 +48,35 @@ async def async_step_usb(self, discovery_info: usb.UsbServiceInfo) -> FlowResult
3548
"description": description,
3649
},
3750
)
51+
52+
53+
class HomeAssistantSkyConnectOptionsFlow(silabs_multiprotocol_addon.OptionsFlowHandler):
54+
"""Handle an option flow for Home Assistant Sky Connect."""
55+
56+
async def _async_serial_port_settings(
57+
self,
58+
) -> silabs_multiprotocol_addon.SerialPortSettings:
59+
"""Return the radio serial port settings."""
60+
usb_dev = self.config_entry.data["device"]
61+
dev_path = await self.hass.async_add_executor_job(usb.get_serial_by_id, usb_dev)
62+
return silabs_multiprotocol_addon.SerialPortSettings(
63+
device=dev_path,
64+
baudrate="115200",
65+
flow_control=True,
66+
)
67+
68+
async def _async_zha_physical_discovery(self) -> dict[str, Any]:
69+
"""Return ZHA discovery data when multiprotocol FW is not used.
70+
71+
Passed to ZHA do determine if the ZHA config entry is connected to the radio
72+
being migrated.
73+
"""
74+
return {"usb": get_usb_service_info(self.config_entry)}
75+
76+
def _zha_name(self) -> str:
77+
"""Return the ZHA name."""
78+
return "Sky Connect Multi-PAN"
79+
80+
def _hardware_name(self) -> str:
81+
"""Return the name of the hardware."""
82+
return "Home Assistant Sky Connect"

homeassistant/components/homeassistant_sky_connect/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Home Assistant Sky Connect",
44
"config_flow": true,
55
"documentation": "https://www.home-assistant.io/integrations/homeassistant_sky_connect",
6-
"dependencies": ["hardware", "usb"],
6+
"dependencies": ["hardware", "usb", "homeassistant_hardware"],
77
"codeowners": ["@home-assistant/core"],
88
"integration_type": "hardware",
99
"usb": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"options": {
3+
"step": {
4+
"addon_not_installed": {
5+
"title": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::addon_not_installed::title%]",
6+
"description": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::addon_not_installed::description%]",
7+
"data": {
8+
"enable_multi_pan": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::addon_not_installed::data::enable_multi_pan%]"
9+
}
10+
},
11+
"addon_installed_other_device": {
12+
"title": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::addon_installed_other_device::title%]"
13+
},
14+
"install_addon": {
15+
"title": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::install_addon::title%]"
16+
},
17+
"show_revert_guide": {
18+
"title": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::show_revert_guide::title%]",
19+
"description": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::show_revert_guide::description%]"
20+
},
21+
"start_addon": {
22+
"title": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::start_addon::title%]"
23+
}
24+
},
25+
"error": {
26+
"unknown": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::error::unknown%]"
27+
},
28+
"abort": {
29+
"addon_info_failed": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::addon_info_failed%]",
30+
"addon_install_failed": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::addon_install_failed%]",
31+
"addon_set_config_failed": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::addon_set_config_failed%]",
32+
"addon_start_failed": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::addon_start_failed%]",
33+
"not_hassio": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::not_hassio%]",
34+
"zha_migration_failed": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::zha_migration_failed%]"
35+
},
36+
"progress": {
37+
"install_addon": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::progress::install_addon%]",
38+
"start_addon": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::progress::start_addon%]"
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"options": {
3+
"abort": {
4+
"addon_info_failed": "Failed to get Silicon Labs Multiprotocol add-on info.",
5+
"addon_install_failed": "Failed to install the Silicon Labs Multiprotocol add-on.",
6+
"addon_set_config_failed": "Failed to set Silicon Labs Multiprotocol configuration.",
7+
"addon_start_failed": "Failed to start the Silicon Labs Multiprotocol add-on.",
8+
"not_hassio": "The hardware options can only be configured on HassOS installations.",
9+
"zha_migration_failed": "The ZHA migration did not succeed."
10+
},
11+
"error": {
12+
"unknown": "Unexpected error"
13+
},
14+
"progress": {
15+
"install_addon": "Please wait while the Silicon Labs Multiprotocol add-on installation finishes. This can take several minutes.",
16+
"start_addon": "Please wait while the Silicon Labs Multiprotocol add-on start completes. This may take some seconds."
17+
},
18+
"step": {
19+
"addon_installed_other_device": {
20+
"title": "Multiprotocol support is already enabled for another device"
21+
},
22+
"addon_not_installed": {
23+
"data": {
24+
"enable_multi_pan": "Enable multiprotocol support"
25+
},
26+
"description": "When multiprotocol support is enabled, the {hardware_name}'s IEEE 802.15.4 radio can be used for both Zigbee and Thread (used by Matter) at the same time. If the radio is already used by the ZHA Zigbee integration, ZHA will be reconfigured to use the multiprotocol firmware.\n\nNote: This is an experimental feature.",
27+
"title": "Enable multiprotocol support on the IEEE 802.15.4 radio"
28+
},
29+
"install_addon": {
30+
"title": "The Silicon Labs Multiprotocol add-on installation has started"
31+
},
32+
"show_revert_guide": {
33+
"description": "If you want to change to Zigbee only firmware, please complete the following manual steps:\n\n * Remove the Silicon Labs Multiprotocol addon\n\n * Flash the Zigbee only firmware, follow the guide at https://github.com/NabuCasa/silabs-firmware/wiki/Flash-Silicon-Labs-radio-firmware-manually.\n\n * Reconfigure ZHA to migrate settings to the reflashed radio",
34+
"title": "Multiprotocol support is enabled for this device"
35+
},
36+
"start_addon": {
37+
"title": "The Silicon Labs Multiprotocol add-on is starting."
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)