Display Homekit QR code when pairing (#34449)
* Display a QR code for homekit pairing This will reduce the failure rate with HomeKit pairing because there is less chance of entry error. * Add coverage * Test that the qr code is created * I cannot spell * Update homeassistant/components/homekit/__init__.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/homekit/__init__.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
1 parent
ca08b70984
commit
d06fce6997
10 files changed
+75
-14
No files matched your search
@@ -340,6 +340,8 @@ def test_home_driver():
|
||||
|
||||
mock_driver.assert_called_with(address=ip_address, port=port, persist_file=path)
|
||||
driver.state = Mock(pincode=pin)
|
||||
xhm_uri_mock = Mock(return_value="X-HM://0")
|
||||
driver.accessory = Mock(xhm_uri=xhm_uri_mock)
|
||||
|
||||
# pair
|
||||
with patch("pyhap.accessory_driver.AccessoryDriver.pair") as mock_pair, patch(
|
||||
@@ -357,4 +359,4 @@ def test_home_driver():
|
||||
driver.unpair("client_uuid")
|
||||
|
||||
mock_unpair.assert_called_with("client_uuid")
|
||||
mock_show_msg.assert_called_with("hass", pin)
|
||||
mock_show_msg.assert_called_with("hass", pin, "X-HM://0")
|
||||
@@ -293,7 +293,7 @@ async def test_homekit_start(hass, hk_driver, debounce_patcher):
|
||||
await hass.async_add_executor_job(homekit.start)
|
||||
|
||||
mock_add_acc.assert_called_with(state)
|
||||
mock_setup_msg.assert_called_with(hass, pin)
|
||||
mock_setup_msg.assert_called_with(hass, pin, ANY)
|
||||
hk_driver_add_acc.assert_called_with(homekit.bridge)
|
||||
assert hk_driver_start.called
|
||||
assert homekit.status == STATUS_RUNNING
|
||||
@@ -328,7 +328,7 @@ async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, debounce_p
|
||||
) as hk_driver_start:
|
||||
await hass.async_add_executor_job(homekit.start)
|
||||
|
||||
mock_setup_msg.assert_called_with(hass, pin)
|
||||
mock_setup_msg.assert_called_with(hass, pin, ANY)
|
||||
hk_driver_add_acc.assert_called_with(homekit.bridge)
|
||||
assert hk_driver_start.called
|
||||
assert homekit.status == STATUS_RUNNING
|
||||
@@ -405,6 +405,8 @@ async def test_homekit_too_many_accessories(hass, hk_driver):
|
||||
|
||||
with patch("pyhap.accessory_driver.AccessoryDriver.start"), patch(
|
||||
"pyhap.accessory_driver.AccessoryDriver.add_accessory"
|
||||
), patch("homeassistant.components.homekit._LOGGER.warning") as mock_warn:
|
||||
), patch("homeassistant.components.homekit._LOGGER.warning") as mock_warn, patch(
|
||||
f"{PATH_HOMEKIT}.show_setup_message"
|
||||
):
|
||||
await hass.async_add_executor_job(homekit.start)
|
||||
assert mock_warn.called is True
|
||||
@@ -10,6 +10,8 @@ from homeassistant.components.homekit.const import (
|
||||
FEATURE_ON_OFF,
|
||||
FEATURE_PLAY_PAUSE,
|
||||
HOMEKIT_NOTIFY_ID,
|
||||
HOMEKIT_PAIRING_QR,
|
||||
HOMEKIT_PAIRING_QR_SECRET,
|
||||
TYPE_FAUCET,
|
||||
TYPE_OUTLET,
|
||||
TYPE_SHOWER,
|
||||
@@ -199,8 +201,10 @@ async def test_show_setup_msg(hass):
|
||||
|
||||
call_create_notification = async_mock_service(hass, DOMAIN, "create")
|
||||
|
||||
await hass.async_add_executor_job(show_setup_message, hass, pincode)
|
||||
await hass.async_add_executor_job(show_setup_message, hass, pincode, "X-HM://0")
|
||||
await hass.async_block_till_done()
|
||||
assert hass.data[HOMEKIT_PAIRING_QR_SECRET]
|
||||
assert hass.data[HOMEKIT_PAIRING_QR]
|
||||
|
||||
assert call_create_notification
|
||||
assert call_create_notification[0].data[ATTR_NOTIFICATION_ID] == HOMEKIT_NOTIFY_ID
|
||||
|
||||
Reference in new issue
Block a user