mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
Merge branch 'master' of github.com:undera/pylgbst into bleak-troubleshooting
This commit is contained in:
commit
92c6e3f26e
@ -251,7 +251,7 @@ if __name__ == '__main__':
|
||||
options = parser.parse_args()
|
||||
parameters = {}
|
||||
try:
|
||||
connection = connection_from_url(options.connection)
|
||||
connection = connection_from_url(options.connection) # get_connection_bleak(hub_name=MoveHub.DEFAULT_NAME)
|
||||
parameters['connection'] = connection
|
||||
except ValueError as err:
|
||||
parser.error(err.args[0])
|
||||
|
@ -224,17 +224,21 @@ class BleakConnection(Connection):
|
||||
:return: None
|
||||
"""
|
||||
log.info("Discovering devices... Press green button on Hub")
|
||||
devices = await discover(timeout=10)
|
||||
log.debug("Devices: %s", devices)
|
||||
for i in range(0, 30):
|
||||
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:
|
||||
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
|
||||
break
|
||||
else:
|
||||
raise ConnectionError('Device not found.')
|
||||
|
||||
|
@ -182,6 +182,8 @@ class MoveHub(Hub):
|
||||
:type motor_external: EncodedMotor
|
||||
"""
|
||||
|
||||
DEFAULT_NAME = "LEGO Move Hub"
|
||||
|
||||
# PORTS
|
||||
PORT_A = 0x00
|
||||
PORT_B = 0x01
|
||||
@ -195,6 +197,12 @@ class MoveHub(Hub):
|
||||
|
||||
# noinspection PyTypeChecker
|
||||
def __init__(self, connection=None):
|
||||
if connection is None:
|
||||
connection = get_connection_auto(hub_name=self.DEFAULT_NAME)
|
||||
|
||||
super(MoveHub, self).__init__(connection)
|
||||
self.info = {}
|
||||
|
||||
# shorthand fields
|
||||
self.led = None
|
||||
self.current = None
|
||||
@ -278,7 +286,9 @@ class MoveHub(Hub):
|
||||
|
||||
|
||||
class TrainHub(Hub):
|
||||
DEFAULT_NAME = 'TrainHub'
|
||||
|
||||
def __init__(self, connection=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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user