From aa40476b4962889822b34c35d5e37ef7945298a2 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 17 Jan 2022 14:19:11 +0100 Subject: [PATCH] Fix comments, improve readability in Cloud (#64291) --- homeassistant/components/cloud/client.py | 4 ++-- .../components/cloud/google_config.py | 2 +- homeassistant/components/cloud/http_api.py | 18 +++++++++--------- homeassistant/components/cloud/prefs.py | 2 +- .../components/google_assistant/helpers.py | 9 ++++++--- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/cloud/client.py b/homeassistant/components/cloud/client.py index ed31a576e67..b6643163331 100644 --- a/homeassistant/components/cloud/client.py +++ b/homeassistant/components/cloud/client.py @@ -13,7 +13,7 @@ from hass_nabucasa.client import CloudClient as Interface from homeassistant.components import persistent_notification, webhook from homeassistant.components.alexa import ( errors as alexa_errors, - smart_home as alexa_sh, + smart_home as alexa_smart_home, ) from homeassistant.components.google_assistant import const as gc, smart_home as ga from homeassistant.core import Context, HomeAssistant, callback @@ -180,7 +180,7 @@ class CloudClient(Interface): """Process cloud alexa message to client.""" cloud_user = await self._prefs.get_cloud_user() aconfig = await self.get_alexa_config() - return await alexa_sh.async_handle_message( + return await alexa_smart_home.async_handle_message( self._hass, aconfig, payload, diff --git a/homeassistant/components/cloud/google_config.py b/homeassistant/components/cloud/google_config.py index 019a3be6f73..891e0e4a956 100644 --- a/homeassistant/components/cloud/google_config.py +++ b/homeassistant/components/cloud/google_config.py @@ -88,7 +88,7 @@ class CloudGoogleConfig(AbstractConfig): start.async_at_start(self.hass, hass_started) - # Remove old/wrong user agent ids + # Remove any stored user agent id that is not ours remove_agent_user_ids = [] for agent_user_id in self._store.agent_user_ids: if agent_user_id != self.agent_user_id: diff --git a/homeassistant/components/cloud/http_api.py b/homeassistant/components/cloud/http_api.py index 50766cd2c6c..0400f01a39f 100644 --- a/homeassistant/components/cloud/http_api.py +++ b/homeassistant/components/cloud/http_api.py @@ -434,17 +434,17 @@ async def _account_data(cloud): certificate = None return { - "logged_in": True, - "email": claims["email"], - "cloud": cloud.iot.state, - "prefs": client.prefs.as_dict(), - "google_registered": google_config.has_registered_user_agent, - "google_entities": client.google_user_config["filter"].config, - "alexa_registered": alexa_config.authorized, "alexa_entities": client.alexa_user_config["filter"].config, - "remote_domain": remote.instance_domain, - "remote_connected": remote.is_connected, + "alexa_registered": alexa_config.authorized, + "cloud": cloud.iot.state, + "email": claims["email"], + "google_entities": client.google_user_config["filter"].config, + "google_registered": google_config.has_registered_user_agent, + "logged_in": True, + "prefs": client.prefs.as_dict(), "remote_certificate": certificate, + "remote_connected": remote.is_connected, + "remote_domain": remote.instance_domain, } diff --git a/homeassistant/components/cloud/prefs.py b/homeassistant/components/cloud/prefs.py index a7ad75b20ba..3cc6e8deb60 100644 --- a/homeassistant/components/cloud/prefs.py +++ b/homeassistant/components/cloud/prefs.py @@ -275,7 +275,7 @@ class CloudPreferences: return self._prefs.get(PREF_TTS_DEFAULT_VOICE, DEFAULT_TTS_DEFAULT_VOICE) async def get_cloud_user(self) -> str: - """Return ID from Home Assistant Cloud system user.""" + """Return ID of Home Assistant Cloud system user.""" user = await self._load_cloud_user() if user: diff --git a/homeassistant/components/google_assistant/helpers.py b/homeassistant/components/google_assistant/helpers.py index 667871a3473..84b1446f9de 100644 --- a/homeassistant/components/google_assistant/helpers.py +++ b/homeassistant/components/google_assistant/helpers.py @@ -256,16 +256,19 @@ class AbstractConfig(ABC): raise NotImplementedError async def async_connect_agent_user(self, agent_user_id: str): - """Add an synced and known agent_user_id. + """Add a synced and known agent_user_id. - Called when a completed sync response have been sent to Google. + Called before sending a sync response to Google. """ self._store.add_agent_user_id(agent_user_id) async def async_disconnect_agent_user(self, agent_user_id: str): """Turn off report state and disable further state reporting. - Called when the user disconnects their account from Google. + Called when: + - The user disconnects their account from Google. + - When the cloud configuration is initialized + - When sync entities fails with 404 """ self._store.pop_agent_user_id(agent_user_id)