mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Simplify Swiss public transport coordinator (#128891)
This commit is contained in:
parent
28a8ed62f3
commit
62773fa88a
@ -75,13 +75,6 @@ class SwissPublicTransportDataUpdateCoordinator(
|
|||||||
return departure_datetime - dt_util.as_local(dt_util.utcnow())
|
return departure_datetime - dt_util.as_local(dt_util.utcnow())
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def nth_departure_time(self, i: int) -> datetime | None:
|
|
||||||
"""Get nth departure time."""
|
|
||||||
connections = self._opendata.connections
|
|
||||||
if len(connections) > i and connections[i] is not None:
|
|
||||||
return dt_util.parse_datetime(connections[i]["departure"])
|
|
||||||
return None
|
|
||||||
|
|
||||||
async def _async_update_data(self) -> list[DataConnection]:
|
async def _async_update_data(self) -> list[DataConnection]:
|
||||||
return await self.fetch_connections(limit=CONNECTIONS_COUNT)
|
return await self.fetch_connections(limit=CONNECTIONS_COUNT)
|
||||||
|
|
||||||
@ -101,7 +94,7 @@ class SwissPublicTransportDataUpdateCoordinator(
|
|||||||
connections = self._opendata.connections
|
connections = self._opendata.connections
|
||||||
return [
|
return [
|
||||||
DataConnection(
|
DataConnection(
|
||||||
departure=self.nth_departure_time(i),
|
departure=dt_util.parse_datetime(connections[i]["departure"]),
|
||||||
train_number=connections[i]["number"],
|
train_number=connections[i]["number"],
|
||||||
platform=connections[i]["platform"],
|
platform=connections[i]["platform"],
|
||||||
transfers=connections[i]["transfers"],
|
transfers=connections[i]["transfers"],
|
||||||
|
@ -99,7 +99,7 @@
|
|||||||
"line": "T10"
|
"line": "T10"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"departure": "2024-01-06T18:14:00+0100",
|
"departure": "invalid",
|
||||||
"number": 11,
|
"number": 11,
|
||||||
"platform": 11,
|
"platform": 11,
|
||||||
"transfers": 0,
|
"transfers": 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user