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

Commit

Permalink
0.26.0
Browse files Browse the repository at this point in the history
0.26.0
  • Loading branch information
doudz authored Jan 22, 2019
2 parents 00e8458 + 2da3a9d commit 3febb54
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 136 deletions.
34 changes: 34 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ def test_reporting_request(self):
b'0212340103030000000000020020000000010e100000000020000100010e10000000'
)

def test_raw_aps_data(self):
r = self.zigate.raw_aps_data_request('1234', 1, 1, 0x0104, 0x0006, b'payload', 3)
self.assertEqual(r.sequence, 1)

def test_assumed_state(self):
device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'})
device.set_attribute(3, 6, {'attribute': 0, 'rssi': 255, 'data': False})
Expand Down Expand Up @@ -323,6 +327,36 @@ def test_assumed_state(self):
# {'attribute': 0, 'data': False, 'name': 'onoff', 'value': False, 'type': bool,
# 'state': 'assumed'})

def test_handle_response_8085(self):
device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'},
self.zigate)
self.zigate._devices['1234'] = device
msg_data = b'\x01\x01\x00\x08\x02\x124\x01'
r = responses.R8085(msg_data, 255)
self.zigate.interpret_response(r)
self.assertEqual(device.get_property_value('remote_level_button'),
'down_hold')

def test_handle_response_8095(self):
device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'},
self.zigate)
self.zigate._devices['1234'] = device
msg_data = b'\x01\x01\x00\x06\x02\x124\x02'
r = responses.R8095(msg_data, 255)
self.zigate.interpret_response(r)
self.assertEqual(device.get_property_value('remote_onoff_button'),
'middle_click')

def test_handle_response_80A7(self):
device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'},
self.zigate)
self.zigate._devices['1234'] = device
msg_data = b'\x01\x01\x00\x05\x02\x124\x07\x01'
r = responses.R80A7(msg_data, 255)
self.zigate.interpret_response(r)
self.assertEqual(device.get_property_value('remote_scene_button'),
'left_click')


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_template(self):
)

def test_inverse_bool(self):
device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'})
device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}, self.zigate)
device.set_attribute(1, 0, {'attribute': 5, 'rssi': 255, 'data': 'lumi.sensor_switch.aq2'})
device.set_attribute(1, 6, {'attribute': 0, 'rssi': 255, 'data': True})
self.assertTrue(device.get_property_value('onoff'))
Expand Down
14 changes: 14 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ def test_packet(self):
self.assertEqual(b'\x01123\x03', connection.received.get())
self.assertEqual(b'\x01456\x03', connection.received.get())

def test_initial_failed(self):
success = False
try:
transport.ThreadSerialConnection(None, '/dummyport')
except transport.ZIGATE_CANNOT_CONNECT:
success = True
self.assertTrue(success)
success = False
try:
transport.ThreadSocketConnection(None, 'fake.address')
except transport.ZIGATE_CANNOT_CONNECT:
success = True
self.assertTrue(success)


if __name__ == '__main__':
unittest.main()
57 changes: 57 additions & 0 deletions zigate/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,24 @@ class C0001(Cluster):
# E_CLD_PWRCFG_BATTERY_SIZE_UNKNOWN = 0xff,


@register_cluster
class C0005(Cluster):
cluster_id = 0x0005
type = 'General: Scenes'
attributes_def = {0xfff0: {'name': 'remote_scene_button', 'value': 'value',
'type': str, 'expire': 2}
}


@register_cluster
class C0006(Cluster):
cluster_id = 0x0006
type = 'General: On/Off'
attributes_def = {0x0000: {'name': 'onoff', 'value': 'value', 'type': bool},
0x8000: {'name': 'multiclick', 'value': 'value', 'type': int,
'expire': 2},
0xfff0: {'name': 'remote_onoff_button', 'value': 'value',
'type': str, 'expire': 2}
}


Expand All @@ -219,6 +230,8 @@ class C0008(Cluster):
cluster_id = 0x0008
type = 'General: Level control'
attributes_def = {0x0000: {'name': 'current_level', 'value': 'int(value*100/254)', 'type': int},
0xfff0: {'name': 'remote_level_button', 'value': 'value',
'type': str, 'expire': 2}
}


Expand Down Expand Up @@ -299,6 +312,21 @@ def __init__(self, endpoint=None):
}


class C000f(Cluster):
cluster_id = 0x000f
type = 'Binary Input (Basic)'
attributes_def = {0x0004: {'name': 'active_text', 'value': 'value'},
0x001c: {'name': 'description', 'value': 'value'},
0x002e: {'name': 'inactive_text', 'value': 'value'},
0x0051: {'name': 'out_of_service', 'value': 'value', 'type': bool},
0x0054: {'name': 'polarity', 'value': 'value'},
0x0055: {'name': 'present_value', 'type': bool},
0x0067: {'name': 'reliability', 'value': 'value'},
0x006f: {'name': 'status_flags', 'value': 'value'},
0x0100: {'name': 'application_type', 'value': 'value'},
}


def vibration_decode(value):
'''
Special decoder for XIAOMI Vibration sensor
Expand Down Expand Up @@ -328,6 +356,35 @@ class C0101(Cluster):
}


@register_cluster
class C0102(Cluster):
cluster_id = 0x0102
type = 'Window covering'
attributes_def = {0x0000: {'name': 'window_covering_type', 'value': 'value'},
0x0001: {'name': 'physical_close_limit_lift_cm', 'value': 'value'},
0x0002: {'name': 'physical_close_limit_tilt_ddegree', 'value': 'value'},
0x0003: {'name': 'current_position_lift_cm', 'value': 'value'},
0x0004: {'name': 'current_position_tilt_ddegree', 'value': 'value'},
0x0005: {'name': 'num_of_actuation_lift', 'value': 'value'},
0x0007: {'name': 'config_status', 'value': 'value'},
0x0008: {'name': 'current_position_lift_percentage', 'value': 'value'},
0x0009: {'name': 'current_position_tilt_percentage', 'value': 'value'},
}


@register_cluster
class C0201(Cluster):
cluster_id = 0x0201
type = 'Thermostat'
attributes_def = {0x0000: {'name': 'local_temperature', 'value': 'value/100.',
'unit': '°C', 'type': float},
0x0008: {'name': 'heating_demand', 'value': 'value'},
0x0012: {'name': 'heating_setpoint', 'value': 'value/100.',
'unit': '°C', 'type': float},
0x001C: {'name': 'system_mode', 'value': 'value'},
}


@register_cluster
class C0300(Cluster):
cluster_id = 0x0300
Expand Down
8 changes: 8 additions & 0 deletions zigate/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
TOGGLE = 2
LOCK = 0
UNLOCK = 1
OPEN = 0x00
CLOSE = 0x01
STOP = 0x02
LIFT_VALUE = 0x04
LIFT_PERCENT = 0x05
TILT_VALUE = 0x07
TILT_PERCENT = 0x08

STATUS_CODES = {0: 'Success', 1: 'Invalid parameters',
2: 'Unhandled command', 3: 'Command failed',
Expand All @@ -43,6 +50,7 @@
ACTIONS_TEMPERATURE = 'temperature'
ACTIONS_HUE = 'hue'
ACTIONS_LOCK = 'lock'
ACTIONS_COVER = 'cover'

DATA_TYPE = {0x00: None,
0x10: '?', # bool
Expand Down
Loading

0 comments on commit 3febb54

Please sign in to comment.