diff --git a/renogybt/BLE.py b/renogybt/BLE.py index e756c96..54811ae 100644 --- a/renogybt/BLE.py +++ b/renogybt/BLE.py @@ -16,7 +16,7 @@ def __init__(self, adapter_name, mac_address, alias): logging.info("Adapter status - Powered: {}".format(self.is_adapter_powered)) def discover(self): - discovering = True; wait = DISCOVERY_TIMEOUT; self.device_found = False; + discovering = True; wait = DISCOVERY_TIMEOUT; self.device_found = False; mac_address = self.mac_address.upper(); self.update_devices() logging.info("Starting discovery...") @@ -26,7 +26,7 @@ def discover(self): time.sleep(1) logging.info("Devices found: %s", len(self.devices())) for dev in self.devices(): - if (dev.mac_address == self.mac_address or dev.alias() == self.device_alias) and discovering: + if dev.mac_address != None and (dev.mac_address.upper() == mac_address or dev.alias() == self.device_alias) and discovering: logging.info("Found matching device %s => [%s]", dev.alias(), dev.mac_address) discovering = False; self.device_found = True wait = wait -1 @@ -34,9 +34,6 @@ def discover(self): discovering = False self.stop_discovery() - def device_discovered(self, device): - logging.info("[{}] Discovered, alias = {}".format(device.mac_address, device.alias())) - class Device(gatt.Device): def __init__(self, mac_address, manager, on_resolved, on_data, on_connect_fail, notify_uuid, write_uuid): @@ -44,10 +41,8 @@ def __init__(self, mac_address, manager, on_resolved, on_data, on_connect_fail, self.data_callback = on_data self.resolved_callback = on_resolved self.connect_fail_callback = on_connect_fail - self.manager = manager self.notify_char_uuid = notify_uuid self.write_char_uuid = write_uuid - self.mac_address = mac_address def connect_succeeded(self): super().connect_succeeded() diff --git a/renogybt/BTOneClient.py b/renogybt/BTOneClient.py index 9efbc6d..fab15a0 100644 --- a/renogybt/BTOneClient.py +++ b/renogybt/BTOneClient.py @@ -87,8 +87,8 @@ def __on_data_received(self, value): if self.on_data_callback is not None: self.on_data_callback(self, self.data) elif operation == 6: - self.data = parse_set_load_response(value) logging.info("on_data_received: response for write operation") + self.data = parse_set_load_response(value) if self.on_data_callback is not None: self.on_data_callback(self, self.data) else: diff --git a/renogybt/Utils.py b/renogybt/Utils.py index ce5746c..1f388c9 100644 --- a/renogybt/Utils.py +++ b/renogybt/Utils.py @@ -28,16 +28,13 @@ def bytes_to_int(bs, offset, length): if len(bs) < (offset + length): return ret if length > 0: - # offset = 11, length = 2 => 11 - 12 byteorder='big' start = offset end = offset + length else: - # offset = 11, length = -2 => 10 - 11 byteorder='little' start = offset + length + 1 end = offset + 1 - # Easier to read than the bitshifting below return int.from_bytes(bs[start:end], byteorder=byteorder)