Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mikettle/mikettle.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ def __init__(self, mac, product_id, cache_timeout=600, retries=3, iface=None, to
token = MiKettle.generateRandomToken()
self._token = token

self._p = None
self._authenticated = False

def connect(self):
self._p = Peripheral(deviceAddr=self._mac, iface=self._iface)
self._p.setDelegate(self)
if self._p is None:
self._p = Peripheral(deviceAddr=self._mac, iface=self._iface)
self._p.setDelegate(self)

def name(self):
"""Return the name of the device."""
Expand Down Expand Up @@ -175,6 +179,8 @@ def bytes_to_int(bytes):
return result

def auth(self):
if self._authenticated:
return
auth_service = self._p.getServiceByUUID(_UUID_SERVICE_KETTLE)
auth_descriptors = auth_service.getDescriptors()

Expand All @@ -191,6 +197,7 @@ def auth(self):
self._p.writeCharacteristic(_HANDLE_AUTH, MiKettle.cipher(self._token, _KEY2), "true")

self._p.readCharacteristic(_HANDLE_VERSION)
self._authenticated = True

def subscribeToData(self):
controlService = self._p.getServiceByUUID(_UUID_SERVICE_KETTLE_DATA)
Expand Down