Replace use of deprecated APIs in aiohomekit (#66409)

This commit is contained in:
Jc2k
2022-02-13 05:17:55 +00:00
committed by GitHub
parent 0a128d006f
commit b8a8485e91
5 changed files with 19 additions and 22 deletions

View File

@@ -86,13 +86,11 @@ def _setup_flow_handler(hass, pairing=None):
discovery = mock.Mock()
discovery.device_id = "00:00:00:00:00:00"
discovery.start_pairing = unittest.mock.AsyncMock(return_value=finish_pairing)
discovery.async_start_pairing = unittest.mock.AsyncMock(return_value=finish_pairing)
flow.controller = mock.Mock()
flow.controller.pairings = {}
flow.controller.find_ip_by_device_id = unittest.mock.AsyncMock(
return_value=discovery
)
flow.controller.async_find = unittest.mock.AsyncMock(return_value=discovery)
return flow
@@ -520,7 +518,7 @@ async def test_pair_abort_errors_on_start(hass, controller, exception, expected)
# User initiates pairing - device refuses to enter pairing mode
test_exc = exception("error")
with patch.object(device, "start_pairing", side_effect=test_exc):
with patch.object(device, "async_start_pairing", side_effect=test_exc):
result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result["type"] == "abort"
assert result["reason"] == expected
@@ -542,7 +540,7 @@ async def test_pair_try_later_errors_on_start(hass, controller, exception, expec
# User initiates pairing - device refuses to enter pairing mode but may be successful after entering pairing mode or rebooting
test_exc = exception("error")
with patch.object(device, "start_pairing", side_effect=test_exc):
with patch.object(device, "async_start_pairing", side_effect=test_exc):
result2 = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result2["step_id"] == expected
assert result2["type"] == "form"
@@ -585,7 +583,7 @@ async def test_pair_form_errors_on_start(hass, controller, exception, expected):
# User initiates pairing - device refuses to enter pairing mode
test_exc = exception("error")
with patch.object(device, "start_pairing", side_effect=test_exc):
with patch.object(device, "async_start_pairing", side_effect=test_exc):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={"pairing_code": "111-22-333"}
)
@@ -634,7 +632,7 @@ async def test_pair_abort_errors_on_finish(hass, controller, exception, expected
# User initiates pairing - this triggers the device to show a pairing code
# and then HA to show a pairing form
finish_pairing = unittest.mock.AsyncMock(side_effect=exception("error"))
with patch.object(device, "start_pairing", return_value=finish_pairing):
with patch.object(device, "async_start_pairing", return_value=finish_pairing):
result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result["type"] == "form"
@@ -674,7 +672,7 @@ async def test_pair_form_errors_on_finish(hass, controller, exception, expected)
# User initiates pairing - this triggers the device to show a pairing code
# and then HA to show a pairing form
finish_pairing = unittest.mock.AsyncMock(side_effect=exception("error"))
with patch.object(device, "start_pairing", return_value=finish_pairing):
with patch.object(device, "async_start_pairing", return_value=finish_pairing):
result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result["type"] == "form"
@@ -789,7 +787,7 @@ async def test_user_no_unpaired_devices(hass, controller):
device = setup_mock_accessory(controller)
# Pair the mock device so that it shows as paired in discovery
finish_pairing = await device.start_pairing(device.device_id)
finish_pairing = await device.async_start_pairing(device.device_id)
await finish_pairing(device.pairing_code)
# Device discovery is requested