From 69991bf3a2c4f09d874946ab10d101e1bacf49e7 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Thu, 28 Nov 2019 05:45:43 +0100 Subject: [PATCH] Move GoogleConfig initialization into setup of component (#29170) --- homeassistant/components/google_assistant/__init__.py | 9 +++++++-- homeassistant/components/google_assistant/http.py | 11 ----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/google_assistant/__init__.py b/homeassistant/components/google_assistant/__init__.py index f0f2ad77388..c156bf0176b 100644 --- a/homeassistant/components/google_assistant/__init__.py +++ b/homeassistant/components/google_assistant/__init__.py @@ -32,7 +32,7 @@ from .const import ( ) from .const import EVENT_COMMAND_RECEIVED, EVENT_SYNC_RECEIVED # noqa: F401 from .const import EVENT_QUERY_RECEIVED # noqa: F401 -from .http import async_register_http +from .http import GoogleAssistantView, GoogleConfig _LOGGER = logging.getLogger(__name__) @@ -93,7 +93,12 @@ CONFIG_SCHEMA = vol.Schema({DOMAIN: GOOGLE_ASSISTANT_SCHEMA}, extra=vol.ALLOW_EX async def async_setup(hass: HomeAssistant, yaml_config: Dict[str, Any]): """Activate Google Actions component.""" config = yaml_config.get(DOMAIN, {}) - google_config = async_register_http(hass, config) + google_config = GoogleConfig(hass, config) + + hass.http.register_view(GoogleAssistantView(google_config)) + + if google_config.should_report_state: + google_config.async_enable_report_state() async def request_sync_service_handler(call: ServiceCall): """Handle request sync service calls.""" diff --git a/homeassistant/components/google_assistant/http.py b/homeassistant/components/google_assistant/http.py index 164ef8bb4de..abf931bd969 100644 --- a/homeassistant/components/google_assistant/http.py +++ b/homeassistant/components/google_assistant/http.py @@ -10,7 +10,6 @@ from aiohttp.web import Request, Response # Typing imports from homeassistant.components.http import HomeAssistantView -from homeassistant.core import callback from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.util import dt as dt_util @@ -225,16 +224,6 @@ class GoogleConfig(AbstractConfig): await self.async_call_homegraph_api(REPORT_STATE_BASE_URL, data) -@callback -def async_register_http(hass, cfg): - """Register HTTP views for Google Assistant.""" - config = GoogleConfig(hass, cfg) - hass.http.register_view(GoogleAssistantView(config)) - if config.should_report_state: - config.async_enable_report_state() - return config - - class GoogleAssistantView(HomeAssistantView): """Handle Google Assistant requests."""