From a37c90af96204f5aa2334ee0cc521ccba74b8565 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Sat, 6 Jul 2019 18:06:39 +0200 Subject: [PATCH] Forward Params (#1150) --- hassio/api/proxy.py | 11 ++++++----- hassio/homeassistant.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hassio/api/proxy.py b/hassio/api/proxy.py index fe026cec5..c193aeb60 100644 --- a/hassio/api/proxy.py +++ b/hassio/api/proxy.py @@ -20,7 +20,7 @@ _LOGGER = logging.getLogger(__name__) class APIProxy(CoreSysAttributes): """API Proxy for Home Assistant.""" - def _check_access(self, request): + def _check_access(self, request: web.Request): """Check the Hass.io token.""" if AUTHORIZATION in request.headers: bearer = request.headers[AUTHORIZATION] @@ -40,7 +40,7 @@ class APIProxy(CoreSysAttributes): raise HTTPUnauthorized() @asynccontextmanager - async def _api_client(self, request, path, timeout=300): + async def _api_client(self, request: web.Request, path: str, timeout: int = 300): """Return a client request with proxy origin for Home Assistant.""" try: # read data @@ -58,6 +58,7 @@ class APIProxy(CoreSysAttributes): content_type=content_type, data=data, timeout=timeout, + params=request.query, ) as resp: yield resp return @@ -73,7 +74,7 @@ class APIProxy(CoreSysAttributes): raise HTTPBadGateway() - async def stream(self, request): + async def stream(self, request: web.Request): """Proxy HomeAssistant EventStream Requests.""" self._check_access(request) @@ -92,7 +93,7 @@ class APIProxy(CoreSysAttributes): _LOGGER.info("Home Assistant EventStream close") return response - async def api(self, request): + async def api(self, request: web.Request): """Proxy Home Assistant API Requests.""" self._check_access(request) @@ -162,7 +163,7 @@ class APIProxy(CoreSysAttributes): raise APIError() - async def websocket(self, request): + async def websocket(self, request: web.Request): """Initialize a WebSocket API connection.""" _LOGGER.info("Home Assistant WebSocket API request initialize") diff --git a/hassio/homeassistant.py b/hassio/homeassistant.py index 72d178a4c..0e831c907 100644 --- a/hassio/homeassistant.py +++ b/hassio/homeassistant.py @@ -460,7 +460,8 @@ class HomeAssistant(JsonConfig, CoreSysAttributes): json: Optional[Dict[str, Any]] = None, content_type: Optional[str] = None, data: Optional[bytes] = None, - timeout=30, + timeout: int = 30, + params: Optional[Dict[str, str]] = None, ) -> AsyncContextManager[aiohttp.ClientResponse]: """Async context manager to make a request with right auth.""" url = f"{self.api_url}/{path}" @@ -482,7 +483,12 @@ class HomeAssistant(JsonConfig, CoreSysAttributes): try: async with getattr(self.sys_websession_ssl, method)( - url, data=data, timeout=timeout, json=json, headers=headers + url, + data=data, + timeout=timeout, + json=json, + headers=headers, + params=params, ) as resp: # Access token expired if resp.status == 401 and self.refresh_token: