Skip to content

Commit

Permalink
Save MAC and port separately.
Browse files Browse the repository at this point in the history
Will be useful when we add support for Nearby.
  • Loading branch information
drinkcat committed Dec 13, 2023
1 parent 78cc353 commit 8437d49
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bluetooth_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def __init__(self, bluetooth_mac: str, bluetooth_port: Optional[Union[str, int]]
The actual query can be performed using the int() and str() method.
"""
self._bt_settings = bluetooth_mac, int(bluetooth_port or RFCOMMSocket.find_rfcomm_port(bluetooth_mac))
self._bluetooth_mac = bluetooth_mac
self._bluetooth_port = int(bluetooth_port or RFCOMMSocket.find_rfcomm_port(bluetooth_mac))

def __int__(self):
"""
Expand All @@ -108,8 +109,8 @@ def query(self) -> dict[str, int]:
"""
result: dict[str, int] = {}
sock = RFCOMMSocket()
logger.debug("Connecting to {}.{}".format(self._bt_settings[0], self._bt_settings[1]))
sock.connect(self._bt_settings)
logger.debug("Connecting to {}.{}".format(self._bluetooth_mac, self._bluetooth_port))
sock.connect((self._bluetooth_mac, self._bluetooth_port))
logger.debug("Connected")
# Iterate received packets until there is no more or a result was found
for line in sock:
Expand Down

0 comments on commit 8437d49

Please sign in to comment.