mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
Cosmetics around bleak
This commit is contained in:
parent
afdbe4b2e0
commit
c73311528d
@ -251,7 +251,7 @@ if __name__ == '__main__':
|
|||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
parameters = {}
|
parameters = {}
|
||||||
try:
|
try:
|
||||||
connection = connection_from_url(options.connection)
|
connection = connection_from_url(options.connection) # get_connection_bleak(hub_name=MoveHub.DEFAULT_NAME)
|
||||||
parameters['connection'] = connection
|
parameters['connection'] = connection
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
parser.error(err.args[0])
|
parser.error(err.args[0])
|
||||||
|
@ -139,17 +139,21 @@ class BleakConnection(Connection):
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
log.info("Discovering devices... Press green button on Hub")
|
log.info("Discovering devices... Press green button on Hub")
|
||||||
devices = await discover(timeout=10)
|
for i in range(0, 30):
|
||||||
log.debug("Devices: %s", devices)
|
devices = await discover(timeout=1)
|
||||||
|
log.debug("Devices: %s", devices)
|
||||||
|
for dev in devices:
|
||||||
|
log.debug(dev)
|
||||||
|
address = dev.address
|
||||||
|
name = dev.name
|
||||||
|
if self._is_device_matched(address, name, hub_mac, hub_name):
|
||||||
|
log.info('Device matched: %r', dev)
|
||||||
|
self._device = dev
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
for dev in devices:
|
break
|
||||||
log.debug(dev)
|
|
||||||
address = dev.address
|
|
||||||
name = dev.name
|
|
||||||
if self._is_device_matched(address, name, hub_mac, hub_name):
|
|
||||||
log.info('Device matched: %r', dev)
|
|
||||||
self._device = dev
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
raise ConnectionError('Device not found.')
|
raise ConnectionError('Device not found.')
|
||||||
|
|
||||||
|
@ -184,6 +184,8 @@ class MoveHub(Hub):
|
|||||||
:type motor_external: EncodedMotor
|
:type motor_external: EncodedMotor
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
DEFAULT_NAME = "LEGO Move Hub"
|
||||||
|
|
||||||
# PORTS
|
# PORTS
|
||||||
PORT_A = 0x00
|
PORT_A = 0x00
|
||||||
PORT_B = 0x01
|
PORT_B = 0x01
|
||||||
@ -198,7 +200,7 @@ class MoveHub(Hub):
|
|||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
def __init__(self, connection=None):
|
def __init__(self, connection=None):
|
||||||
if connection is None:
|
if connection is None:
|
||||||
connection = get_connection_auto(hub_name="LEGO Move Hub")
|
connection = get_connection_auto(hub_name=self.DEFAULT_NAME)
|
||||||
|
|
||||||
super(MoveHub, self).__init__(connection)
|
super(MoveHub, self).__init__(connection)
|
||||||
self.info = {}
|
self.info = {}
|
||||||
@ -279,7 +281,9 @@ class MoveHub(Hub):
|
|||||||
|
|
||||||
|
|
||||||
class TrainHub(Hub):
|
class TrainHub(Hub):
|
||||||
|
DEFAULT_NAME = 'TrainHub'
|
||||||
|
|
||||||
def __init__(self, connection=None):
|
def __init__(self, connection=None):
|
||||||
if connection is None:
|
if connection is None:
|
||||||
connection = get_connection_auto(hub_name='TrainHub')
|
connection = get_connection_auto(hub_name=self.DEFAULT_NAME)
|
||||||
super(TrainHub, self).__init__(connection)
|
super(TrainHub, self).__init__(connection)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user