Skip to content

Commit

Permalink
Response type should not contain datetime for Swiss Public Transport (h…
Browse files Browse the repository at this point in the history
…ome-assistant#128391)

* response type should not contain datetime

* use isoformat
  • Loading branch information
miaucl authored Oct 15, 2024
1 parent 2c00cd4 commit c3e7fcc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions homeassistant/components/swiss_public_transport/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
import homeassistant.util.dt as dt_util
from homeassistant.util.json import JsonValueType

from .const import CONNECTIONS_COUNT, DEFAULT_UPDATE_TIME, DOMAIN

Expand Down Expand Up @@ -110,3 +111,23 @@ async def fetch_connections(self, limit: int) -> list[DataConnection]:
for i in range(limit)
if len(connections) > i and connections[i] is not None
]

async def fetch_connections_as_json(self, limit: int) -> list[JsonValueType]:
"""Fetch connections using the opendata api."""
return [
{
"departure": connection["departure"].isoformat()
if connection["departure"]
else None,
"duration": connection["duration"],
"platform": connection["platform"],
"remaining_time": connection["remaining_time"],
"start": connection["start"],
"destination": connection["destination"],
"train_number": connection["train_number"],
"transfers": connection["transfers"],
"delay": connection["delay"],
"line": connection["line"],
}
for connection in await self.fetch_connections(limit)
]
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def async_fetch_connections(
limit = call.data.get(ATTR_LIMIT) or CONNECTIONS_COUNT
coordinator = hass.data[DOMAIN][config_entry.entry_id]
try:
connections = await coordinator.fetch_connections(limit=int(limit))
connections = await coordinator.fetch_connections_as_json(limit=int(limit))
except UpdateFailed as e:
raise HomeAssistantError(
translation_domain=DOMAIN,
Expand Down

0 comments on commit c3e7fcc

Please sign in to comment.