Adapt otbr to upstream openthread REST API changes (#93544)

* Adapt otbr to upstream openthread REST API changes

* Bump python-otbr-api to 2.0.0
This commit is contained in:
Erik Montnemery 2023-05-30 10:11:21 +02:00 committed by GitHub
parent 49ae298c55
commit 901624ad6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 23 additions and 25 deletions

View File

@ -50,7 +50,7 @@ class OTBRConfigFlow(ConfigFlow, domain=DOMAIN):
"not importing TLV with channel %s", thread_dataset_channel "not importing TLV with channel %s", thread_dataset_channel
) )
await api.create_active_dataset( await api.create_active_dataset(
python_otbr_api.OperationalDataSet( python_otbr_api.ActiveDataSet(
channel=allowed_channel if allowed_channel else DEFAULT_CHANNEL, channel=allowed_channel if allowed_channel else DEFAULT_CHANNEL,
network_name="home-assistant", network_name="home-assistant",
) )

View File

@ -8,5 +8,5 @@
"documentation": "https://www.home-assistant.io/integrations/otbr", "documentation": "https://www.home-assistant.io/integrations/otbr",
"integration_type": "service", "integration_type": "service",
"iot_class": "local_polling", "iot_class": "local_polling",
"requirements": ["python-otbr-api==1.0.9"] "requirements": ["python-otbr-api==2.0.0"]
} }

View File

@ -79,7 +79,7 @@ class OTBRData:
@_handle_otbr_error @_handle_otbr_error
async def create_active_dataset( async def create_active_dataset(
self, dataset: python_otbr_api.OperationalDataSet self, dataset: python_otbr_api.ActiveDataSet
) -> None: ) -> None:
"""Create an active operational dataset.""" """Create an active operational dataset."""
return await self.api.create_active_dataset(dataset) return await self.api.create_active_dataset(dataset)

View File

@ -80,7 +80,7 @@ async def websocket_create_network(
try: try:
await data.create_active_dataset( await data.create_active_dataset(
python_otbr_api.OperationalDataSet( python_otbr_api.ActiveDataSet(
channel=channel, network_name="home-assistant" channel=channel, network_name="home-assistant"
) )
) )

View File

@ -7,6 +7,6 @@
"documentation": "https://www.home-assistant.io/integrations/thread", "documentation": "https://www.home-assistant.io/integrations/thread",
"integration_type": "service", "integration_type": "service",
"iot_class": "local_polling", "iot_class": "local_polling",
"requirements": ["python-otbr-api==1.0.9", "pyroute2==0.7.5"], "requirements": ["python-otbr-api==2.0.0", "pyroute2==0.7.5"],
"zeroconf": ["_meshcop._udp.local."] "zeroconf": ["_meshcop._udp.local."]
} }

View File

@ -2109,7 +2109,7 @@ python-opensky==0.0.7
# homeassistant.components.otbr # homeassistant.components.otbr
# homeassistant.components.thread # homeassistant.components.thread
python-otbr-api==1.0.9 python-otbr-api==2.0.0
# homeassistant.components.picnic # homeassistant.components.picnic
python-picnic-api==1.1.0 python-picnic-api==1.1.0

View File

@ -1532,7 +1532,7 @@ python-nest==4.2.0
# homeassistant.components.otbr # homeassistant.components.otbr
# homeassistant.components.thread # homeassistant.components.thread
python-otbr-api==1.0.9 python-otbr-api==2.0.0
# homeassistant.components.picnic # homeassistant.components.picnic
python-picnic-api==1.1.0 python-picnic-api==1.1.0

View File

@ -72,8 +72,8 @@ async def test_user_flow_router_not_setup(
""" """
url = "http://custom_url:1234" url = "http://custom_url:1234"
aioclient_mock.get(f"{url}/node/dataset/active", status=HTTPStatus.NO_CONTENT) aioclient_mock.get(f"{url}/node/dataset/active", status=HTTPStatus.NO_CONTENT)
aioclient_mock.post(f"{url}/node/dataset/active", status=HTTPStatus.ACCEPTED) aioclient_mock.put(f"{url}/node/dataset/active", status=HTTPStatus.CREATED)
aioclient_mock.post(f"{url}/node/state", status=HTTPStatus.OK) aioclient_mock.put(f"{url}/node/state", status=HTTPStatus.OK)
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
otbr.DOMAIN, context={"source": "user"} otbr.DOMAIN, context={"source": "user"}
@ -96,14 +96,14 @@ async def test_user_flow_router_not_setup(
) )
# Check we create a dataset and enable the router # Check we create a dataset and enable the router
assert aioclient_mock.mock_calls[-2][0] == "POST" assert aioclient_mock.mock_calls[-2][0] == "PUT"
assert aioclient_mock.mock_calls[-2][1].path == "/node/dataset/active" assert aioclient_mock.mock_calls[-2][1].path == "/node/dataset/active"
assert aioclient_mock.mock_calls[-2][2] == { assert aioclient_mock.mock_calls[-2][2] == {
"Channel": 15, "Channel": 15,
"NetworkName": "home-assistant", "NetworkName": "home-assistant",
} }
assert aioclient_mock.mock_calls[-1][0] == "POST" assert aioclient_mock.mock_calls[-1][0] == "PUT"
assert aioclient_mock.mock_calls[-1][1].path == "/node/state" assert aioclient_mock.mock_calls[-1][1].path == "/node/state"
assert aioclient_mock.mock_calls[-1][2] == "enable" assert aioclient_mock.mock_calls[-1][2] == "enable"
@ -216,8 +216,8 @@ async def test_hassio_discovery_flow_router_not_setup(
""" """
url = "http://core-silabs-multiprotocol:8081" url = "http://core-silabs-multiprotocol:8081"
aioclient_mock.get(f"{url}/node/dataset/active", status=HTTPStatus.NO_CONTENT) aioclient_mock.get(f"{url}/node/dataset/active", status=HTTPStatus.NO_CONTENT)
aioclient_mock.post(f"{url}/node/dataset/active", status=HTTPStatus.ACCEPTED) aioclient_mock.put(f"{url}/node/dataset/active", status=HTTPStatus.CREATED)
aioclient_mock.post(f"{url}/node/state", status=HTTPStatus.OK) aioclient_mock.put(f"{url}/node/state", status=HTTPStatus.OK)
with patch( with patch(
"homeassistant.components.otbr.config_flow.async_get_preferred_dataset", "homeassistant.components.otbr.config_flow.async_get_preferred_dataset",
@ -231,14 +231,14 @@ async def test_hassio_discovery_flow_router_not_setup(
) )
# Check we create a dataset and enable the router # Check we create a dataset and enable the router
assert aioclient_mock.mock_calls[-2][0] == "POST" assert aioclient_mock.mock_calls[-2][0] == "PUT"
assert aioclient_mock.mock_calls[-2][1].path == "/node/dataset/active" assert aioclient_mock.mock_calls[-2][1].path == "/node/dataset/active"
assert aioclient_mock.mock_calls[-2][2] == { assert aioclient_mock.mock_calls[-2][2] == {
"Channel": 15, "Channel": 15,
"NetworkName": "home-assistant", "NetworkName": "home-assistant",
} }
assert aioclient_mock.mock_calls[-1][0] == "POST" assert aioclient_mock.mock_calls[-1][0] == "PUT"
assert aioclient_mock.mock_calls[-1][1].path == "/node/state" assert aioclient_mock.mock_calls[-1][1].path == "/node/state"
assert aioclient_mock.mock_calls[-1][2] == "enable" assert aioclient_mock.mock_calls[-1][2] == "enable"
@ -268,8 +268,8 @@ async def test_hassio_discovery_flow_router_not_setup_has_preferred(
""" """
url = "http://core-silabs-multiprotocol:8081" url = "http://core-silabs-multiprotocol:8081"
aioclient_mock.get(f"{url}/node/dataset/active", status=HTTPStatus.NO_CONTENT) aioclient_mock.get(f"{url}/node/dataset/active", status=HTTPStatus.NO_CONTENT)
aioclient_mock.put(f"{url}/node/dataset/active", status=HTTPStatus.ACCEPTED) aioclient_mock.put(f"{url}/node/dataset/active", status=HTTPStatus.CREATED)
aioclient_mock.post(f"{url}/node/state", status=HTTPStatus.OK) aioclient_mock.put(f"{url}/node/state", status=HTTPStatus.OK)
with patch( with patch(
"homeassistant.components.otbr.config_flow.async_get_preferred_dataset", "homeassistant.components.otbr.config_flow.async_get_preferred_dataset",
@ -287,7 +287,7 @@ async def test_hassio_discovery_flow_router_not_setup_has_preferred(
assert aioclient_mock.mock_calls[-2][1].path == "/node/dataset/active" assert aioclient_mock.mock_calls[-2][1].path == "/node/dataset/active"
assert aioclient_mock.mock_calls[-2][2] == DATASET_CH15.hex() assert aioclient_mock.mock_calls[-2][2] == DATASET_CH15.hex()
assert aioclient_mock.mock_calls[-1][0] == "POST" assert aioclient_mock.mock_calls[-1][0] == "PUT"
assert aioclient_mock.mock_calls[-1][1].path == "/node/state" assert aioclient_mock.mock_calls[-1][1].path == "/node/state"
assert aioclient_mock.mock_calls[-1][2] == "enable" assert aioclient_mock.mock_calls[-1][2] == "enable"
@ -318,8 +318,8 @@ async def test_hassio_discovery_flow_router_not_setup_has_preferred_2(
""" """
url = "http://core-silabs-multiprotocol:8081" url = "http://core-silabs-multiprotocol:8081"
aioclient_mock.get(f"{url}/node/dataset/active", status=HTTPStatus.NO_CONTENT) aioclient_mock.get(f"{url}/node/dataset/active", status=HTTPStatus.NO_CONTENT)
aioclient_mock.post(f"{url}/node/dataset/active", status=HTTPStatus.ACCEPTED) aioclient_mock.put(f"{url}/node/dataset/active", status=HTTPStatus.CREATED)
aioclient_mock.post(f"{url}/node/state", status=HTTPStatus.OK) aioclient_mock.put(f"{url}/node/state", status=HTTPStatus.OK)
networksettings = Mock() networksettings = Mock()
networksettings.network_info.channel = 15 networksettings.network_info.channel = 15
@ -342,14 +342,14 @@ async def test_hassio_discovery_flow_router_not_setup_has_preferred_2(
) )
# Check we create a dataset and enable the router # Check we create a dataset and enable the router
assert aioclient_mock.mock_calls[-2][0] == "POST" assert aioclient_mock.mock_calls[-2][0] == "PUT"
assert aioclient_mock.mock_calls[-2][1].path == "/node/dataset/active" assert aioclient_mock.mock_calls[-2][1].path == "/node/dataset/active"
assert aioclient_mock.mock_calls[-2][2] == { assert aioclient_mock.mock_calls[-2][2] == {
"Channel": 15, "Channel": 15,
"NetworkName": "home-assistant", "NetworkName": "home-assistant",
} }
assert aioclient_mock.mock_calls[-1][0] == "POST" assert aioclient_mock.mock_calls[-1][0] == "PUT"
assert aioclient_mock.mock_calls[-1][1].path == "/node/state" assert aioclient_mock.mock_calls[-1][1].path == "/node/state"
assert aioclient_mock.mock_calls[-1][2] == "enable" assert aioclient_mock.mock_calls[-1][2] == "enable"

View File

@ -97,9 +97,7 @@ async def test_create_network(
assert msg["result"] is None assert msg["result"] is None
create_dataset_mock.assert_called_once_with( create_dataset_mock.assert_called_once_with(
python_otbr_api.models.OperationalDataSet( python_otbr_api.models.ActiveDataSet(channel=15, network_name="home-assistant")
channel=15, network_name="home-assistant"
)
) )
assert len(set_enabled_mock.mock_calls) == 2 assert len(set_enabled_mock.mock_calls) == 2
assert set_enabled_mock.mock_calls[0][1][0] is False assert set_enabled_mock.mock_calls[0][1][0] is False