mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
* It's HUB ID * Rename file * Working with official doc * Some progress * AttachedIO msg * device action impl * some better device alert impl * restructuring * Some port commands handled * Some command feedback waiting * Some more request-reply things * Some more request-reply things * Reworked msg classes * Getting back to UTs * Getting back to UTs * Facing sync lock problems * Facing sync lock problems * Testing it * Covering more with tests * handle actions * Hub class is almost covered * done coverage for Hub * done coverage for MoveHub * Button is tested * remove debug server from examples * Current and voltage tested * color sensor basic test * cover tilt sensor * motor sensor tested * constant motor * motor is tested * hold_speed impl for motor * motor commands recorded * some cleanup * some cleanup * some cleanup * debug * debug * FIX a bug * acc/dec profiles figured out * UT motor ops * UT motor ops * Get rid of weird piggyback * fix UT * Fix encoding? * fix test mb * More robust * Checked demo works * cosmetics * cosmetics * Maybe better test * fetching and decoding some device caps * describing devs * describing devs works * Applying modes we've learned * Simple and extensible dev attach * Reworking peripherals based on modes * Applying modes we've learned * implemented getting sensor data * fixed port subscribe * Added led out cmds on vision sensor * Worked on color-distance sensor * Introduce some locking for consistency * Improved it all * Travis flags * improve * improve * improve docs
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import dbus
|
|
import sys
|
|
import unittest
|
|
|
|
from gatt import DeviceManager
|
|
|
|
from pylgbst.comms.cgatt import CustomDevice, GattConnection
|
|
from tests import log, str2hex
|
|
|
|
|
|
class MockBus(object):
|
|
def __init__(self, *args, **kwargs):
|
|
# super(MockBus, self).__init__(*args, **kwargs)
|
|
pass
|
|
|
|
def get_object(self, bus_name, object_path, introspect=True, follow_name_owner_changes=False, **kwargs):
|
|
return None
|
|
|
|
|
|
dbus.SystemBus = lambda: MockBus()
|
|
|
|
|
|
class DeviceManagerMock(DeviceManager, object):
|
|
def update_devices(self):
|
|
pass
|
|
|
|
|
|
class TestGatt(unittest.TestCase):
|
|
def test_one(self):
|
|
log.debug("")
|
|
manager = DeviceManagerMock("hci0")
|
|
obj = CustomDevice("AA", manager)
|
|
|
|
def callback(handle, value):
|
|
log.debug("%s: %s", type(value), str2hex(value))
|
|
if sys.version_info[0] == 2:
|
|
self.assertEquals("0f0004020126000000001000000010", str2hex(value))
|
|
|
|
obj.set_notific_handler(callback)
|
|
arr = "dbus.Array([dbus.Byte(15), dbus.Byte(0), dbus.Byte(4), dbus.Byte(2), dbus.Byte(1), dbus.Byte(38), " \
|
|
"dbus.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(16), dbus.Byte(0), dbus.Byte(0), " \
|
|
"dbus.Byte(0), dbus.Byte(16)], signature=dbus.Signature('y'), variant_level=1)"
|
|
obj.characteristic_value_updated(None, arr if sys.version_info[0] == 2 else bytes(arr, 'ascii'))
|
|
|
|
def test_conn(self):
|
|
try:
|
|
obj = GattConnection()
|
|
obj.connect()
|
|
except AttributeError:
|
|
pass
|