Use new API for Vasttrafik (#102570)
parent
3f56ca49c6
commit
a516f32bbd
|
@ -5,5 +5,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/vasttrafik",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["vasttrafik"],
|
||||
"requirements": ["vtjp==0.1.14"]
|
||||
"requirements": ["vtjp==0.2.1"]
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Support for Västtrafik public transport."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
|
||||
import vasttrafik
|
||||
|
@ -22,6 +22,9 @@ ATTR_ACCESSIBILITY = "accessibility"
|
|||
ATTR_DIRECTION = "direction"
|
||||
ATTR_LINE = "line"
|
||||
ATTR_TRACK = "track"
|
||||
ATTR_FROM = "from"
|
||||
ATTR_TO = "to"
|
||||
ATTR_DELAY = "delay"
|
||||
|
||||
CONF_DEPARTURES = "departures"
|
||||
CONF_FROM = "from"
|
||||
|
@ -32,7 +35,6 @@ CONF_SECRET = "secret"
|
|||
|
||||
DEFAULT_DELAY = 0
|
||||
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
@ -101,7 +103,7 @@ class VasttrafikDepartureSensor(SensorEntity):
|
|||
if location.isdecimal():
|
||||
station_info = {"station_name": location, "station_id": location}
|
||||
else:
|
||||
station_id = self._planner.location_name(location)[0]["id"]
|
||||
station_id = self._planner.location_name(location)[0]["gid"]
|
||||
station_info = {"station_name": location, "station_id": station_id}
|
||||
return station_info
|
||||
|
||||
|
@ -143,20 +145,36 @@ class VasttrafikDepartureSensor(SensorEntity):
|
|||
self._attributes = {}
|
||||
else:
|
||||
for departure in self._departureboard:
|
||||
line = departure.get("sname")
|
||||
if "cancelled" in departure:
|
||||
service_journey = departure.get("serviceJourney", {})
|
||||
line = service_journey.get("line", {})
|
||||
|
||||
if departure.get("isCancelled"):
|
||||
continue
|
||||
if not self._lines or line in self._lines:
|
||||
if "rtTime" in departure:
|
||||
self._state = departure["rtTime"]
|
||||
if not self._lines or line.get("shortName") in self._lines:
|
||||
if "estimatedOtherwisePlannedTime" in departure:
|
||||
try:
|
||||
self._state = datetime.fromisoformat(
|
||||
departure["estimatedOtherwisePlannedTime"]
|
||||
).strftime("%H:%M")
|
||||
except ValueError:
|
||||
self._state = departure["estimatedOtherwisePlannedTime"]
|
||||
else:
|
||||
self._state = departure["time"]
|
||||
self._state = None
|
||||
|
||||
stop_point = departure.get("stopPoint", {})
|
||||
|
||||
params = {
|
||||
ATTR_ACCESSIBILITY: departure.get("accessibility"),
|
||||
ATTR_DIRECTION: departure.get("direction"),
|
||||
ATTR_LINE: departure.get("sname"),
|
||||
ATTR_TRACK: departure.get("track"),
|
||||
ATTR_ACCESSIBILITY: "wheelChair"
|
||||
if line.get("isWheelchairAccessible")
|
||||
else None,
|
||||
ATTR_DIRECTION: service_journey.get("direction"),
|
||||
ATTR_LINE: line.get("shortName"),
|
||||
ATTR_TRACK: stop_point.get("platform"),
|
||||
ATTR_FROM: stop_point.get("name"),
|
||||
ATTR_TO: self._heading["station_name"]
|
||||
if self._heading
|
||||
else "ANY",
|
||||
ATTR_DELAY: self._delay.seconds // 60 % 60,
|
||||
}
|
||||
|
||||
self._attributes = {k: v for k, v in params.items() if v}
|
||||
|
|
|
@ -2682,7 +2682,7 @@ volvooncall==0.10.3
|
|||
vsure==2.6.6
|
||||
|
||||
# homeassistant.components.vasttrafik
|
||||
vtjp==0.1.14
|
||||
vtjp==0.2.1
|
||||
|
||||
# homeassistant.components.vulcan
|
||||
vulcan-api==2.3.0
|
||||
|
|
Loading…
Reference in New Issue