Skip to content

Commit

Permalink
Merge pull request #61 from NabuCasa/dev
Browse files Browse the repository at this point in the history
Release 0.13
  • Loading branch information
pvizeli authored May 30, 2019
2 parents 0fb99f6 + 2e4d851 commit efd9909
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
template: |
## What’s Changed
$CHANGES
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
[![Build Status](https://dev.azure.com/NabuCasa/OpenSource/_apis/build/status/hass-nabucasa?branchName=dev)](https://dev.azure.com/NabuCasa/OpenSource/_build/latest?definitionId=2&branchName=dev)

## Cloud integration in Home Assistant
77 changes: 77 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# https://dev.azure.com/NabuCasa/OpenSource

trigger:
branches:
include:
- master
- dev
tags:
include:
- '*'
exclude:
- untagged*
pr:
- dev

variables:
- group: twine


jobs:

- job: "Tox"
pool:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python36:
python.version: '3.6'
Python37:
python.version: '3.7'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(python.version)'
inputs:
versionSpec: '$(python.version)'
- script: pip install tox
displayName: 'Install Tox'
- script: tox
displayName: 'Run Tox'


- job: 'Black'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.7'
inputs:
versionSpec: '3.7'
- script: pip install black
displayName: 'Install black'
- script: black --check hass_nabucasa tests
displayName: 'Run Black'


- job: 'Release'
condition: and(startsWith(variables['Build.SourceBranch'], 'refs/tags'), succeeded('Tox'), succeeded('Black'))
dependsOn:
- 'Tox'
- 'Black'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.7'
inputs:
versionSpec: '3.7'
- script: pip install twine
displayName: 'Install twine'
- script: python setup.py sdist
displayName: 'Build package'
- script: |
export TWINE_USERNAME="$(twineUser)"
export TWINE_PASSWORD="$(twinePassword)"
twine upload dist/*
displayName: 'Upload pypi'
5 changes: 5 additions & 0 deletions hass_nabucasa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ async def logout(self) -> None:

def write_user_info(self) -> None:
"""Write user info to a file."""
base_path = self.path()
if not base_path.exists():
base_path.mkdir()

self.user_info_path.write_text(
json.dumps(
{
Expand All @@ -162,6 +166,7 @@ def write_user_info(self) -> None:
indent=4,
)
)
self.user_info_path.chmod(0o600)

async def start(self):
"""Start the cloud component."""
Expand Down
16 changes: 11 additions & 5 deletions hass_nabucasa/acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ def _create_client(self) -> None:
network = client.ClientNetwork(
self._account_jwk, account=regr, user_agent=USER_AGENT
)
directory = messages.Directory.from_json(network.get(self._acme_server).json())
directory = messages.Directory.from_json(
network.get(self._acme_server).json()
)
self._acme_client = client.ClientV2(directory, net=network)
except errors.Error as err:
_LOGGER.error("Can't connect to ACME server: %s", err)
Expand All @@ -202,7 +204,9 @@ def _create_client(self) -> None:
# Create a new registration
try:
network = client.ClientNetwork(self._account_jwk, user_agent=USER_AGENT)
directory = messages.Directory.from_json(network.get(self._acme_server).json())
directory = messages.Directory.from_json(
network.get(self._acme_server).json()
)
self._acme_client = client.ClientV2(directory, net=network)
except errors.Error as err:
_LOGGER.error("Can't connect to ACME server: %s", err)
Expand Down Expand Up @@ -287,8 +291,7 @@ async def load_certificate(self) -> None:
def _load_cert():
"""Load certificate in a thread."""
return x509.load_pem_x509_certificate(
self.path_fullchain.read_bytes(),
default_backend()
self.path_fullchain.read_bytes(), default_backend()
)

self._x509 = await self.cloud.run_executor(_load_cert)
Expand Down Expand Up @@ -363,7 +366,9 @@ async def issue_certificate(self) -> None:
await self.cloud.run_executor(self._finish_challenge, challenge)
await self.load_certificate()
finally:
await cloud_api.async_remote_challenge_cleanup(self.cloud, challenge.validation)
await cloud_api.async_remote_challenge_cleanup(
self.cloud, challenge.validation
)

async def reset_acme(self) -> None:
"""Revoke and deactivate acme certificate/account."""
Expand All @@ -381,6 +386,7 @@ async def reset_acme(self) -> None:

async def hardening_files(self) -> None:
"""Control permission on files."""

def _control():
# Set file permission to 0600
if self.path_account_key.exists():
Expand Down
2 changes: 1 addition & 1 deletion hass_nabucasa/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ async def _certificate_handler(self) -> None:
continue

# Renew certificate?
if self._acme.expire_date > utils.utcnow() + timedelta(days=14):
if self._acme.expire_date > utils.utcnow() + timedelta(days=25):
continue

# Renew certificate
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = "0.12"
VERSION = "0.13"

setup(
name="hass-nabucasa",
Expand Down
1 change: 0 additions & 1 deletion tests/test_iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,3 @@ async def test_send_message_answer(loop, cloud_mock_iot):
cloud_iot._response_handler[uuid].set_result({"response": True})
response = await send_task
assert response == {"response": True}

18 changes: 9 additions & 9 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def test_load_backend_exists_cert(
"token": "test-token",
"server": "rest-remote.nabu.casa",
"valid": valid.timestamp(),
"throttling": 400
"throttling": 400,
},
)

Expand Down Expand Up @@ -127,7 +127,7 @@ async def test_load_backend_not_exists_cert(
"token": "test-token",
"server": "rest-remote.nabu.casa",
"valid": valid.timestamp(),
"throttling": 400
"throttling": 400,
},
)

Expand Down Expand Up @@ -180,7 +180,7 @@ async def test_load_and_unload_backend(
"token": "test-token",
"server": "rest-remote.nabu.casa",
"valid": valid.timestamp(),
"throttling": 400
"throttling": 400,
},
)

Expand Down Expand Up @@ -239,7 +239,7 @@ async def test_load_backend_exists_wrong_cert(
"token": "test-token",
"server": "rest-remote.nabu.casa",
"valid": valid.timestamp(),
"throttling": 400
"throttling": 400,
},
)

Expand Down Expand Up @@ -289,7 +289,7 @@ async def test_call_disconnect(
"token": "test-token",
"server": "rest-remote.nabu.casa",
"valid": valid.timestamp(),
"throttling": 400
"throttling": 400,
},
)

Expand Down Expand Up @@ -326,7 +326,7 @@ async def test_load_backend_no_autostart(
"token": "test-token",
"server": "rest-remote.nabu.casa",
"valid": valid.timestamp(),
"throttling": 400
"throttling": 400,
},
)

Expand Down Expand Up @@ -373,7 +373,7 @@ async def test_get_certificate_details(
"token": "test-token",
"server": "rest-remote.nabu.casa",
"valid": valid.timestamp(),
"throttling": 400
"throttling": 400,
},
)

Expand Down Expand Up @@ -414,7 +414,7 @@ async def test_certificate_task_no_backend(
"token": "test-token",
"server": "rest-remote.nabu.casa",
"valid": valid.timestamp(),
"throttling": 400
"throttling": 400,
},
)

Expand Down Expand Up @@ -451,7 +451,7 @@ async def test_certificate_task_renew_cert(
"token": "test-token",
"server": "rest-remote.nabu.casa",
"valid": valid.timestamp(),
"throttling": 400
"throttling": 400,
},
)

Expand Down

0 comments on commit efd9909

Please sign in to comment.