Skip to content

Commit

Permalink
Release v0.7.1
Browse files Browse the repository at this point in the history
*Fix pizigate connection
  • Loading branch information
doudz committed Nov 13, 2020
2 parents 7ce14e2 + 648b180 commit 135f264
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ jobs:
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_TOKEN }}
update_draft_release:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 0 additions & 16 deletions .github/workflows/release-management.yml

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def is_raspberry_pi(raise_on_errors=False):
author="Sébastien RAMAGE",
author_email="sebatien.ramage@gmail.com",
license="GPL-3.0",
packages=find_packages(exclude=['*.tests']),
packages=find_packages(exclude=['tests']),
install_requires=requires,
tests_require=[
'pytest',
Expand Down
1 change: 1 addition & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
FAKE_FIRMWARE_VERSION = '3.1z'


@pytest.fixture
def app():
a = zigpy_zigate.zigbee.application.ControllerApplication(APP_CONFIG)
Expand Down
57 changes: 57 additions & 0 deletions tests/test_uart.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from unittest import mock
from .async_mock import MagicMock

import pytest
import serial_asyncio
import serial.tools.list_ports

import zigpy_zigate.config
from zigpy_zigate import uart
from zigpy_zigate import common

DEVICE_CONFIG = zigpy_zigate.config.SCHEMA_DEVICE(
{zigpy_zigate.config.CONF_DEVICE_PATH: "/dev/null"}
Expand Down Expand Up @@ -112,3 +115,57 @@ def test_checksum(gw):
checksum = 0xaa
r = gw._checksum(b'\x80\x10', 5, 0xff, data)
assert r == checksum


@pytest.mark.parametrize(
"port",
('/dev/ttyAMA0', '/dev/serial0', 'pizigate:/dev/ttyAMA0'),
)
def test_is_pizigate(port):
r = common.is_pizigate(port)
assert r is True


def test_is_not_pizigate():
port = '/dev/ttyUSB1'
r = common.is_pizigate(port)
assert r is False


def test_is_zigatedin(monkeypatch):
def mock_grep(*args, **kwargs):
device = MagicMock()
device.description = 'ZiGate'
device.manufacturer = 'FTDI'
return iter([device])
monkeypatch.setattr(serial.tools.list_ports, 'grep', mock_grep)
port = '/dev/ttyUSB1'
r = common.is_zigate_din(port)
assert r is True


@pytest.mark.parametrize(
"port",
('/dev/ttyUSB1', '/dev/ttyAMA0', '/dev/serial0'),
)
def test_is_not_zigatedin(port, monkeypatch):
def mock_grep(*args, **kwargs):
device = MagicMock()
device.description = 'Other'
device.manufacturer = 'FTDI'
return iter([device])
monkeypatch.setattr(serial.tools.list_ports, 'grep', mock_grep)
r = common.is_zigate_din(port)
assert r is False


def test_is_zigate_wifi():
port = 'socket://192.168.1.10:9999'
r = common.is_zigate_wifi(port)
assert r is True


def test_is_not_zigate_wifi():
port = '/dev/ttyUSB1'
r = common.is_zigate_wifi(port)
assert r is False
2 changes: 1 addition & 1 deletion zigpy_zigate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MAJOR_VERSION = 0
MINOR_VERSION = 7
PATCH_VERSION = '0'
PATCH_VERSION = '1'
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
5 changes: 5 additions & 0 deletions zigpy_zigate/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import os.path
import serial.tools.list_ports
import serial
import usb
Expand Down Expand Up @@ -28,11 +29,15 @@ def discover_port():
def is_pizigate(port):
""" detect pizigate """
# Suppose pizigate on /dev/ttyAMAx or /dev/serialx
if port.startswith('pizigate:'):
return True
port = os.path.realpath(port)
return re.match(r"/dev/(tty(S|AMA)|serial)\d+", port) is not None


def is_zigate_din(port):
""" detect zigate din """
port = os.path.realpath(port)
if re.match(r"/dev/ttyUSB\d+", port):
try:
device = next(serial.tools.list_ports.grep(port))
Expand Down
2 changes: 0 additions & 2 deletions zigpy_zigate/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import binascii
import logging
import struct
import os.path
from typing import Any, Dict

import serial # noqa
Expand Down Expand Up @@ -140,7 +139,6 @@ async def connect(device_config: Dict[str, Any], api, loop=None):
lambda: protocol,
host, port)
else:
port = os.path.realpath(port)
if c.is_pizigate(port):
LOGGER.debug('PiZiGate detected')
await c.set_pizigate_running_mode()
Expand Down
3 changes: 2 additions & 1 deletion zigpy_zigate/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ async def startup(self, auto_form=False):

async def shutdown(self):
"""Shutdown application."""
self._api.close()
if self._api:
self._api.close()

async def form_network(self, channel=None, pan_id=None, extended_pan_id=None):
await self._api.set_channel(channel)
Expand Down

0 comments on commit 135f264

Please sign in to comment.