From 0d9a76fb8fd86d6a1c4ffea4e1527f766d9505c2 Mon Sep 17 00:00:00 2001 From: seidler2547 Date: Wed, 7 Jun 2023 20:01:20 +0000 Subject: [PATCH] remove scan for devices the scan for devices and check if the BMS to test is present doesn't add value if the device is not within range (or the MAC is wrong), then the subsequent start_scraping call will either fail or fail to produce usable data --- etc/dbus-serialbattery/bms/jkbms_ble.py | 53 +------------------------ 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/etc/dbus-serialbattery/bms/jkbms_ble.py b/etc/dbus-serialbattery/bms/jkbms_ble.py index 276103c4..0056c902 100644 --- a/etc/dbus-serialbattery/bms/jkbms_ble.py +++ b/etc/dbus-serialbattery/bms/jkbms_ble.py @@ -28,58 +28,9 @@ def test_connection(self): # The result or call should be unique to this BMS. Battery name or version, etc. # Return True if success, False for failure - # check if device with given mac is found, otherwise abort - logger.info("Test of Jkbms_Ble at " + self.jk.address) - try: - loop = asyncio.get_event_loop() - t = loop.create_task(BleakScanner.discover()) - devices = loop.run_until_complete(t) - except BleakError as err: - logger.error(str(err)) - return False - except Exception as err: - logger.error(f"Unexpected {err=}, {type(err)=}") - return False - - found = False - for d in devices: - if d.address == self.jk.address: - found = True - if not found: - logger.error("No Jkbms_Ble found at " + self.jk.address) - return False - - """ - # before indipended service, has to be checked - - logger.info("test of jkbmsble") - tries = 0 - while True: - try: - loop = asyncio.get_event_loop() - t = loop.create_task( - BleakScanner.find_device_by_address(self.jk.address) - ) - device = loop.run_until_complete(t) - - if device is None: - logger.info("jkbmsble not found") - if tries > 2: - return False - else: - # device found, exit loop and continue test - break - except BleakError as e: - if tries > 2: - return False - # recover from error if tries left - logger.error(str(e)) - self.reset_bluetooth() - tries += 1 - """ - - # device was found, presumeably a jkbms so start scraping + + # start scraping self.jk.start_scraping() tries = 1