Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #57 from doudz/dev
Browse files Browse the repository at this point in the history
Release 0.24.0
  • Loading branch information
doudz authored Dec 20, 2018
2 parents d3280c5 + fe84eb0 commit 0e200fb
Show file tree
Hide file tree
Showing 10 changed files with 493 additions and 69 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![PyPI version](https://badge.fury.io/py/zigate.svg)](https://pypi.python.org/pypi/zigate)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/doudz/zigate.svg)](http://isitmaintained.com/project/doudz/zigate "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/doudz/zigate.svg)](http://isitmaintained.com/project/doudz/zigate "Percentage of issues still open")
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/sebramage)

Python library for [ZiGate](http://zigate.fr/).
This library manage communication between python and zigate key, both USB and WiFi key are supported.
Expand Down Expand Up @@ -93,8 +94,24 @@ True
# call action on devices
z.action_onoff('b8ce', 1, zigate.ON)

or from devices
# or from devices
z.devices[1].action_onoff(zigate.ON)

# OTA process
# Load image and send headers to ZiGate
z.ota_load_image('path/to/ota/image_file.ota')
# Tell client that image is available
z.ota_image_notify('addr')
# It will take client usually couple seconds to query headers
# from server. Upgrade process start automatically if correct
# headers are loaded to ZiGate. If you have logging level debug
# enabled you will get automatically progress updates.
# Manually check ota status - logging level INFO
z.get_ota_status()
# Whole upgrade process time depends on device and ota image size
# Upgrading ikea bulb took ~15 minutes
# Upgrading ikea remote took ~45 minutes

```

### Callback
Expand Down
75 changes: 75 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'''
ZiGate Transport Tests
-------------------------
'''

import unittest
from zigate import transport


class TestTransport(unittest.TestCase):
def test_packet(self):
connection = transport.BaseTransport()
data = b'\x01123\x03'
connection.read_data(data)
self.assertEqual(1, connection.received.qsize())
self.assertEqual(b'\x01123\x03', connection.received.get())

data = b'\x01123'
connection.read_data(data)
self.assertEqual(0, connection.received.qsize())

data = b'123\x03'
connection.read_data(data)
self.assertEqual(1, connection.received.qsize())
self.assertEqual(b'\x01123123\x03', connection.received.get())

data = b'123\x03'
connection.read_data(data)
self.assertEqual(0, connection.received.qsize())

data = b'123\x03\x01123\x03'
connection.read_data(data)
self.assertEqual(1, connection.received.qsize())
self.assertEqual(b'\x01123\x03', connection.received.get())

data = b'123\x01123\x03'
connection.read_data(data)
self.assertEqual(1, connection.received.qsize())
self.assertEqual(b'\x01123\x03', connection.received.get())

data = b'\x01123\x03123\x03\x01456\x03\x011'
connection.read_data(data)
self.assertEqual(2, connection.received.qsize())
self.assertEqual(b'\x01123\x03', connection.received.get())
self.assertEqual(b'\x01456\x03', connection.received.get())

data = b'456'
connection.read_data(data)
self.assertEqual(0, connection.received.qsize())

data = b'123\x03'
connection.read_data(data)
self.assertEqual(1, connection.received.qsize())
self.assertEqual(b'\x011456123\x03', connection.received.get())

data = b'\x01123\x01123\x01123\x03'
connection.read_data(data)
self.assertEqual(1, connection.received.qsize())
self.assertEqual(b'\x01123\x03', connection.received.get())

data = b'\x01123\x01123\x01123\x03\x01456\x03'
connection.read_data(data)
self.assertEqual(2, connection.received.qsize())
self.assertEqual(b'\x01123\x03', connection.received.get())
self.assertEqual(b'\x01456\x03', connection.received.get())

data = b'\x01123\x01123\x01\x01123\x03\x03\x01456\x03'
connection.read_data(data)
self.assertEqual(2, connection.received.qsize())
self.assertEqual(b'\x01123\x03', connection.received.get())
self.assertEqual(b'\x01456\x03', connection.received.get())


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ commands =
flake8 .

[flake8]
max-line-length = 160
max-line-length = 119
exclude = .tox,*.egg,build/*,docs/*,
select = E,W,F
18 changes: 15 additions & 3 deletions zigate/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def vibration_decode(value):
'''
if value == '' or value is None:
return value
events = {0x0001: 'take',
events = {0x0001: 'touched',
0x0002: 'tilt',
0x0003: 'drop',
}
Expand All @@ -315,8 +315,6 @@ class C0101(Cluster):
'expire': 2, 'expire_value': ''},
0x0503: {'name': 'rotation', 'value': 'value',
'expire': 2, 'expire_value': ''},
0x0505: {'name': 'unknown', 'value': 'value',
'expire': 2, 'expire_value': ''}
}


Expand Down Expand Up @@ -370,6 +368,13 @@ class C0402(Cluster):
'unit': '°C'},
}

def update(self, data):
added, attribute = Cluster.update(self, data)
# ignore erroneous value
if abs(attribute['value']) > 80:
return
return added, attribute


@register_cluster
class C0403(Cluster):
Expand All @@ -390,6 +395,13 @@ class C0405(Cluster):
'unit': '%'},
}

def update(self, data):
added, attribute = Cluster.update(self, data)
# ignore erroneous value
if abs(attribute['value']) > 100:
return
return added, attribute


@register_cluster
class C0406(Cluster):
Expand Down
16 changes: 16 additions & 0 deletions zigate/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,19 @@
ACTIONS_TEMPERATURE = 'temperature'
ACTIONS_HUE = 'hue'
ACTIONS_LOCK = 'lock'

DATA_TYPE = {0x00: None,
0x10: '?', # bool
0x18: 'b',
0x20: 'B',
0x21: 'H',
0x22: 'I',
0x23: 'I',
0x28: 'b',
0x29: 'h',
0x2a: 'i',
0x30: 'b',
0x39: 'f',
0x41: 's',
0x42: 's',
}
Loading

0 comments on commit 0e200fb

Please sign in to comment.