Skip to content

Commit

Permalink
make mac address case insensitive (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrils authored Jul 24, 2023
1 parent 623e8da commit 993c50c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
9 changes: 2 additions & 7 deletions renogybt/BLE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand All @@ -26,28 +26,23 @@ 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
if (wait <= 0):
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):
super(). __init__(mac_address=mac_address, manager=manager)
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()
Expand Down
2 changes: 1 addition & 1 deletion renogybt/BTOneClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions renogybt/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 993c50c

Please sign in to comment.