mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Mobile App: Expose Cloud Remote UI FQDN in registration response (#22055)
* Add a callback to get the cloud remote UI FQDN * Expose Cloud Remote UI FQDN in the registration response * Return a URL instead of FQDN
This commit is contained in:
parent
11ebb3f24e
commit
0029dc3813
@ -118,6 +118,16 @@ async def async_delete_cloudhook(hass, webhook_id: str) -> None:
|
|||||||
await hass.data[DOMAIN].cloudhooks.async_delete(webhook_id)
|
await hass.data[DOMAIN].cloudhooks.async_delete(webhook_id)
|
||||||
|
|
||||||
|
|
||||||
|
@bind_hass
|
||||||
|
@callback
|
||||||
|
def async_remote_ui_url(hass) -> str:
|
||||||
|
"""Get the remote UI URL."""
|
||||||
|
if not async_is_logged_in(hass):
|
||||||
|
raise CloudNotAvailable
|
||||||
|
|
||||||
|
return "https://" + hass.data[DOMAIN].remote.instance_domain
|
||||||
|
|
||||||
|
|
||||||
def is_cloudhook_request(request):
|
def is_cloudhook_request(request):
|
||||||
"""Test if a request came from a cloudhook.
|
"""Test if a request came from a cloudhook.
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ STORAGE_KEY = DOMAIN
|
|||||||
STORAGE_VERSION = 1
|
STORAGE_VERSION = 1
|
||||||
|
|
||||||
CONF_CLOUDHOOK_URL = 'cloudhook_url'
|
CONF_CLOUDHOOK_URL = 'cloudhook_url'
|
||||||
|
CONF_REMOTE_UI_URL = 'remote_ui_url'
|
||||||
CONF_SECRET = 'secret'
|
CONF_SECRET = 'secret'
|
||||||
CONF_USER_ID = 'user_id'
|
CONF_USER_ID = 'user_id'
|
||||||
|
|
||||||
|
@ -5,7 +5,9 @@ from typing import Dict
|
|||||||
from aiohttp.web import Response, Request
|
from aiohttp.web import Response, Request
|
||||||
|
|
||||||
from homeassistant.auth.util import generate_secret
|
from homeassistant.auth.util import generate_secret
|
||||||
from homeassistant.components.cloud import async_create_cloudhook
|
from homeassistant.components.cloud import (async_create_cloudhook,
|
||||||
|
async_remote_ui_url,
|
||||||
|
CloudNotAvailable)
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.components.http.data_validator import RequestDataValidator
|
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||||
from homeassistant.const import (HTTP_CREATED, CONF_WEBHOOK_ID)
|
from homeassistant.const import (HTTP_CREATED, CONF_WEBHOOK_ID)
|
||||||
@ -13,7 +15,8 @@ from homeassistant.const import (HTTP_CREATED, CONF_WEBHOOK_ID)
|
|||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
|
|
||||||
from .const import (ATTR_APP_COMPONENT, ATTR_DEVICE_ID,
|
from .const import (ATTR_APP_COMPONENT, ATTR_DEVICE_ID,
|
||||||
ATTR_SUPPORTS_ENCRYPTION, CONF_CLOUDHOOK_URL, CONF_SECRET,
|
ATTR_SUPPORTS_ENCRYPTION, CONF_CLOUDHOOK_URL,
|
||||||
|
CONF_REMOTE_UI_URL, CONF_SECRET,
|
||||||
CONF_USER_ID, DOMAIN, ERR_INVALID_COMPONENT,
|
CONF_USER_ID, DOMAIN, ERR_INVALID_COMPONENT,
|
||||||
REGISTRATION_SCHEMA)
|
REGISTRATION_SCHEMA)
|
||||||
|
|
||||||
@ -67,8 +70,15 @@ class RegistrationsView(HomeAssistantView):
|
|||||||
hass.config_entries.flow.async_init(DOMAIN, context=ctx,
|
hass.config_entries.flow.async_init(DOMAIN, context=ctx,
|
||||||
data=data))
|
data=data))
|
||||||
|
|
||||||
|
remote_ui_url = None
|
||||||
|
try:
|
||||||
|
remote_ui_url = async_remote_ui_url(hass)
|
||||||
|
except CloudNotAvailable:
|
||||||
|
pass
|
||||||
|
|
||||||
return self.json({
|
return self.json({
|
||||||
CONF_CLOUDHOOK_URL: data.get(CONF_CLOUDHOOK_URL),
|
CONF_CLOUDHOOK_URL: data.get(CONF_CLOUDHOOK_URL),
|
||||||
|
CONF_REMOTE_UI_URL: remote_ui_url,
|
||||||
CONF_SECRET: data.get(CONF_SECRET),
|
CONF_SECRET: data.get(CONF_SECRET),
|
||||||
CONF_WEBHOOK_ID: data[CONF_WEBHOOK_ID],
|
CONF_WEBHOOK_ID: data[CONF_WEBHOOK_ID],
|
||||||
}, status_code=HTTP_CREATED)
|
}, status_code=HTTP_CREATED)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user