Skip to content

Commit 7b2e142

Browse files
committed
Updated Manager.exit_with_error and all calls, to write the error. 'Device <address> not found' will now cause the script to exit.
1 parent 7548912 commit 7b2e142

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

evseMQTT/ble_manager.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ async def scan(self):
3030
self.connectiondata[address] = device
3131
return self.available_devices
3232
except BleakError as e:
33-
self.logger.error(f"BleakError during scanning: {e}")
34-
await self.manager.exit_with_error()
33+
await self.manager.exit_with_error(f"BleakError during scanning: {e}")
3534

3635
async def connect_device(self, address):
3736
if address in self.available_devices:
@@ -47,16 +46,14 @@ async def connect_device(self, address):
4746
self._schedule_reconnect_check()
4847
return True
4948
except BleakError as e:
50-
self.logger.error(f"Attempt {attempt + 1} failed with BleakError: {e}")
51-
await self.manager.exit_with_error()
49+
await self.manager.exit_with_error(f"Attempt {attempt + 1} failed with BleakError: {e}")
5250
except Exception as e:
5351
self.logger.error(f"Attempt {attempt + 1} failed with error: {e}")
5452
await asyncio.sleep(2) # Wait a bit before retrying
55-
self.logger.error(f"Failed to connect to {address} after {self.max_retries} attempts")
56-
await self.manager.exit_with_error()
53+
await self.manager.exit_with_error(f"Failed to connect to {address} after {self.max_retries} attempts")
5754
return False
5855
else:
59-
self.logger.error(f"Device {address} not found")
56+
await self.manager.exit_with_error(f"Device {address} not found")
6057
return False
6158

6259
async def start_notifications(self, address, characteristic_uuid):

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ async def restart_run(self, address=None):
113113

114114
await self.run(address)
115115

116-
async def exit_with_error(self):
117-
self.logger.error("Exiting due to repeated connection failures.")
116+
async def exit_with_error(self, error):
117+
self.logger.error(f"Error encountered:\n{error}")
118118
# Perform necessary cleanup actions
119119
if self.mqtt_client:
120120
self.mqtt_client.publish_availability(self.device.info['serial'], "offline")

0 commit comments

Comments
 (0)