Skip to content

Commit

Permalink
Release 0.7.0
Browse files Browse the repository at this point in the history
Release 0.7.0
  • Loading branch information
doudz authored Nov 10, 2020
2 parents 3a48b14 + 77b145d commit 7ce14e2
Show file tree
Hide file tree
Showing 20 changed files with 1,169 additions and 146 deletions.
22 changes: 22 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name-template: '$NEXT_PATCH_VERSION Release.'
tag-template: '$NEXT_PATCH_VERSION'
categories:
- title: 'Breaking changes'
labels:
- 'breaking'
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
template: |
## Changes
$CHANGES
16 changes: 16 additions & 0 deletions .github/workflows/release-management.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Release Management

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master

jobs:
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 }}
45 changes: 45 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build & Tests

on:
push:
branches: [ master, dev ]
pull_request:
branches: [ master, dev ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-asyncio mock
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -e "."
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=16 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
markdownlint:

runs-on: ubuntu-latest
name: Test Markdown
steps:
- name: Run mdl
uses: actionshub/markdownlint@master
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

86 changes: 66 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# zigpy-zigate

[![Build Status](https://travis-ci.com/zigpy/zigpy-zigate.svg?branch=master)](https://travis-ci.com/zigpy/zigpy-zigate)
![Build & Tests](https://github.com/zigpy/zigpy-zigate/workflows/Build%20&%20Tests/badge.svg?branch=master)
[![Coverage](https://coveralls.io/repos/github/zigpy/zigpy-zigate/badge.svg?branch=master)](https://coveralls.io/github/zigpy/zigpy-zigate?branch=master)

**WARNING: EXPERIMENTAL! This project is under development as WIP (work in progress). Developer’s work provided “AS IS”.**
Expand All @@ -14,29 +14,57 @@ ZiGate is a open source ZigBee adapter hardware that was initially launched on K
- https://www.zigate.fr
- https://www.kickstarter.com/projects/1361563794/zigate-universal-zigbee-gateway-for-smarthome

## Compatible hardware
## Hardware and firmware compatibility
The ZiGate USB adapter communicates via a PL-2303HX USB to Serial Bridge Controller module by Prolific.
There's also a Wi-Fi adapter to communicate with ZiGate over network.

Note! ZiGate open source ZigBee adapter hardware requires ZiGate firmware 3.1a or later to work with this zigpy-zigate module.
Note! ZiGate open source ZigBee USB and GPIO adapter hardware requires ZiGate 3.1a firmware or later to work with this zigpy-zigate module, however ZiGate 3.1d firmware or later is recommended as it contains a specific bug-fix related to zigpy.

### Known working Zigbee radio modules
- [ZiGate USB-TTL](https://zigate.fr/produit/zigate-ttl/)
- [ZiGate USB-DIN](https://zigate.fr/produit/zigate-usb-din/)
- [PiZiGate (ZiGate module for Raspberry Pi GPIO)](https://zigate.fr/produit/pizigate-v1-0/)
- [ZiGate Pack WiFi](https://zigate.fr/produit/zigate-pack-wifi-v1-3/)

### Experimental Zigbee radio modules
- [ZiGate Pack WiFi](https://zigate.fr/produit/zigate-pack-wifi-v1-3/) (work in progress)
- [Open Lumi Gateway](https://github.com/openlumi) - [DIY ZiGate WiFi bridge hacked from an Xiaomi Lumi Gateway with modded OpenWRT firmware](https://github.com/zigpy/zigpy-zigate/issues/59)

## Port configuration

- To configure __usb__ ZiGate port, just specify the port, example : `/dev/ttyUSB0`
- Alternatively you could set port to `auto` to enable automatic usb port discovery
- To configure __pizigate__ port, prefix the port with `pizigate:`, example : `pizigate:/dev/serial0`
- To configure __wifi__ ZiGate, specify IP address and port, example : `socket://192.168.1.10:9999`
- To configure __usb__ ZiGate (USB TTL or DIN) port, just specify the port, example : `/dev/ttyUSB0`
- Alternatively you could manually set port to `auto` to enable automatic usb port discovery
- To configure __pizigate__ port, specify the port, example : `/dev/serial0` or `/dev/ttyAMA0`
- To configure __wifi__ ZiGate, manually specify IP address and port, example : `socket://192.168.1.10:9999`

Note! Requires ZiGate firmware 3.1a and later
- https://zigate.fr/tag/firmware/
__pizigate__ does require some additional adjustements on Raspberry Pi 3/Zero, and 4:
- [Raspberry Pi 3 and Raspberry Pi Zero configuration adjustements](https://zigate.fr/documentation/compatibilite-raspberry-pi-3-et-zero-w/)
- [Raspberry Pi 4 configuration adjustements](https://zigate.fr/documentation/compatibilite-raspberry-pi-4-b/)

## Flasher (ZiGate Firmware Tool)

zigpy-zigate has an integrated Python "flasher" tool to flash firmware updates on your ZiGate (NXP Jennic JN5168).

Thanks to Sander Hoentjen (tjikkun) zigpy-zigate now has an integrated firmware flasher tool!
- [tjikkun original zigate-flasher repo](https://github.com/tjikkun/zigate-flasher)

### Flasher Usage

```bash
usage: python3 -m zigpy_zigate.tools.flasher [-h] -p {/dev/ttyUSB0} [-w WRITE] [-s SAVE] [-u] [-d] [--gpio] [--din]

optional arguments:
-h, --help show this help message and exit
-p {/dev/ttyUSB0}, --serialport {/dev/ttyUSB0}
Serial port, e.g. /dev/ttyUSB0
-w WRITE, --write WRITE
Firmware bin to flash onto the chip
-s SAVE, --save SAVE File to save the currently loaded firmware to
-u, --upgrade Download and flash the lastest available firmware
-d, --debug Set log level to DEBUG
--gpio Configure GPIO for PiZiGate flash
--din Configure USB for ZiGate DIN flash

```

## Testing new releases

Expand Down Expand Up @@ -71,6 +99,9 @@ Tagged versions are also released via PyPI
Documents that layout the serial protocol used for ZiGate serial interface communication can be found here:
- https://github.com/fairecasoimeme/ZiGate/tree/master/Protocol
- https://github.com/doudz/zigate
- https://github.com/Neonox31/zigate
- https://github.com/nouknouk/node-zigate
## How to contribute
Expand All @@ -82,17 +113,32 @@ Some developers might also be interested in receiving donations in the form of h
## Related projects
### Zigpy
[Zigpy](https://github.com/zigpy/zigpy)** is **[Zigbee protocol stack](https://en.wikipedia.org/wiki/Zigbee)** integration project to implement the **[Zigbee Home Automation](https://www.zigbee.org/)** standard as a Python 3 library. Zigbee Home Automation integration with zigpy allows you to connect one of many off-the-shelf Zigbee adapters using one of the available Zigbee radio library modules compatible with zigpy to control Zigbee based devices. There is currently support for controlling Zigbee device types such as binary sensors (e.g., motion and door sensors), sensors (e.g., temperature sensors), lightbulbs, switches, and fans. A working implementation of zigbe exist in **[Home Assistant](https://www.home-assistant.io)** (Python based open source home automation software) as part of its **[ZHA component](https://www.home-assistant.io/components/zha/)**
#### Zigpy
[Zigpy](https://github.com/zigpy/zigpy) is [Zigbee protocol stack](https://en.wikipedia.org/wiki/Zigbee) integration project to implement the [Zigbee Home Automation](https://www.zigbee.org/) standard as a Python 3 library. Zigbee Home Automation integration with zigpy allows you to connect one of many off-the-shelf Zigbee adapters using one of the available Zigbee radio library modules compatible with zigpy to control Zigbee based devices. There is currently support for controlling Zigbee device types such as binary sensors (e.g., motion and door sensors), sensors (e.g., temperature sensors), lightbulbs, switches, and fans. A working implementation of zigbe exist in [Home Assistant](https://www.home-assistant.io) (Python based open source home automation software) as part of its [ZHA component](https://www.home-assistant.io/components/zha/)
#### ZHA Device Handlers
ZHA deviation handling in Home Assistant relies on the third-party [ZHA Device Handlers](https://github.com/zigpy/zha-device-handlers) project. Zigbee devices that deviate from or do not fully conform to the standard specifications set by the [Zigbee Alliance](https://www.zigbee.org) may require the development of custom [ZHA Device Handlers](https://github.com/zigpy/zha-device-handlers) (ZHA custom quirks handler implementation) to for all their functions to work properly with the ZHA component in Home Assistant. These ZHA Device Handlers for Home Assistant can thus be used to parse custom messages to and from non-compliant Zigbee devices. The custom quirks implementations for zigpy implemented as ZHA Device Handlers for Home Assistant are a similar concept to that of [Hub-connected Device Handlers for the SmartThings platform](https://docs.smartthings.com/en/latest/device-type-developers-guide/) as well as that of [zigbee-herdsman converters as used by Zigbee2mqtt](https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html), meaning they are each virtual representations of a physical device that expose additional functionality that is not provided out-of-the-box by the existing integration between these platforms.
#### ZHA integration component for Home Assistant
[ZHA integration component for Home Assistant](https://www.home-assistant.io/integrations/zha/) is a reference implementation of the zigpy library as integrated into the core of [Home Assistant](https://www.home-assistant.io) (a Python based open source home automation software). There are also other GUI and non-GUI projects for Home Assistant's ZHA components which builds on or depends on its features and functions to enhance or improve its user-experience, some of those are listed and linked below.
#### ZHA Custom Radios
[zha-custom-radios](https://github.com/zha-ng/zha-custom-radios) adds support for custom radio modules for zigpy to [[Home Assistant's ZHA (Zigbee Home Automation) integration component]](https://www.home-assistant.io/integrations/zha/). This custom component for Home Assistant allows users to test out new modules for zigpy in Home Assistant's ZHA integration component before they are integrated into zigpy ZHA and also helps developers new zigpy radio modules without having to modify the Home Assistant's source code.
#### ZHA Custom
[zha_custom](https://github.com/Adminiuga/zha_custom) is a custom component package for Home Assistant (with its ZHA component for zigpy integration) that acts as zigpy commands service wrapper, when installed it allows you to enter custom commands via to zigy to example change advanced configuration and settings that are not available in the UI.
#### ZHA Map
[zha-map](https://github.com/zha-ng/zha-map) for Home Assistant's ZHA component can build a Zigbee network topology map.
### ZHA Device Handlers
ZHA deviation handling in Home Assistant relies on on the third-party [ZHA Device Handlers](https://github.com/dmulcahey/zha-device-handlers) project. Zigbee devices that deviate from or do not fully conform to the standard specifications set by the [Zigbee Alliance](https://www.zigbee.org) may require the development of custom [ZHA Device Handlers](https://github.com/dmulcahey/zha-device-handlers) (ZHA custom quirks handler implementation) to for all their functions to work properly with the ZHA component in Home Assistant. These ZHA Device Handlers for Home Assistant can thus be used to parse custom messages to and from non-compliant Zigbee devices. The custom quirks implementations for zigpy implemented as ZHA Device Handlers for Home Assistant are a similar concept to that of [Hub-connected Device Handlers for the SmartThings Classics platform](https://docs.smartthings.com/en/latest/device-type-developers-guide/) as well as that of [Zigbee-Shepherd Converters as used by Zigbee2mqtt](https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html), meaning they are each virtual representations of a physical device that expose additional functionality that is not provided out-of-the-box by the existing integration between these platforms.
#### ZHA Network Visualization Card
[zha-network-visualization-card](https://github.com/dmulcahey/zha-network-visualization-card) is a custom Lovelace element for Home Assistant which visualize the Zigbee network for the ZHA component.
### ZHA Map
Home Assistant can build ZHA network topology map using the [zha-map](https://github.com/zha-ng/zha-map) project.
#### ZHA Network Card
[zha-network-card](https://github.com/dmulcahey/zha-network-card) is a custom Lovelace card for Home Assistant that displays ZHA component Zigbee network and device information in Home Assistant
### zha-network-visualization-card
[zha-network-visualization-card](https://github.com/dmulcahey/zha-network-visualization-card) is a custom Lovelace element for visualizing the ZHA Zigbee network in Home Assistant.
#### Zigzag
[Zigzag](https://github.com/Samantha-uk/zigzag) is an custom card/panel for [Home Assistant](https://www.home-assistant.io/) that displays a graphical layout of Zigbee devices and the connections between them. Zigzag can be installed as a panel or a custom card and relies on the data provided by the [zha-map](https://github.com/zha-ng/zha-map) integration commponent.
### ZHA Network Card
[zha-network-card](https://github.com/dmulcahey/zha-network-card) is a custom Lovelace card that displays ZHA network and device information in Home Assistant
#### ZHA Device Exporter
[zha-device-exporter](https://github.com/dmulcahey/zha-device-exporter) is a custom component for Home Assistant to allow the ZHA component to export lists of Zigbee devices.
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def is_raspberry_pi(raise_on_errors=False):

requires = [
'pyserial-asyncio',
'pyusb',
'zigpy>=0.22.2',
]

Expand All @@ -66,13 +67,15 @@ def is_raspberry_pi(raise_on_errors=False):
description="A library which communicates with ZiGate radios for zigpy",
long_description=long_description,
long_description_content_type="text/markdown",
url="http://github.com/doudz/zigpy-zigate",
url="http://github.com/zigpy/zigpy-zigate",
author="Sébastien RAMAGE",
author_email="[email protected]",
license="GPL-3.0",
packages=find_packages(exclude=['*.tests']),
install_requires=requires,
tests_require=[
'pytest',
'pytest-asyncio',
'mock'
],
)
Empty file added tests/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions tests/async_mock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Mock utilities that are async aware."""
import sys

if sys.version_info[:2] < (3, 8):
from mock import * # noqa
else:
from unittest.mock import * # noqa
33 changes: 22 additions & 11 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import serial
import serial_asyncio
from asynctest import CoroutineMock, mock
from .async_mock import AsyncMock, MagicMock, patch, sentinel

import zigpy_zigate.config as config
import zigpy_zigate.uart
Expand All @@ -15,13 +15,13 @@
@pytest.fixture
def api():
api = zigate_api.ZiGate(DEVICE_CONFIG)
api._uart = mock.MagicMock()
api._uart = MagicMock()
return api


def test_set_application(api):
api.set_application(mock.sentinel.app)
assert api._app == mock.sentinel.app
api.set_application(sentinel.app)
assert api._app == sentinel.app


@pytest.mark.asyncio
Expand All @@ -39,26 +39,26 @@ async def mock_conn(loop, protocol_factory, **kwargs):


def test_close(api):
api._uart.close = mock.MagicMock()
api._uart.close = MagicMock()
uart = api._uart
api.close()
assert uart.close.call_count == 1
assert api._uart is None


@pytest.mark.asyncio
@mock.patch.object(zigpy_zigate.uart, "connect")
@patch.object(zigpy_zigate.uart, "connect")
async def test_api_new(conn_mck):
"""Test new class method."""
api = await zigate_api.ZiGate.new(DEVICE_CONFIG, mock.sentinel.application)
api = await zigate_api.ZiGate.new(DEVICE_CONFIG, sentinel.application)
assert isinstance(api, zigate_api.ZiGate)
assert conn_mck.call_count == 1
assert conn_mck.await_count == 1


@pytest.mark.asyncio
@mock.patch.object(zigate_api.ZiGate, "set_raw_mode", new_callable=CoroutineMock)
@mock.patch.object(zigpy_zigate.uart, "connect")
@patch.object(zigate_api.ZiGate, "set_raw_mode", new_callable=AsyncMock)
@patch.object(zigpy_zigate.uart, "connect")
async def test_probe_success(mock_connect, mock_raw_mode):
"""Test device probing."""

Expand All @@ -72,8 +72,8 @@ async def test_probe_success(mock_connect, mock_raw_mode):


@pytest.mark.asyncio
@mock.patch.object(zigate_api.ZiGate, "set_raw_mode", side_effect=asyncio.TimeoutError)
@mock.patch.object(zigpy_zigate.uart, "connect")
@patch.object(zigate_api.ZiGate, "set_raw_mode", side_effect=asyncio.TimeoutError)
@patch.object(zigpy_zigate.uart, "connect")
@pytest.mark.parametrize(
"exception",
(asyncio.TimeoutError, serial.SerialException, zigate_api.NoResponseError),
Expand All @@ -91,3 +91,14 @@ async def test_probe_fail(mock_connect, mock_raw_mode, exception):
assert mock_connect.call_args[0][0] == DEVICE_CONFIG
assert mock_raw_mode.call_count == 1
assert mock_connect.return_value.close.call_count == 1


@pytest.mark.asyncio
@patch.object(zigate_api.ZiGate, "_command", side_effect=asyncio.TimeoutError)
async def test_api_command(mock_command, api):
"""Test command method."""
try:
await api.set_raw_mode()
except zigate_api.NoResponseError:
pass
assert mock_command.call_count == 2
11 changes: 9 additions & 2 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
config.CONF_DATABASE: None,
}
)

FAKE_FIRMWARE_VERSION = '3.1z'

@pytest.fixture
def app():
return zigpy_zigate.zigbee.application.ControllerApplication(APP_CONFIG)
a = zigpy_zigate.zigbee.application.ControllerApplication(APP_CONFIG)
a.version = FAKE_FIRMWARE_VERSION
return a


def test_zigpy_ieee(app):
Expand All @@ -30,3 +32,8 @@ def test_zigpy_ieee(app):

dst_addr = app.get_dst_address(cluster)
assert dst_addr.serialize() == b"\x03" + data[::-1] + b"\x01"


def test_model_detection(app):
device = zigpy_zigate.zigbee.application.ZiGateDevice(app, 0, 0)
assert device.model == 'ZiGate USB-TTL {}'.format(FAKE_FIRMWARE_VERSION)
28 changes: 0 additions & 28 deletions tox.ini

This file was deleted.

Loading

0 comments on commit 7ce14e2

Please sign in to comment.