Make OTBR use same channel as ZHA (#88546)

This commit is contained in:
Erik Montnemery 2023-03-28 12:34:25 +02:00 committed by GitHub
parent ae41547b73
commit 3c3860c923
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 171 additions and 34 deletions

View file

@ -11,6 +11,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from .const import DEFAULT_CHANNEL, DOMAIN
from .util import get_allowed_channel
if TYPE_CHECKING:
from . import OTBRData
@ -72,11 +73,8 @@ async def websocket_create_network(
connection.send_error(msg["id"], "not_loaded", "No OTBR API loaded")
return
# We currently have no way to know which channel zha is using, assume it's
# the default
zha_channel = DEFAULT_CHANNEL
data: OTBRData = hass.data[DOMAIN]
channel = await get_allowed_channel(hass, data.url) or DEFAULT_CHANNEL
try:
await data.set_enabled(False)
@ -87,7 +85,7 @@ async def websocket_create_network(
try:
await data.create_active_dataset(
python_otbr_api.OperationalDataSet(
channel=zha_channel, network_name="home-assistant"
channel=channel, network_name="home-assistant"
)
)
except HomeAssistantError as exc:
@ -139,21 +137,18 @@ async def websocket_set_network(
if channel_str := dataset.get(tlv_parser.MeshcopTLVType.CHANNEL):
thread_dataset_channel = int(channel_str, base=16)
# We currently have no way to know which channel zha is using, assume it's
# the default
zha_channel = DEFAULT_CHANNEL
data: OTBRData = hass.data[DOMAIN]
allowed_channel = await get_allowed_channel(hass, data.url)
if thread_dataset_channel != zha_channel:
if allowed_channel and thread_dataset_channel != allowed_channel:
connection.send_error(
msg["id"],
"channel_conflict",
f"Can't connect to network on channel {thread_dataset_channel}, ZHA is "
f"using channel {zha_channel}",
f"using channel {allowed_channel}",
)
return
data: OTBRData = hass.data[DOMAIN]
try:
await data.set_enabled(False)
except HomeAssistantError as exc: