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