8000 Remove cloud dependency from mobile_app by balloob · Pull Request #29373 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove cloud dependency from mobile_app #29373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions homeassistant/components/mobile_app/http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
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
Expand Down Expand Up @@ -41,8 +37,12 @@ async def post(self, request: Request, data: Dict) -> Response:

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("-", "")

Expand All @@ -59,10 +59,11 @@ async def post(self, request: Request, data: Dict) -> Response:
)

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(
{
Expand Down
14 changes: 3 additions & 11 deletions homeassistant/components/mobile_app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
10 changes: 5 additions & 5 deletions homeassistant/components/mobile_app/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 (
Expand Down Expand Up @@ -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)
3 changes: 1 addition & 2 deletions homeassistant/components/mobile_app/websocket_api.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"))
0