Add cloud status (#21960)

* Add cloud status

* Expose certificate details

* store & reset last state

* Fix tests

* update tests

* update req

* fix lint
This commit is contained in:
Paulus Schoutsen 2019-03-12 07:54:04 -07:00 committed by Pascal Vizeli
parent ac97cebe11
commit d3bab30dbe
9 changed files with 133 additions and 47 deletions

View file

@ -3,6 +3,7 @@ import asyncio
from functools import wraps
import logging
import attr
import aiohttp
import async_timeout
import voluptuous as vol
@ -82,6 +83,10 @@ async def async_setup(hass):
WS_TYPE_HOOK_DELETE, websocket_hook_delete,
SCHEMA_WS_HOOK_DELETE
)
hass.components.websocket_api.async_register_command(
websocket_remote_connect)
hass.components.websocket_api.async_register_command(
websocket_remote_disconnect)
hass.http.register_view(GoogleActionsSyncView)
hass.http.register_view(CloudLoginView)
hass.http.register_view(CloudLogoutView)
@ -387,6 +392,13 @@ def _account_data(cloud):
claims = cloud.claims
client = cloud.client
remote = cloud.remote
# Load remote certificate
if remote.certificate:
certificate = attr.asdict(remote.certificate)
else:
certificate = None
return {
'logged_in': True,
@ -397,4 +409,33 @@ def _account_data(cloud):
'google_domains': list(google_sh.DOMAIN_TO_GOOGLE_TYPES),
'alexa_entities': client.alexa_config.should_expose.config,
'alexa_domains': list(alexa_sh.ENTITY_ADAPTERS),
'remote_domain': remote.instance_domain,
'remote_connected': remote.is_connected,
'remote_certificate': certificate,
}
@_require_cloud_login
@websocket_api.async_response
@websocket_api.websocket_command({
'type': 'cloud/remote/connect'
})
async def websocket_remote_connect(hass, connection, msg):
"""Handle request for connect remote."""
cloud = hass.data[DOMAIN]
await cloud.remote.connect()
await cloud.client.prefs.async_update(remote_enabled=True)
connection.send_result(msg['id'], _account_data(cloud))
@_require_cloud_login
@websocket_api.async_response
@websocket_api.websocket_command({
'type': 'cloud/remote/disconnect'
})
async def websocket_remote_disconnect(hass, connection, msg):
"""Handle request for disconnect remote."""
cloud = hass.data[DOMAIN]
await cloud.remote.disconnect()
await cloud.client.prefs.async_update(remote_enabled=False)
connection.send_result(msg['id'], _account_data(cloud))