Skip to content

Commit

Permalink
Fix coordinator memory leak
Browse files Browse the repository at this point in the history
We were using a class attribute for saving API response data,
which causes corruption when there are more than one config
entries set up.

Move that to an instance attribute to avoid the collision.

This fixes #4
  • Loading branch information
jhansche committed Nov 25, 2023
1 parent e24c853 commit 65d8f38
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions custom_components/teslafi/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class TeslaFiCoordinator(DataUpdateCoordinator[TeslaFiVehicle]):
"""TeslaFi Update Coordinator"""

_vehicle = TeslaFiVehicle({})
_vehicle: TeslaFiVehicle
data: TeslaFiVehicle

_override_next_refresh: timedelta = None
Expand All @@ -30,6 +30,8 @@ def __init__(
client: TeslaFiClient,
) -> None:
self._client = client
self.data = None
self._vehicle = TeslaFiVehicle({})
# TODO: implement custom Debouncer to ensure no more than 2x per min,
# as per API rate limit?
super().__init__(
Expand Down Expand Up @@ -74,7 +76,7 @@ def _schedule_refresh(self) -> None:
async def _refresh(self) -> TeslaFiVehicle:
"""Refresh"""
current = await self._client.last_good()
LOGGER.info("Last good: %s", current)
LOGGER.debug("Last good: %s", current)
self._vehicle.update_non_empty(current)
last_remote_update = self._vehicle.get("Date")
LOGGER.debug("Remote data last updated %s", last_remote_update)
Expand Down

0 comments on commit 65d8f38

Please sign in to comment.