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
@@ -2,11 +2,13 @@
|
||||
import ipaddress
|
||||
import logging
|
||||
|
||||
from aiohttp import web
|
||||
import voluptuous as vol
|
||||
from zeroconf import InterfaceChoice
|
||||
|
||||
from homeassistant.components import cover, vacuum
|
||||
from homeassistant.components.cover import DEVICE_CLASS_GARAGE, DEVICE_CLASS_GATE
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.components.media_player import DEVICE_CLASS_TV
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
@@ -28,6 +30,7 @@ from homeassistant.const import (
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import Unauthorized
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entityfilter import FILTER_SCHEMA
|
||||
from homeassistant.util import get_local_ip
|
||||
@@ -56,6 +59,8 @@ from .const import (
|
||||
DOMAIN,
|
||||
EVENT_HOMEKIT_CHANGED,
|
||||
HOMEKIT_FILE,
|
||||
HOMEKIT_PAIRING_QR,
|
||||
HOMEKIT_PAIRING_QR_SECRET,
|
||||
SERVICE_HOMEKIT_RESET_ACCESSORY,
|
||||
SERVICE_HOMEKIT_START,
|
||||
TYPE_FAUCET,
|
||||
@@ -129,6 +134,8 @@ async def async_setup(hass, config):
|
||||
aid_storage = hass.data[AID_STORAGE] = AccessoryAidStorage(hass)
|
||||
await aid_storage.async_initialize()
|
||||
|
||||
hass.http.register_view(HomeKitPairingQRView)
|
||||
|
||||
conf = config[DOMAIN]
|
||||
name = conf[CONF_NAME]
|
||||
port = conf[CONF_PORT]
|
||||
@@ -445,7 +452,9 @@ class HomeKit:
|
||||
self.driver.add_accessory(self.bridge)
|
||||
|
||||
if not self.driver.state.paired:
|
||||
show_setup_message(self.hass, self.driver.state.pincode)
|
||||
show_setup_message(
|
||||
self.hass, self.driver.state.pincode, self.bridge.xhm_uri()
|
||||
)
|
||||
|
||||
_LOGGER.debug("Driver start")
|
||||
self.hass.add_job(self.driver.start)
|
||||
@@ -459,3 +468,21 @@ class HomeKit:
|
||||
|
||||
_LOGGER.debug("Driver stop")
|
||||
self.hass.add_job(self.driver.stop)
|
||||
|
||||
|
||||
class HomeKitPairingQRView(HomeAssistantView):
|
||||
"""Display the homekit pairing code at a protected url."""
|
||||
|
||||
url = "/api/homekit/pairingqr"
|
||||
name = "api:homekit:pairingqr"
|
||||
requires_auth = False
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
async def get(self, request):
|
||||
"""Retrieve the pairing QRCode image."""
|
||||
if request.query_string != request.app["hass"].data[HOMEKIT_PAIRING_QR_SECRET]:
|
||||
raise Unauthorized()
|
||||
return web.Response(
|
||||
body=request.app["hass"].data[HOMEKIT_PAIRING_QR],
|
||||
content_type="image/svg+xml",
|
||||
)
|
||||
Reference in new issue
Block a user