Remove cloud dependency from mobile_app (#29373)
parent
98b6905738
commit
e26eebfc19
|
@ -6,11 +6,7 @@ from aiohttp.web import Request, Response
|
||||||
from nacl.secret import SecretBox
|
from nacl.secret import SecretBox
|
||||||
|
|
||||||
from homeassistant.auth.util import generate_secret
|
from homeassistant.auth.util import generate_secret
|
||||||
from homeassistant.components.cloud import (
|
|
||||||
CloudNotAvailable,
|
|
||||||
async_create_cloudhook,
|
|
||||||
async_remote_ui_url,
|
|
||||||
)
|
|
||||||
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 CONF_WEBHOOK_ID, HTTP_CREATED
|
from homeassistant.const import CONF_WEBHOOK_ID, HTTP_CREATED
|
||||||
|
@ -41,8 +37,12 @@ class RegistrationsView(HomeAssistantView):
|
||||||
|
|
||||||
webhook_id = generate_secret()
|
webhook_id = generate_secret()
|
||||||
|
|
||||||
if hass.components.cloud.async_active_subscription():
|
cloud_loaded = "cloud" in hass.config.components
|
||||||
data[CONF_CLOUDHOOK_URL] = await async_create_cloudhook(hass, webhook_id)
|
|
||||||
|
if cloud_loaded and hass.components.cloud.async_active_subscription():
|
||||||
|
data[
|
||||||
|
CONF_CLOUDHOOK_URL
|
||||||
|
] = await hass.components.cloud.async_create_cloudhook(webhook_id)
|
||||||
|
|
||||||
data[ATTR_DEVICE_ID] = str(uuid.uuid4()).replace("-", "")
|
data[ATTR_DEVICE_ID] = str(uuid.uuid4()).replace("-", "")
|
||||||
|
|
||||||
|
@ -59,9 +59,10 @@ class RegistrationsView(HomeAssistantView):
|
||||||
)
|
)
|
||||||
|
|
||||||
remote_ui_url = None
|
remote_ui_url = None
|
||||||
|
if cloud_loaded:
|
||||||
try:
|
try:
|
||||||
remote_ui_url = async_remote_ui_url(hass)
|
remote_ui_url = hass.components.cloud.async_remote_ui_url()
|
||||||
except CloudNotAvailable:
|
except hass.components.cloud.CloudNotAvailable:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return self.json(
|
return self.json(
|
||||||
|
|
|
@ -3,15 +3,7 @@
|
||||||
"name": "Home Assistant Mobile App Support",
|
"name": "Home Assistant Mobile App Support",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/mobile_app",
|
"documentation": "https://www.home-assistant.io/integrations/mobile_app",
|
||||||
"requirements": [
|
"requirements": ["PyNaCl==1.3.0"],
|
||||||
"PyNaCl==1.3.0"
|
"dependencies": ["http", "webhook"],
|
||||||
],
|
"codeowners": ["@robbiet480"]
|
||||||
"dependencies": [
|
|
||||||
"cloud",
|
|
||||||
"http",
|
|
||||||
"webhook"
|
|
||||||
],
|
|
||||||
"codeowners": [
|
|
||||||
"@robbiet480"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import logging
|
||||||
from aiohttp.web import HTTPBadRequest, Request, Response
|
from aiohttp.web import HTTPBadRequest, Request, Response
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.cloud import CloudNotAvailable, async_remote_ui_url
|
|
||||||
from homeassistant.components.frontend import MANIFEST_JSON
|
from homeassistant.components.frontend import MANIFEST_JSON
|
||||||
from homeassistant.components.zone.const import DOMAIN as ZONE_DOMAIN
|
from homeassistant.components.zone.const import DOMAIN as ZONE_DOMAIN
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -310,9 +309,10 @@ async def handle_webhook(
|
||||||
if CONF_CLOUDHOOK_URL in registration:
|
if CONF_CLOUDHOOK_URL in registration:
|
||||||
resp[CONF_CLOUDHOOK_URL] = registration[CONF_CLOUDHOOK_URL]
|
resp[CONF_CLOUDHOOK_URL] = registration[CONF_CLOUDHOOK_URL]
|
||||||
|
|
||||||
|
if "cloud" in hass.config.components:
|
||||||
try:
|
try:
|
||||||
resp[CONF_REMOTE_UI_URL] = async_remote_ui_url(hass)
|
resp[CONF_REMOTE_UI_URL] = hass.components.cloud.async_remote_ui_url()
|
||||||
except CloudNotAvailable:
|
except hass.components.cloud.CloudNotAvailable:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return webhook_response(resp, registration=registration, headers=headers)
|
return webhook_response(resp, registration=registration, headers=headers)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""Websocket API for mobile_app."""
|
"""Websocket API for mobile_app."""
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.cloud import async_delete_cloudhook
|
|
||||||
from homeassistant.components.websocket_api import (
|
from homeassistant.components.websocket_api import (
|
||||||
ActiveConnection,
|
ActiveConnection,
|
||||||
async_register_command,
|
async_register_command,
|
||||||
|
@ -117,6 +116,6 @@ async def websocket_delete_registration(
|
||||||
return error_message(msg["id"], "internal_error", "Error deleting registration")
|
return error_message(msg["id"], "internal_error", "Error deleting registration")
|
||||||
|
|
||||||
if CONF_CLOUDHOOK_URL in registration and "cloud" in hass.config.components:
|
if CONF_CLOUDHOOK_URL in registration and "cloud" in hass.config.components:
|
||||||
await async_delete_cloudhook(hass, webhook_id)
|
await hass.components.cloud.async_delete_cloudhook(webhook_id)
|
||||||
|
|
||||||
connection.send_message(result_message(msg["id"], "ok"))
|
connection.send_message(result_message(msg["id"], "ok"))
|
||||||
|
|
Loading…
Reference in New Issue