From a91eb91ac64e47c11a9ae98c9a4c4d989a54f3ef Mon Sep 17 00:00:00 2001 From: sqozz Date: Wed, 13 Nov 2019 18:48:46 +0100 Subject: [PATCH] Instantiate Peripheral on class initialization --- sem6000.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sem6000.py b/sem6000.py index 63c5283..df36d5f 100644 --- a/sem6000.py +++ b/sem6000.py @@ -20,6 +20,7 @@ class SEMSocket(): def __init__(self, mac, auto_reconnect_timeout = None): self.mac_address = mac self.auto_reconnect_timeout = auto_reconnect_timeout + self._btle_device = btle.Peripheral(None ,addrType=btle.ADDR_TYPE_PUBLIC,iface=0) try: self.reconnect() except self.NotConnectedException: @@ -96,10 +97,7 @@ class SEMSocket(): def connect(self): self.disconnect() - if not self._btle_device: - self._btle_device = btle.Peripheral(self.mac_address,addrType=btle.ADDR_TYPE_PUBLIC,iface=0) - else: - self._btle_device.connect(self.mac_address) + self._btle_device.connect(self.mac_address) self._btle_handler = self.BTLEHandler(self) self._custom_service = self._btle_device.getServiceByUUID(0xfff0)