Skip to content

Commit 2dd58db

Browse files
authored
Fix ZHA network formation (home-assistant#157769)
1 parent 4ef1779 commit 2dd58db

File tree

7 files changed

+9
-107
lines changed

7 files changed

+9
-107
lines changed

homeassistant/components/homeassistant_connect_zbt2/config_flow.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
NABU_CASA_FIRMWARE_RELEASES_URL,
4040
PID,
4141
PRODUCT,
42-
RADIO_TX_POWER_DBM_BY_COUNTRY,
43-
RADIO_TX_POWER_DBM_DEFAULT,
4442
SERIAL_NUMBER,
4543
VID,
4644
)
@@ -114,21 +112,6 @@ async def async_step_install_thread_firmware(
114112
next_step_id="finish_thread_installation",
115113
)
116114

117-
def _extra_zha_hardware_options(self) -> dict[str, Any]:
118-
"""Return extra ZHA hardware options."""
119-
country = self.hass.config.country
120-
121-
if country is None:
122-
tx_power = RADIO_TX_POWER_DBM_DEFAULT
123-
else:
124-
tx_power = RADIO_TX_POWER_DBM_BY_COUNTRY.get(
125-
country, RADIO_TX_POWER_DBM_DEFAULT
126-
)
127-
128-
return {
129-
"tx_power": tx_power,
130-
}
131-
132115

133116
class HomeAssistantConnectZBT2ConfigFlow(
134117
ZBT2FirmwareMixin,
Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Constants for the Home Assistant Connect ZBT-2 integration."""
22

3-
from homeassistant.generated.countries import COUNTRIES
4-
53
DOMAIN = "homeassistant_connect_zbt2"
64

75
NABU_CASA_FIRMWARE_RELEASES_URL = (
@@ -19,59 +17,3 @@
1917
DEVICE = "device"
2018

2119
HARDWARE_NAME = "Home Assistant Connect ZBT-2"
22-
23-
RADIO_TX_POWER_DBM_DEFAULT = 8
24-
RADIO_TX_POWER_DBM_BY_COUNTRY = {
25-
# EU Member States
26-
"AT": 10,
27-
"BE": 10,
28-
"BG": 10,
29-
"HR": 10,
30-
"CY": 10,
31-
"CZ": 10,
32-
"DK": 10,
33-
"EE": 10,
34-
"FI": 10,
35-
"FR": 10,
36-
"DE": 10,
37-
"GR": 10,
38-
"HU": 10,
39-
"IE": 10,
40-
"IT": 10,
41-
"LV": 10,
42-
"LT": 10,
43-
"LU": 10,
44-
"MT": 10,
45-
"NL": 10,
46-
"PL": 10,
47-
"PT": 10,
48-
"RO": 10,
49-
"SK": 10,
50-
"SI": 10,
51-
"ES": 10,
52-
"SE": 10,
53-
# EEA Members
54-
"IS": 10,
55-
"LI": 10,
56-
"NO": 10,
57-
# Standards harmonized with RED or ETSI
58-
"CH": 10,
59-
"GB": 10,
60-
"TR": 10,
61-
"AL": 10,
62-
"BA": 10,
63-
"GE": 10,
64-
"MD": 10,
65-
"ME": 10,
66-
"MK": 10,
67-
"RS": 10,
68-
"UA": 10,
69-
# Other CEPT nations
70-
"AD": 10,
71-
"AZ": 10,
72-
"MC": 10,
73-
"SM": 10,
74-
"VA": 10,
75-
}
76-
77-
assert set(RADIO_TX_POWER_DBM_BY_COUNTRY) <= COUNTRIES

homeassistant/components/homeassistant_hardware/firmware_config_flow.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,6 @@ async def async_step_pre_confirm_zigbee(
457457
# This step is necessary to prevent `user_input` from being passed through
458458
return await self.async_step_continue_zigbee()
459459

460-
def _extra_zha_hardware_options(self) -> dict[str, Any]:
461-
"""Return extra ZHA hardware options."""
462-
return {}
463-
464460
async def async_step_continue_zigbee(
465461
self, user_input: dict[str, Any] | None = None
466462
) -> ConfigFlowResult:
@@ -483,7 +479,6 @@ async def async_step_continue_zigbee(
483479
},
484480
"radio_type": "ezsp",
485481
"flow_strategy": self._zigbee_flow_strategy,
486-
**self._extra_zha_hardware_options(),
487482
},
488483
)
489484
return self._continue_zha_flow(result)

homeassistant/components/zha/config_flow.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import voluptuous as vol
1616
from zha.application.const import RadioType
1717
import zigpy.backups
18-
from zigpy.config import CONF_DEVICE, CONF_DEVICE_PATH, CONF_NWK_TX_POWER
18+
from zigpy.config import CONF_DEVICE, CONF_DEVICE_PATH
1919
from zigpy.exceptions import CannotWriteNetworkSettings, DestructiveWriteNetworkSettings
2020

2121
from homeassistant.components import onboarding, usb
@@ -196,7 +196,6 @@ def __init__(self) -> None:
196196
self._restore_backup_task: asyncio.Task[None] | None = None
197197
self._reset_old_radio_task: asyncio.Task[None] | None = None
198198
self._form_network_task: asyncio.Task[None] | None = None
199-
self._extra_network_config: dict[str, Any] = {}
200199

201200
# Progress flow steps cannot abort so we need to store the abort reason and then
202201
# re-raise it in a dedicated step
@@ -658,7 +657,7 @@ async def async_step_form_initial_network(
658657

659658
async def _async_form_new_network(self) -> None:
660659
"""Do the work of forming a new network."""
661-
await self._radio_mgr.async_form_network(config=self._extra_network_config)
660+
await self._radio_mgr.async_form_network()
662661
# Load the newly formed network settings to get the network info
663662
await self._radio_mgr.async_load_network_settings()
664663

@@ -1068,9 +1067,6 @@ async def async_step_hardware(
10681067
device_path = device_settings[CONF_DEVICE_PATH]
10691068
self._flow_strategy = discovery_data.get("flow_strategy")
10701069

1071-
if "tx_power" in discovery_data:
1072-
self._extra_network_config[CONF_NWK_TX_POWER] = discovery_data["tx_power"]
1073-
10741070
await self._set_unique_id_and_update_ignored_flow(
10751071
unique_id=f"{name}_{radio_type.name}_{device_path}",
10761072
device_path=device_path,

homeassistant/components/zha/radio_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ async def async_load_network_settings(
323323

324324
return backup
325325

326-
async def async_form_network(self, config: dict[str, Any] | None) -> None:
326+
async def async_form_network(self) -> None:
327327
"""Form a brand-new network."""
328328

329329
# When forming a new network, we delete the ZHA database to prevent old devices
@@ -332,7 +332,7 @@ async def async_form_network(self, config: dict[str, Any] | None) -> None:
332332
await self.hass.async_add_executor_job(os.remove, self.zigpy_database_path)
333333

334334
async with self.create_zigpy_app() as app:
335-
await app.form_network(config=config)
335+
await app.form_network()
336336

337337
async def async_reset_adapter(self) -> None:
338338
"""Reset the current adapter."""

tests/components/homeassistant_connect_zbt2/test_config_flow.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,8 @@ def setup_entry_fixture() -> Generator[AsyncMock]:
5050
yield mock_setup_entry
5151

5252

53-
@pytest.mark.parametrize(
54-
("country", "expected_tx_power"),
55-
[
56-
("US", 8),
57-
("NL", 10),
58-
("JP", 8),
59-
("DE", 10),
60-
],
61-
)
62-
async def test_config_flow_zigbee(
63-
hass: HomeAssistant,
64-
country: str,
65-
expected_tx_power: int,
66-
) -> None:
53+
async def test_config_flow_zigbee(hass: HomeAssistant) -> None:
6754
"""Test Zigbee config flow for Connect ZBT-2."""
68-
hass.config.country = country
69-
7055
fw_type = ApplicationType.EZSP
7156
fw_version = "7.4.4.0 build 0"
7257
model = "Home Assistant Connect ZBT-2"
@@ -160,7 +145,6 @@ async def mock_install_firmware_step(
160145
"flow_control": "hardware",
161146
},
162147
"radio_type": fw_type.value,
163-
"tx_power": expected_tx_power,
164148
}
165149

166150

@@ -400,7 +384,6 @@ async def test_options_flow(
400384
"flow_control": "hardware",
401385
},
402386
"radio_type": "ezsp",
403-
"tx_power": 8,
404387
}
405388

406389

tests/components/zha/test_config_flow.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pytest
2020
from serial.tools.list_ports_common import ListPortInfo
2121
from zha.application.const import RadioType
22+
from zigpy.application import ControllerApplication
2223
from zigpy.backups import BackupManager
2324
import zigpy.config
2425
from zigpy.config import CONF_DEVICE, CONF_DEVICE_PATH, SCHEMA_DEVICE
@@ -97,9 +98,11 @@ def mock_multipan_platform():
9798
@pytest.fixture(autouse=True)
9899
def mock_app() -> Generator[AsyncMock]:
99100
"""Mock zigpy app interface."""
100-
mock_app = AsyncMock()
101+
mock_app = create_autospec(ControllerApplication, instance=True)
101102
mock_app.backups = create_autospec(BackupManager, instance=True)
102103
mock_app.backups.backups = []
104+
105+
mock_app.state = MagicMock()
103106
mock_app.state.network_info.extended_pan_id = zigpy.types.EUI64.convert(
104107
"AABBCCDDEE000000"
105108
)

0 commit comments

Comments
 (0)