diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a27fe99b0..6979f8569 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,6 +3,9 @@ "name": "Hass.io dev", "context": "..", "dockerFile": "Dockerfile", + "runArgs": [ + "-e", "GIT_EDTIOR='code --wait'" + ], "extensions": [ "ms-python.python" ], @@ -13,6 +16,7 @@ "python.formatting.provider": "black", "editor.formatOnPaste": false, "editor.formatOnSave": true, - "editor.formatOnType": true + "editor.formatOnType": true, + "files.trimTrailingWhitespace": true } -} \ No newline at end of file +} diff --git a/API.md b/API.md index 87226f6c4..48c2cc5f5 100644 --- a/API.md +++ b/API.md @@ -730,7 +730,8 @@ return: "arch": "arch", "supported_arch": ["arch1", "arch2"], "channel": "stable|beta|dev", - "logging": "debug|info|warning|error|critical" + "logging": "debug|info|warning|error|critical", + "timezone": "Europe/Zurich" } ``` diff --git a/hassio/api/addons.py b/hassio/api/addons.py index 2c10870d0..41e0767b3 100644 --- a/hassio/api/addons.py +++ b/hassio/api/addons.py @@ -291,7 +291,7 @@ class APIAddons(CoreSysAttributes): _LOGGER.warning("Protected flag changing for %s!", addon.slug) addon.protected = body[ATTR_PROTECTED] - addon.save_data() + addon.save_persist() @api_process async def stats(self, request: web.Request) -> Dict[str, Any]: diff --git a/hassio/api/info.py b/hassio/api/info.py index 527397946..249f6f03c 100644 --- a/hassio/api/info.py +++ b/hassio/api/info.py @@ -14,6 +14,7 @@ from ..const import ( ATTR_MACHINE, ATTR_SUPERVISOR, ATTR_SUPPORTED_ARCH, + ATTR_TIMEZONE, ) from ..coresys import CoreSysAttributes from .utils import api_process @@ -37,4 +38,5 @@ class APIInfo(CoreSysAttributes): ATTR_SUPPORTED_ARCH: self.sys_arch.supported, ATTR_CHANNEL: self.sys_updater.channel, ATTR_LOGGING: self.sys_config.logging, + ATTR_TIMEZONE: self.sys_timezone, } 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/const.py b/hassio/const.py index 8e49f1b5e..cf3eedcd0 100644 --- a/hassio/const.py +++ b/hassio/const.py @@ -3,7 +3,7 @@ from pathlib import Path from ipaddress import ip_network -HASSIO_VERSION = "167" +HASSIO_VERSION = "168" URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons" URL_HASSIO_VERSION = "https://s3.amazonaws.com/hassio-version/{channel}.json" 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: diff --git a/hassio/ingress.py b/hassio/ingress.py index cc87b242b..83dda70b0 100644 --- a/hassio/ingress.py +++ b/hassio/ingress.py @@ -96,8 +96,6 @@ class Ingress(JsonConfig, CoreSysAttributes): valid = utcnow() + timedelta(minutes=15) self.sessions[session] = valid.timestamp() - self.save_data() - return session def validate_session(self, session: str) -> bool: diff --git a/requirements_tests.txt b/requirements_tests.txt index a5678efc3..d6830550d 100644 --- a/requirements_tests.txt +++ b/requirements_tests.txt @@ -1,5 +1,5 @@ flake8==3.7.7 pylint==2.3.1 -pytest==4.6.3 +pytest==5.0.1 pytest-timeout==1.3.3 pytest-aiohttp==0.3.0 diff --git a/tests/test_ingress.py b/tests/test_ingress.py index 50f1d5de4..a1aaf570e 100644 --- a/tests/test_ingress.py +++ b/tests/test_ingress.py @@ -9,7 +9,6 @@ def test_session_handling(coresys): session = coresys.ingress.create_session() validate = coresys.ingress.sessions[session] - assert coresys.ingress.save_data.called assert session assert validate @@ -22,6 +21,14 @@ def test_session_handling(coresys): assert not coresys.ingress.validate_session("invalid session") +async def test_save_on_unload(coresys): + """Test called save on unload.""" + coresys.ingress.create_session() + await coresys.ingress.unload() + + assert coresys.ingress.save_data.called + + def test_dynamic_ports(coresys): """Test dyanmic port handling.""" port_test1 = coresys.ingress.get_dynamic_port("test1") diff --git a/tox.ini b/tox.ini index 970b3f383..99aa3aa26 100644 --- a/tox.ini +++ b/tox.ini @@ -16,4 +16,4 @@ commands = [testenv:tests] basepython = python3 commands = - pytest --duration=10 tests + pytest --timeout=10 tests