Move GoogleConfig initialization into setup of component (#29170)

pull/29182/head
Joakim Plate 2019-11-28 05:45:43 +01:00 committed by Paulus Schoutsen
parent 3ecf5596ff
commit 69991bf3a2
2 changed files with 7 additions and 13 deletions

View File

@ -32,7 +32,7 @@ from .const import (
) )
from .const import EVENT_COMMAND_RECEIVED, EVENT_SYNC_RECEIVED # noqa: F401 from .const import EVENT_COMMAND_RECEIVED, EVENT_SYNC_RECEIVED # noqa: F401
from .const import EVENT_QUERY_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__) _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]): async def async_setup(hass: HomeAssistant, yaml_config: Dict[str, Any]):
"""Activate Google Actions component.""" """Activate Google Actions component."""
config = yaml_config.get(DOMAIN, {}) 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): async def request_sync_service_handler(call: ServiceCall):
"""Handle request sync service calls.""" """Handle request sync service calls."""

View File

@ -10,7 +10,6 @@ from aiohttp.web import Request, Response
# Typing imports # Typing imports
from homeassistant.components.http import HomeAssistantView from homeassistant.components.http import HomeAssistantView
from homeassistant.core import callback
from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.util import dt as dt_util 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) 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): class GoogleAssistantView(HomeAssistantView):
"""Handle Google Assistant requests.""" """Handle Google Assistant requests."""