From a22d5d143a279df9f02d9f9dbd7166aa81d3d6fa Mon Sep 17 00:00:00 2001 From: SchumyHao Date: Sat, 17 Mar 2018 11:27:17 +0800 Subject: [PATCH] fix lumi cube's rotation issue Signed-off-by: SchumyHao --- pyzigate/attributes_helpers.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/pyzigate/attributes_helpers.py b/pyzigate/attributes_helpers.py index f5dfc65..94094a5 100644 --- a/pyzigate/attributes_helpers.py +++ b/pyzigate/attributes_helpers.py @@ -1,5 +1,6 @@ #! /usr/bin/python3 import logging +from struct import unpack from binascii import hexlify, unhexlify from collections import OrderedDict from time import strftime @@ -73,16 +74,38 @@ def interpret_attributes(self, msg_data): ZGT_LOG.info(' * Pressed: {} times'.format(clicks)) # Movement elif cluster_id == b'000c': # Unknown cluster id - ZGT_LOG.info(' * Rotation horizontal') + if attribute_id == b'ff05': + if hexlify(attribute_data) == b'01f4': + ZGT_LOG.info(' * Rotation horizontal') + elif attribute_id == b'0055': + ZGT_LOG.info(' * Rotated: %s°' % (unpack('!f', attribute_data)[0])) elif cluster_id == b'0012': # Unknown cluster id if attribute_id == b'0055': if hexlify(attribute_data) == b'0000': ZGT_LOG.info(' * Shaking') - elif hexlify(attribute_data) == b'0055': - ZGT_LOG.info(' * Rotating vertical') - ZGT_LOG.info(' * Rotated: {}°'. format(int(hexlify(attribute_data), 16))) - elif hexlify(attribute_data) == b'0103': + elif hexlify(attribute_data) in [b'0100', b'0101', b'0102', b'0103', b'0104', b'0105']: ZGT_LOG.info(' * Sliding') + else: + ZGT_LOG.info(' * Rotating vertical') + if hexlify(attribute_data) in [b'0050', b'0042', + b'0044', b'0060', + b'0045', b'0068', + b'0041', b'0048', + + b'0063', b'005c', + b'0059', b'004b', + b'005d', b'006b', + b'005a', b'0053', + + b'004a', b'0051', + b'0054', b'0062', + b'0069', b'004d', + b'006c', b'0065',]: + ZGT_LOG.info(' * Rotated: 90°') + if hexlify(attribute_data) in [b'0080', b'0083', + b'0081', b'0084', + b'0085', b'0082',]: + ZGT_LOG.info(' * Rotated: 180°') # Illuminance Measurement elif cluster_id == b'0400': # MeasuredValue