diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..2634ba93c --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.7 + +WORKDIR /workspace + +# Install Python dependencies from requirements.txt if it exists +COPY requirements_tests.txt /workspace/ +RUN pip3 install -r requirements_tests.txt + +# Set the default shell to bash instead of sh +ENV SHELL /bin/bash diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..8e2bfcc86 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,30 @@ +// See https://aka.ms/vscode-remote/devcontainer.json for format details. +{ + "name": "Hass-NabuCasa Dev", + "context": "..", + "dockerFile": "Dockerfile", + "postCreateCommand": "pip3 install -e .", + "runArgs": [ + "-e", + "GIT_EDTIOR='code --wait'" + ], + "extensions": [ + "ms-python.python", + "ms-azure-devops.azure-pipelines" + ], + "settings": { + "python.pythonPath": "/usr/local/bin/python", + "python.linting.pylintEnabled": true, + "python.linting.enabled": true, + "python.formatting.provider": "black", + "python.formatting.blackArgs": [ + "--target-version", + "py36" + ], + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "files.trimTrailingWhitespace": true, + "terminal.integrated.shell.linux": "/bin/bash" + } +} \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 24346e07f..6b1984a94 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -49,7 +49,8 @@ jobs: versionSpec: '3.7' - script: pip install black displayName: 'Install black' - - script: black --check hass_nabucasa tests + - script: | + black --target-version py36 --check hass_nabucasa tests displayName: 'Run Black' diff --git a/hass_nabucasa/acme.py b/hass_nabucasa/acme.py index 4f82d8411..74f47c9be 100644 --- a/hass_nabucasa/acme.py +++ b/hass_nabucasa/acme.py @@ -60,13 +60,13 @@ class AcmeHandler: def __init__(self, cloud, domain: str, email: str) -> None: """Initialize local ACME Handler.""" self.cloud = cloud - self._acme_server = cloud.acme_directory_server - self._account_jwk = None - self._acme_client = None - self._x509 = None + self._acme_server: str = cloud.acme_directory_server + self._account_jwk: Optional[jose.JWKRSA] = None + self._acme_client: Optional[client.ClientV2] = None + self._x509: Optional[x509.Certificate] = None - self._domain = domain - self._email = email + self._domain: str = domain + self._email: str = email @property def path_account_key(self) -> Path: @@ -352,7 +352,7 @@ async def issue_certificate(self) -> None: # Update DNS try: - async with async_timeout.timeout(15): + async with async_timeout.timeout(30): resp = await cloud_api.async_remote_challenge_txt( self.cloud, challenge.validation ) diff --git a/hass_nabucasa/auth.py b/hass_nabucasa/auth.py index 21e6cde38..53eaeffe3 100644 --- a/hass_nabucasa/auth.py +++ b/hass_nabucasa/auth.py @@ -197,7 +197,7 @@ def _cognito(self, **kwargs): user_pool_id=self.cloud.user_pool_id, client_id=self.cloud.cognito_client_id, user_pool_region=self.cloud.region, - **kwargs + **kwargs, ) cognito.client = boto3.client( "cognito-idp", diff --git a/hass_nabucasa/remote.py b/hass_nabucasa/remote.py index 1c710d608..eb7cf6ff1 100644 --- a/hass_nabucasa/remote.py +++ b/hass_nabucasa/remote.py @@ -104,8 +104,8 @@ async def _create_context(self) -> ssl.SSLContext: await self.cloud.run_executor( context.load_cert_chain, - str(self._acme.path_fullchain), - str(self._acme.path_private_key), + self._acme.path_fullchain, + self._acme.path_private_key, ) return context @@ -121,7 +121,7 @@ async def load_backend(self) -> None: # Load instance data from backend try: - async with async_timeout.timeout(15): + async with async_timeout.timeout(30): resp = await cloud_api.async_remote_register(self.cloud) assert resp.status == 200 except (asyncio.TimeoutError, AssertionError): @@ -228,7 +228,7 @@ async def _refresh_snitun_token(self) -> None: # Generate session token aes_key, aes_iv = generate_aes_keyset() try: - async with async_timeout.timeout(15): + async with async_timeout.timeout(30): resp = await cloud_api.async_remote_token(self.cloud, aes_key, aes_iv) assert resp.status == 200 except (asyncio.TimeoutError, AssertionError): diff --git a/requirements_tests.txt b/requirements_tests.txt index c5321f2a2..831bd093f 100644 --- a/requirements_tests.txt +++ b/requirements_tests.txt @@ -2,4 +2,5 @@ flake8==3.7.7 pylint==2.3.1 pytest==4.3.0 pytest-timeout==1.3.3 -pytest-aiohttp==0.3.0 \ No newline at end of file +pytest-aiohttp==0.3.0 +black==19.3b0 diff --git a/setup.py b/setup.py index bf98a8a05..c72c4c92e 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -VERSION = "0.16" +VERSION = "0.17" setup( name="hass-nabucasa", diff --git a/tests/utils/aiohttp.py b/tests/utils/aiohttp.py index e4a36b284..a333397fb 100644 --- a/tests/utils/aiohttp.py +++ b/tests/utils/aiohttp.py @@ -47,7 +47,7 @@ def request( params=None, headers={}, exc=None, - cookies=None + cookies=None, ): """Mock a request.""" if json is not None: @@ -117,7 +117,7 @@ async def match_request( headers=None, allow_redirects=None, timeout=None, - json=None + json=None, ): """Match a request against pre-registered requests.""" data = data or json