Add last updated attribute to UK transport train sensor (#139352)
added last updated attribute to train sensor Co-authored-by: Franck Nijhof <git@frenck.dev>pull/139641/head
parent
0a3562aca3
commit
8d6178ffa6
|
@ -32,6 +32,7 @@ ATTR_NEXT_BUSES = "next_buses"
|
||||||
ATTR_STATION_CODE = "station_code"
|
ATTR_STATION_CODE = "station_code"
|
||||||
ATTR_CALLING_AT = "calling_at"
|
ATTR_CALLING_AT = "calling_at"
|
||||||
ATTR_NEXT_TRAINS = "next_trains"
|
ATTR_NEXT_TRAINS = "next_trains"
|
||||||
|
ATTR_LAST_UPDATED = "last_updated"
|
||||||
|
|
||||||
CONF_API_APP_KEY = "app_key"
|
CONF_API_APP_KEY = "app_key"
|
||||||
CONF_API_APP_ID = "app_id"
|
CONF_API_APP_ID = "app_id"
|
||||||
|
@ -199,7 +200,9 @@ class UkTransportLiveBusTimeSensor(UkTransportSensor):
|
||||||
def extra_state_attributes(self) -> dict[str, Any] | None:
|
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||||
"""Return other details about the sensor state."""
|
"""Return other details about the sensor state."""
|
||||||
if self._data is not None:
|
if self._data is not None:
|
||||||
attrs = {ATTR_NEXT_BUSES: self._next_buses}
|
attrs = {
|
||||||
|
ATTR_NEXT_BUSES: self._next_buses,
|
||||||
|
}
|
||||||
for key in (
|
for key in (
|
||||||
ATTR_ATCOCODE,
|
ATTR_ATCOCODE,
|
||||||
ATTR_LOCALITY,
|
ATTR_LOCALITY,
|
||||||
|
@ -272,6 +275,7 @@ class UkTransportLiveTrainTimeSensor(UkTransportSensor):
|
||||||
attrs = {
|
attrs = {
|
||||||
ATTR_STATION_CODE: self._station_code,
|
ATTR_STATION_CODE: self._station_code,
|
||||||
ATTR_CALLING_AT: self._calling_at,
|
ATTR_CALLING_AT: self._calling_at,
|
||||||
|
ATTR_LAST_UPDATED: self._data[ATTR_REQUEST_TIME],
|
||||||
}
|
}
|
||||||
if self._next_trains:
|
if self._next_trains:
|
||||||
attrs[ATTR_NEXT_TRAINS] = self._next_trains
|
attrs[ATTR_NEXT_TRAINS] = self._next_trains
|
||||||
|
|
|
@ -8,6 +8,7 @@ import requests_mock
|
||||||
from homeassistant.components.uk_transport.sensor import (
|
from homeassistant.components.uk_transport.sensor import (
|
||||||
ATTR_ATCOCODE,
|
ATTR_ATCOCODE,
|
||||||
ATTR_CALLING_AT,
|
ATTR_CALLING_AT,
|
||||||
|
ATTR_LAST_UPDATED,
|
||||||
ATTR_LOCALITY,
|
ATTR_LOCALITY,
|
||||||
ATTR_NEXT_BUSES,
|
ATTR_NEXT_BUSES,
|
||||||
ATTR_NEXT_TRAINS,
|
ATTR_NEXT_TRAINS,
|
||||||
|
@ -90,3 +91,4 @@ async def test_train(hass: HomeAssistant) -> None:
|
||||||
== "London Waterloo"
|
== "London Waterloo"
|
||||||
)
|
)
|
||||||
assert train_state.attributes[ATTR_NEXT_TRAINS][0]["estimated"] == "06:13"
|
assert train_state.attributes[ATTR_NEXT_TRAINS][0]["estimated"] == "06:13"
|
||||||
|
assert train_state.attributes[ATTR_LAST_UPDATED] == "2017-07-10T06:10:05+01:00"
|
||||||
|
|
Loading…
Reference in New Issue