Improve adherence to python coding standards and clear up IDE static analysis warnings

This commit is contained in:
Ian Renton
2026-02-27 19:17:04 +00:00
parent 6b18ec6f88
commit 6982354364
53 changed files with 633 additions and 626 deletions

View File

@@ -15,25 +15,25 @@ class WebsocketSpotProvider(SpotProvider):
def __init__(self, provider_config, url):
super().__init__(provider_config)
self.url = url
self.ws = None
self.thread = None
self.stopped = False
self.last_event_id = None
self._url = url
self._ws = None
self._thread = None
self._stopped = False
self._last_event_id = None
def start(self):
logging.info("Set up websocket connection to " + self.name + " spot API.")
self.stopped = False
self.thread = Thread(target=self.run)
self.thread.daemon = True
self.thread.start()
self._stopped = False
self._thread = Thread(target=self._run)
self._thread.daemon = True
self._thread.start()
def stop(self):
self.stopped = True
if self.ws:
self.ws.close()
if self.thread:
self.thread.join()
self._stopped = True
if self._ws:
self._ws.close()
if self._thread:
self._thread.join()
def _on_open(self):
self.status = "Waiting for Data"
@@ -41,25 +41,25 @@ class WebsocketSpotProvider(SpotProvider):
def _on_error(self):
self.status = "Connecting"
def run(self):
while not self.stopped:
def _run(self):
while not self._stopped:
try:
logging.debug("Connecting to " + self.name + " spot API...")
self.status = "Connecting"
self.ws = create_connection(self.url, header=HTTP_HEADERS)
self._ws = create_connection(self._url, header=HTTP_HEADERS)
self.status = "Connected"
data = self.ws.recv()
data = self._ws.recv()
if data:
try:
new_spot = self.ws_message_to_spot(data)
new_spot = self._ws_message_to_spot(data)
if new_spot:
self.submit(new_spot)
self._submit(new_spot)
self.status = "OK"
self.last_update_time = datetime.now(pytz.UTC)
logging.debug("Received data from " + self.name + " spot API.")
except Exception as e:
except Exception:
logging.exception(
"Exception processing message from Websocket Spot Provider (" + self.name + ")")
@@ -70,7 +70,7 @@ class WebsocketSpotProvider(SpotProvider):
self.status = "Disconnected"
sleep(5) # Wait before trying to reconnect
def ws_message_to_spot(self, bytes):
def _ws_message_to_spot(self, b):
"""Convert a WS message received from the API into a spot. The exact message data (in bytes) is provided here so the
subclass implementations can handle the message as string, JSON, XML, whatever the API actually provides."""