Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ability to call check_and_force_update_vehicles function for just one specific vehicle. #688

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions hyundai_kia_connect_api/VehicleManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,28 @@ def update_vehicle_with_cached_state(self, vehicle_id: str) -> None:
_LOGGER.debug(f"{DOMAIN} - Vehicle Disabled, skipping.")

def check_and_force_update_vehicles(self, force_refresh_interval: int) -> None:
for vehicle_id in self.vehicles.keys():
self.check_and_force_update_vehicle(force_refresh_interval, vehicle_id)

def check_and_force_update_vehicle(
self, force_refresh_interval: int, vehicle_id: str
) -> None:
# Force refresh only if current data is older than the value bassed in seconds.
# Otherwise runs a cached update.
started_at_utc: dt = dt.datetime.now(pytz.utc)
for vehicle_id in self.vehicles.keys():
vehicle = self.get_vehicle(vehicle_id)
if vehicle.last_updated_at is not None:
_LOGGER.debug(
f"{DOMAIN} - Time differential in seconds: {(started_at_utc - vehicle.last_updated_at).total_seconds()}" # noqa
)
if (
started_at_utc - vehicle.last_updated_at
).total_seconds() > force_refresh_interval:
self.force_refresh_vehicle_state(vehicle_id)
else:
self.update_vehicle_with_cached_state(vehicle_id)
vehicle = self.get_vehicle(vehicle_id)
if vehicle.last_updated_at is not None:
_LOGGER.debug(
f"{DOMAIN} - Time differential in seconds: {(started_at_utc - vehicle.last_updated_at).total_seconds()}" # noqa
)
if (
started_at_utc - vehicle.last_updated_at
).total_seconds() > force_refresh_interval:
self.force_refresh_vehicle_state(vehicle_id)
else:
self.update_vehicle_with_cached_state(vehicle_id)
else:
self.update_vehicle_with_cached_state(vehicle_id)

def force_refresh_all_vehicles_states(self) -> None:
for vehicle_id in self.vehicles.keys():
Expand Down
Loading