Skip to content

Commit 135f264

Browse files
committed
Release v0.7.1
*Fix pizigate connection
2 parents 7ce14e2 + 648b180 commit 135f264

File tree

9 files changed

+74
-21
lines changed

9 files changed

+74
-21
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ jobs:
2424
uses: pypa/gh-action-pypi-publish@master
2525
with:
2626
password: ${{ secrets.PYPI_TOKEN }}
27+
update_draft_release:
28+
runs-on: ubuntu-latest
29+
steps:
30+
# Drafts your next Release notes as Pull Requests are merged into "master"
31+
- uses: release-drafter/release-drafter@v5
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release-management.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def is_raspberry_pi(raise_on_errors=False):
7171
author="Sébastien RAMAGE",
7272
author_email="[email protected]",
7373
license="GPL-3.0",
74-
packages=find_packages(exclude=['*.tests']),
74+
packages=find_packages(exclude=['tests']),
7575
install_requires=requires,
7676
tests_require=[
7777
'pytest',

tests/test_application.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
FAKE_FIRMWARE_VERSION = '3.1z'
1717

18+
1819
@pytest.fixture
1920
def app():
2021
a = zigpy_zigate.zigbee.application.ControllerApplication(APP_CONFIG)

tests/test_uart.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from unittest import mock
2+
from .async_mock import MagicMock
23

34
import pytest
45
import serial_asyncio
6+
import serial.tools.list_ports
57

68
import zigpy_zigate.config
79
from zigpy_zigate import uart
10+
from zigpy_zigate import common
811

912
DEVICE_CONFIG = zigpy_zigate.config.SCHEMA_DEVICE(
1013
{zigpy_zigate.config.CONF_DEVICE_PATH: "/dev/null"}
@@ -112,3 +115,57 @@ def test_checksum(gw):
112115
checksum = 0xaa
113116
r = gw._checksum(b'\x80\x10', 5, 0xff, data)
114117
assert r == checksum
118+
119+
120+
@pytest.mark.parametrize(
121+
"port",
122+
('/dev/ttyAMA0', '/dev/serial0', 'pizigate:/dev/ttyAMA0'),
123+
)
124+
def test_is_pizigate(port):
125+
r = common.is_pizigate(port)
126+
assert r is True
127+
128+
129+
def test_is_not_pizigate():
130+
port = '/dev/ttyUSB1'
131+
r = common.is_pizigate(port)
132+
assert r is False
133+
134+
135+
def test_is_zigatedin(monkeypatch):
136+
def mock_grep(*args, **kwargs):
137+
device = MagicMock()
138+
device.description = 'ZiGate'
139+
device.manufacturer = 'FTDI'
140+
return iter([device])
141+
monkeypatch.setattr(serial.tools.list_ports, 'grep', mock_grep)
142+
port = '/dev/ttyUSB1'
143+
r = common.is_zigate_din(port)
144+
assert r is True
145+
146+
147+
@pytest.mark.parametrize(
148+
"port",
149+
('/dev/ttyUSB1', '/dev/ttyAMA0', '/dev/serial0'),
150+
)
151+
def test_is_not_zigatedin(port, monkeypatch):
152+
def mock_grep(*args, **kwargs):
153+
device = MagicMock()
154+
device.description = 'Other'
155+
device.manufacturer = 'FTDI'
156+
return iter([device])
157+
monkeypatch.setattr(serial.tools.list_ports, 'grep', mock_grep)
158+
r = common.is_zigate_din(port)
159+
assert r is False
160+
161+
162+
def test_is_zigate_wifi():
163+
port = 'socket://192.168.1.10:9999'
164+
r = common.is_zigate_wifi(port)
165+
assert r is True
166+
167+
168+
def test_is_not_zigate_wifi():
169+
port = '/dev/ttyUSB1'
170+
r = common.is_zigate_wifi(port)
171+
assert r is False

zigpy_zigate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
MAJOR_VERSION = 0
22
MINOR_VERSION = 7
3-
PATCH_VERSION = '0'
3+
PATCH_VERSION = '1'
44
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
55
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)

zigpy_zigate/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import os.path
23
import serial.tools.list_ports
34
import serial
45
import usb
@@ -28,11 +29,15 @@ def discover_port():
2829
def is_pizigate(port):
2930
""" detect pizigate """
3031
# Suppose pizigate on /dev/ttyAMAx or /dev/serialx
32+
if port.startswith('pizigate:'):
33+
return True
34+
port = os.path.realpath(port)
3135
return re.match(r"/dev/(tty(S|AMA)|serial)\d+", port) is not None
3236

3337

3438
def is_zigate_din(port):
3539
""" detect zigate din """
40+
port = os.path.realpath(port)
3641
if re.match(r"/dev/ttyUSB\d+", port):
3742
try:
3843
device = next(serial.tools.list_ports.grep(port))

zigpy_zigate/uart.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import binascii
33
import logging
44
import struct
5-
import os.path
65
from typing import Any, Dict
76

87
import serial # noqa
@@ -140,7 +139,6 @@ async def connect(device_config: Dict[str, Any], api, loop=None):
140139
lambda: protocol,
141140
host, port)
142141
else:
143-
port = os.path.realpath(port)
144142
if c.is_pizigate(port):
145143
LOGGER.debug('PiZiGate detected')
146144
await c.set_pizigate_running_mode()

zigpy_zigate/zigbee/application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ async def startup(self, auto_form=False):
6060

6161
async def shutdown(self):
6262
"""Shutdown application."""
63-
self._api.close()
63+
if self._api:
64+
self._api.close()
6465

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

0 commit comments

Comments
 (0)