Skip to content

Commit

Permalink
Mobile App: Expose Cloud Remote UI FQDN in registration response (hom…
Browse files Browse the repository at this point in the history
…e-assistant#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
  • Loading branch information
robbiet480 authored and balloob committed Mar 15, 2019
1 parent 11ebb3f commit 0029dc3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 10 additions & 0 deletions homeassistant/components/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/mobile_app/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
STORAGE_VERSION = 1

CONF_CLOUDHOOK_URL = 'cloudhook_url'
CONF_REMOTE_UI_URL = 'remote_ui_url'
CONF_SECRET = 'secret'
CONF_USER_ID = 'user_id'

Expand Down
14 changes: 12 additions & 2 deletions homeassistant/components/mobile_app/http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
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)

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)

Expand Down Expand Up @@ -67,8 +70,15 @@ async def post(self, request: Request, data: Dict) -> Response:
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)

0 comments on commit 0029dc3

Please sign in to comment.