-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from NabuCasa/dev
Release 0.18
- Loading branch information
Showing
26 changed files
with
897 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
FROM python:3.7 | ||
|
||
WORKDIR /workspace | ||
WORKDIR /workspaces | ||
|
||
# Install Python dependencies from requirements.txt if it exists | ||
COPY requirements_tests.txt /workspace/ | ||
RUN pip3 install -r requirements_tests.txt | ||
COPY requirements_tests.txt . | ||
RUN pip3 install -r requirements_tests.txt tox \ | ||
&& rm -f requirements_tests.txt | ||
|
||
# Set the default shell to bash instead of sh | ||
ENV SHELL /bin/bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# https://dev.azure.com/NabuCasa/OpenSource | ||
|
||
trigger: | ||
branches: | ||
include: | ||
- dev | ||
pr: | ||
- dev | ||
|
||
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# https://dev.azure.com/NabuCasa/OpenSource | ||
|
||
trigger: | ||
tags: | ||
include: | ||
- '*' | ||
pr: none | ||
|
||
variables: | ||
- group: twine | ||
|
||
|
||
jobs: | ||
|
||
- job: 'Release' | ||
pool: | ||
vmImage: 'ubuntu-latest' | ||
steps: | ||
- task: UsePythonVersion@0 | ||
displayName: 'Use Python 3.7' | ||
inputs: | ||
versionSpec: '3.7' | ||
- script: | | ||
setup_version="$(python setup.py -V)" | ||
branch_version="$(Build.SourceBranchName)" | ||
if [ "${setup_version}" != "${branch_version}" ]; then | ||
echo "Version of tag ${branch_version} don't match with ${setup_version}!" | ||
exit 1 | ||
fi | ||
displayName: 'Check version of branch/tag' | ||
- script: pip install twine wheel | ||
displayName: 'Install twine' | ||
- script: python setup.py sdist bdist_wheel | ||
displayName: 'Build package' | ||
- script: | | ||
export TWINE_USERNAME="$(twineUser)" | ||
export TWINE_PASSWORD="$(twinePassword)" | ||
twine upload dist/* | ||
displayName: 'Upload pypi' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""Module to handle Google Report State.""" | ||
import asyncio | ||
from asyncio.queues import Queue | ||
import logging | ||
|
||
from . import iot_base | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
MAX_PENDING = 100 | ||
|
||
|
||
class GoogleReportState(iot_base.BaseIoT): | ||
"""Report states to Google. | ||
Uses a queue to send messages. | ||
""" | ||
|
||
def __init__(self, cloud): | ||
"""Initialize Google Report State.""" | ||
super().__init__(cloud) | ||
self._connect_lock = asyncio.Lock() | ||
self._to_send = Queue(100) | ||
self._message_sender_task = None | ||
self.register_on_connect(self._async_on_connect) | ||
self.register_on_disconnect(self._async_on_disconnect) | ||
|
||
@property | ||
def package_name(self) -> str: | ||
"""Return the package name for logging.""" | ||
return __name__ | ||
|
||
@property | ||
def ws_server_url(self) -> str: | ||
"""Server to connect to.""" | ||
return self.cloud.google_actions_report_state_url | ||
|
||
async def async_send_message(self, msg): | ||
"""Send a message.""" | ||
# Since connect is async, guard against send_message called twice in parallel. | ||
async with self._connect_lock: | ||
if self.state == iot_base.STATE_DISCONNECTED: | ||
self.cloud.run_task(self.connect()) | ||
# Give connect time to start up and change state. | ||
await asyncio.sleep(0) | ||
|
||
if self._to_send.full(): | ||
self._to_send.get_nowait() | ||
self._to_send.put_nowait(msg) | ||
|
||
def async_handle_message(self, msg): | ||
"""Handle a message.""" | ||
self._logger.warning("Got unhandled message: %s", msg) | ||
|
||
async def _async_on_connect(self): | ||
"""On Connect handler.""" | ||
self._message_sender_task = self.cloud.run_task(self._async_message_sender()) | ||
|
||
async def _async_on_disconnect(self): | ||
"""On disconnect handler.""" | ||
self._message_sender_task.cancel() | ||
self._message_sender_task = None | ||
|
||
async def _async_message_sender(self): | ||
"""Start sending messages.""" | ||
try: | ||
while True: | ||
await self.async_send_json_message(await self._to_send.get()) | ||
except asyncio.CancelledError: | ||
pass |
Oops, something went wrong.