Skip to content

Commit

Permalink
Fix async lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jul 4, 2024
1 parent 1f1829a commit bff2c2e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions teslemetry_stream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


LOGGER = logging.getLogger(__package__)
DELAY = 10
DELAY = 1


class TeslemetryStreamError(Exception):
Expand All @@ -32,6 +32,12 @@ class TeslemetryStreamVehicleNotConfigured(TeslemetryStreamError):
message = "This vehicle is not configured to connect to Teslemetry."


class TeslemetryStreamEnded(TeslemetryStreamError):
"""Teslemetry Stream Connection Error"""

message = "The stream was ended by the server."


class TeslemetryStream:
"""Teslemetry Stream Client"""

Expand Down Expand Up @@ -192,15 +198,16 @@ async def __anext__(self) -> dict:
.replace(tzinfo=timezone.utc)
.timestamp()
) * 1000 + int(ns[:3])
LOGGER.debug("event %s", json.dumps(data))
# LOGGER.debug("event %s", json.dumps(data))
self.delay = DELAY
return data
except aiohttp.ClientError as error:
raise TeslemetryStreamEnded()
except (TeslemetryStreamEnded, aiohttp.ClientError) as error:
LOGGER.warning("Connection error: %s", error)
self.close()
LOGGER.debug("Reconnecting in %s seconds", self.delay)
await asyncio.sleep(self.delay)
self.delay += DELAY
self.delay += self.delay

def async_add_listener(
self, callback: Callable, filters: dict | None = None
Expand Down

0 comments on commit bff2c2e

Please sign in to comment.