diff --git a/homeassistant/components/cloud/__init__.py b/homeassistant/components/cloud/__init__.py index 2e324f06738..3e3d6f975e9 100644 --- a/homeassistant/components/cloud/__init__.py +++ b/homeassistant/components/cloud/__init__.py @@ -118,6 +118,16 @@ async def async_delete_cloudhook(hass, webhook_id: str) -> None: 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): """Test if a request came from a cloudhook. diff --git a/homeassistant/components/mobile_app/const.py b/homeassistant/components/mobile_app/const.py index d38df31b214..3aa4626da29 100644 --- a/homeassistant/components/mobile_app/const.py +++ b/homeassistant/components/mobile_app/const.py @@ -17,6 +17,7 @@ STORAGE_KEY = DOMAIN STORAGE_VERSION = 1 CONF_CLOUDHOOK_URL = 'cloudhook_url' +CONF_REMOTE_UI_URL = 'remote_ui_url' CONF_SECRET = 'secret' CONF_USER_ID = 'user_id' diff --git a/homeassistant/components/mobile_app/http_api.py b/homeassistant/components/mobile_app/http_api.py index 8076d217cac..2ae8f441e52 100644 --- a/homeassistant/components/mobile_app/http_api.py +++ b/homeassistant/components/mobile_app/http_api.py @@ -5,7 +5,9 @@ from typing import Dict from aiohttp.web import Response, Request 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.data_validator import RequestDataValidator 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 .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, REGISTRATION_SCHEMA) @@ -67,8 +70,15 @@ class RegistrationsView(HomeAssistantView): hass.config_entries.flow.async_init(DOMAIN, context=ctx, data=data)) + remote_ui_url = None + try: + remote_ui_url = async_remote_ui_url(hass) + except CloudNotAvailable: + pass + return self.json({ CONF_CLOUDHOOK_URL: data.get(CONF_CLOUDHOOK_URL), + CONF_REMOTE_UI_URL: remote_ui_url, CONF_SECRET: data.get(CONF_SECRET), CONF_WEBHOOK_ID: data[CONF_WEBHOOK_ID], }, status_code=HTTP_CREATED)