mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Response type should not contain datetime for Swiss Public Transport (#128391)
* response type should not contain datetime * use isoformat
This commit is contained in:
parent
2c00cd489e
commit
c3e7fcc153
@ -16,6 +16,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
from homeassistant.util.json import JsonValueType
|
||||||
|
|
||||||
from .const import CONNECTIONS_COUNT, DEFAULT_UPDATE_TIME, DOMAIN
|
from .const import CONNECTIONS_COUNT, DEFAULT_UPDATE_TIME, DOMAIN
|
||||||
|
|
||||||
@ -110,3 +111,23 @@ class SwissPublicTransportDataUpdateCoordinator(
|
|||||||
for i in range(limit)
|
for i in range(limit)
|
||||||
if len(connections) > i and connections[i] is not None
|
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)
|
||||||
|
]
|
||||||
|
@ -69,7 +69,7 @@ def setup_services(hass: HomeAssistant) -> None:
|
|||||||
limit = call.data.get(ATTR_LIMIT) or CONNECTIONS_COUNT
|
limit = call.data.get(ATTR_LIMIT) or CONNECTIONS_COUNT
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
try:
|
try:
|
||||||
connections = await coordinator.fetch_connections(limit=int(limit))
|
connections = await coordinator.fetch_connections_as_json(limit=int(limit))
|
||||||
except UpdateFailed as e:
|
except UpdateFailed as e:
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user