Apply SSE Spot Provider patch by Steven M1SDH

This commit is contained in:
Ian Renton
2025-10-21 08:11:43 +01:00
parent fc951ead41
commit 229228d209

View File

@@ -34,11 +34,19 @@ class SSESpotProvider(SpotProvider):
if self.thread:
self.thread.join()
def _on_open(self):
self.status = "Waiting for Data"
def _on_error(self):
self.status = "Connecting"
def run(self):
while not self.stopped:
try:
logging.debug("Connecting to " + self.name + " spot API...")
with EventSource(self.url, headers=HTTP_HEADERS, latest_event_id=self.last_event_id, timeout=30) as event_source:
self.status = "Connecting"
with EventSource(self.url, headers=HTTP_HEADERS, latest_event_id=self.last_event_id, timeout=30,
on_open=self._on_open, on_error=self._on_error) as event_source:
self.event_source = event_source
for event in self.event_source:
if event.type == 'message':
@@ -58,6 +66,8 @@ class SSESpotProvider(SpotProvider):
except Exception as e:
self.status = "Error"
logging.exception("Exception in SSE Spot Provider (" + self.name + ")")
else:
self.status = "Disconnected"
sleep(5) # Wait before trying to reconnect
# Convert an SSE message received from the API into a spot. The whole message data is provided here so the subclass