File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed
custom_components/first_bus Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ The following attributes are available in addition
2121| ` is_live ` | ` boolean ` | Determines if the bus is being tracked (` true ` ) or is from the timetable (` false ` ) |
2222| ` stop ` | ` string ` | The ATCO code of the bus stop that is being tracked |
2323| ` buses ` | ` list ` | The collection of known upcoming buses for the stop |
24+ | ` data_last_updated ` | ` datetime ` | The timestamp when the underlying data was last updated |
2425
2526For each bus in ` buses ` , you can find the following attributes
2627
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ def __init__(self, data):
4343 self ._attributes = {}
4444 self ._state = None
4545 self ._mins_since_last_update = 0
46+ self ._data_last_updated = None
4647
4748 @property
4849 def unique_id (self ):
@@ -78,12 +79,13 @@ async def async_update(self):
7879 self ._mins_since_last_update = self ._mins_since_last_update - 1
7980
8081 # We only want to update every 5 minutes so we don't hammer the service
82+ data_last_updated = None
8183 if self ._mins_since_last_update <= 0 :
8284 bus_times = await self ._client .async_get_bus_times (self ._data [CONFIG_STOP ])
8385 buses = get_buses (bus_times , now ())
8486 self ._buses = buses
8587 self ._mins_since_last_update = MINUTES_BETWEEN_UPDATES
86- self ._attributes [ "data_last_updated" ] = now ()
88+ self ._data_last_updated = now ()
8789
8890 next_bus = get_next_bus (self ._buses , self ._data [CONFIG_BUSES ], now ())
8991 self ._attributes = copy .copy (next_bus )
@@ -92,6 +94,9 @@ async def async_update(self):
9294
9395 self ._attributes ["stop" ] = self ._data [CONFIG_STOP ]
9496 self ._attributes ["buses" ] = self ._buses
97+
98+ if self ._data_last_updated is not None :
99+ self ._attributes ["data_last_updated" ] = self ._data_last_updated
95100
96101 if next_bus is not None :
97102 self ._state = next_bus ["due" ]
You can’t perform that action at this time.
0 commit comments