Skip to content

Commit

Permalink
Add last data refresh sensor
Browse files Browse the repository at this point in the history
Add last data refresh sensor - Timestamp when services were refreshed successfully for the last time.
  • Loading branch information
stickpin committed Jan 9, 2024
1 parent e1dccdd commit e83179c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions volkswagencarnet/vw_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ async def getSelectiveStatus(self, vin, services):
f"Did not receive return data for requested service {service}. (This is expected for several service/car combinations)"
)

if response:
response.update({"refreshTimestamp": datetime.now()})

return response

except Exception as error:
Expand Down
6 changes: 6 additions & 0 deletions volkswagencarnet/vw_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,12 @@ def create_instruments():
icon="mdi:api",
unit="",
),
Sensor(
attr="last_data_refresh",
name="Last data refresh",
icon="mdi:clock",
unit="",
),
BinarySensor(attr="external_power", name="External power", device_class=VWDeviceClass.POWER),
BinarySensor(attr="energy_flow", name="Energy flow", device_class=VWDeviceClass.POWER),
BinarySensor(
Expand Down
20 changes: 20 additions & 0 deletions volkswagencarnet/vw_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2673,3 +2673,23 @@ def api_token_status_last_updated(self) -> datetime:
def is_api_token_status_supported(self):
"""Parkingposition API status is always supported."""
return True

@property
def last_data_refresh(self) -> bool:
"""Check when services were refreshed successfully for the last time."""
last_data_refresh_time = "Unknown"
last_data_refresh_path = "refreshTimestamp"
if is_valid_path(self.attrs, last_data_refresh_path):
last_data_refresh_time = find_path(self.attrs, last_data_refresh_path)
return last_data_refresh_time.strftime("%Y-%m-%d %H:%M:%S")
return last_data_refresh_time

@property
def last_data_refresh_last_updated(self) -> datetime:
"""Return attribute last updated timestamp."""
return datetime.now()

@property
def is_last_data_refresh_supported(self):
"""Last data refresh is always supported."""
return True

0 comments on commit e83179c

Please sign in to comment.