Add direction configuration (#17308)

This commit is contained in:
cgtobi 2018-10-10 17:59:55 +02:00 committed by Martin Hjelmare
parent 9d4dbd7d97
commit 99c6622ee2

View File

@ -24,7 +24,7 @@ CONF_NEXT_DEPARTURE = 'next_departure'
CONF_STATION = 'station' CONF_STATION = 'station'
CONF_DESTINATIONS = 'destinations' CONF_DESTINATIONS = 'destinations'
CONF_DIRECTIONS = 'directions' CONF_DIRECTION = 'direction'
CONF_LINES = 'lines' CONF_LINES = 'lines'
CONF_PRODUCTS = 'products' CONF_PRODUCTS = 'products'
CONF_TIME_OFFSET = 'time_offset' CONF_TIME_OFFSET = 'time_offset'
@ -57,8 +57,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_STATION): cv.string, vol.Required(CONF_STATION): cv.string,
vol.Optional(CONF_DESTINATIONS, default=[]): vol.Optional(CONF_DESTINATIONS, default=[]):
vol.All(cv.ensure_list, [cv.string]), vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_DIRECTIONS, default=[]): vol.Optional(CONF_DIRECTION): cv.string,
vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_LINES, default=[]): vol.Optional(CONF_LINES, default=[]):
vol.All(cv.ensure_list, [cv.positive_int, cv.string]), vol.All(cv.ensure_list, [cv.positive_int, cv.string]),
vol.Optional(CONF_PRODUCTS, default=VALID_PRODUCTS): vol.Optional(CONF_PRODUCTS, default=VALID_PRODUCTS):
@ -84,7 +83,7 @@ async def async_setup_platform(hass, config, async_add_entities,
session, session,
next_departure[CONF_STATION], next_departure[CONF_STATION],
next_departure.get(CONF_DESTINATIONS), next_departure.get(CONF_DESTINATIONS),
next_departure.get(CONF_DIRECTIONS), next_departure.get(CONF_DIRECTION),
next_departure.get(CONF_LINES), next_departure.get(CONF_LINES),
next_departure.get(CONF_PRODUCTS), next_departure.get(CONF_PRODUCTS),
next_departure.get(CONF_TIME_OFFSET), next_departure.get(CONF_TIME_OFFSET),
@ -97,14 +96,14 @@ async def async_setup_platform(hass, config, async_add_entities,
class RMVDepartureSensor(Entity): class RMVDepartureSensor(Entity):
"""Implementation of an RMV departure sensor.""" """Implementation of an RMV departure sensor."""
def __init__(self, session, station, destinations, directions, lines, def __init__(self, session, station, destinations, direction, lines,
products, time_offset, max_journeys, name, timeout): products, time_offset, max_journeys, name, timeout):
"""Initialize the sensor.""" """Initialize the sensor."""
self._station = station self._station = station
self._name = name self._name = name
self._state = None self._state = None
self.data = RMVDepartureData(session, station, destinations, self.data = RMVDepartureData(session, station, destinations,
directions, lines, products, time_offset, direction, lines, products, time_offset,
max_journeys, timeout) max_journeys, timeout)
self._icon = ICONS[None] self._icon = ICONS[None]
@ -167,7 +166,7 @@ class RMVDepartureSensor(Entity):
class RMVDepartureData: class RMVDepartureData:
"""Pull data from the opendata.rmv.de web page.""" """Pull data from the opendata.rmv.de web page."""
def __init__(self, session, station_id, destinations, directions, lines, def __init__(self, session, station_id, destinations, direction, lines,
products, time_offset, max_journeys, timeout): products, time_offset, max_journeys, timeout):
"""Initialize the sensor.""" """Initialize the sensor."""
from RMVtransport import RMVtransport from RMVtransport import RMVtransport
@ -175,7 +174,7 @@ class RMVDepartureData:
self.station = None self.station = None
self._station_id = station_id self._station_id = station_id
self._destinations = destinations self._destinations = destinations
self._directions = directions self._direction = direction
self._lines = lines self._lines = lines
self._products = products self._products = products
self._time_offset = time_offset self._time_offset = time_offset
@ -189,6 +188,7 @@ class RMVDepartureData:
try: try:
_data = await self.rmv.get_departures(self._station_id, _data = await self.rmv.get_departures(self._station_id,
products=self._products, products=self._products,
directionId=self._direction,
maxJourneys=50) maxJourneys=50)
except ValueError: except ValueError:
self.departures = [] self.departures = []