1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00

Fix tests

This commit is contained in:
Andrey Pohilko 2017-09-14 17:06:57 +03:00
parent eeb1891cb6
commit 753d22d13d
3 changed files with 10 additions and 11 deletions

View File

@ -36,7 +36,7 @@ else:
def str2hex(data):
return binascii.hexlify(data)
return binascii.hexlify(data).decode("utf8")
def hex2str(data):

View File

@ -66,7 +66,7 @@ MSG_PORT_CMD_ERROR = 0x05
MSG_SET_PORT_VAL = 0x81
MSG_PORT_STATUS = 0x82
MSG_SENSOR_SUBSCRIBE = 0x41
#MSG_SENSOR_UNSUBSCRIBE = 0x42
MSG_SENSOR_SOMETHING = 0x42
MSG_SENSOR_DATA = 0x45
MSG_SENSOR_SUBSCRIBE_ACK = 0x47

View File

@ -37,10 +37,6 @@ class Peripheral(object):
# FIXME: became obsolete
self._write_to_hub(MSG_SET_PORT_VAL, value)
def _subscribe_on_port(self, params):
# FIXME: became obsolete
self._write_to_hub(MSG_SENSOR_SUBSCRIBE, params)
def started(self):
self.working = True
@ -126,22 +122,25 @@ class EncodedMotor(Peripheral):
class TiltSensor(Peripheral):
TRAILER = b'\x01\x00\x00\x00'
TRAILER = b'\x00\x00\x00'
def __init__(self, parent, port):
super(TiltSensor, self).__init__(parent, port)
self.mode = None
def subscribe(self, callback, mode=TILT_SENSOR_MODE_BASIC):
# TODO: check input for valid mode
def subscribe(self, callback, mode=TILT_SENSOR_MODE_BASIC, threshold=1):
self.mode = mode
self._subscribe_on_port(int2byte(self.mode) + self.TRAILER + int2byte(1))
params = int2byte(self.mode)
params += int2byte(threshold)
params += self.TRAILER
params += int2byte(1) # enable
self._write_to_hub(MSG_SENSOR_SUBSCRIBE, params + self.TRAILER)
self._subscribers.add(callback)
def unsubscribe(self, callback):
self._subscribers.remove(callback)
if not self._subscribers:
self._subscribe_on_port(int2byte(self.mode) + self.TRAILER + int2byte(0))
self._write_to_hub(MSG_SENSOR_SUBSCRIBE, int2byte(self.mode) + self.TRAILER + int2byte(0))
def handle_notification(self, data):
if self.mode == TILT_SENSOR_MODE_BASIC: