Skip to content

Commit

Permalink
pass all transport types if none is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
mondbaron committed Aug 27, 2023
1 parent d228e42 commit 0d79bfe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "mvg"
version = "1.0.5"
version = "1.1.0"

description = "An unofficial interface to timetable information of the Münchner Verkehrsgesellschaft (MVG)."
readme = "README.md"
Expand Down
12 changes: 9 additions & 3 deletions src/mvg/mvgapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ class TransportType(Enum):
BUS: tuple[str, str] = ("Bus", "mdi:bus")
REGIONAL_BUS: tuple[str, str] = ("Regionalbus", "mdi:bus")
SEV: tuple[str, str] = ("SEV", "mdi:taxi")
SHIFF: tuple[str, str] = ("Schiff", "mdi:ferry")
SCHIFF: tuple[str, str] = ("Schiff", "mdi:ferry")

@classmethod
def all(cls) -> list[TransportType]:
"""Returns a list of all products."""
return [getattr(TransportType, c.name) for c in cls if c.name != "SEV"]


class MvgApiError(Exception):
Expand Down Expand Up @@ -339,8 +344,9 @@ async def departures_async(
try:
args = dict.fromkeys(Endpoint.FIB_LOCATION.value[1])
args.update({"globalId": station_id, "offsetInMinutes": offset, "limit": limit})
if transport_types:
args.update({"transportTypes": ",".join([product.name for product in transport_types])})
if transport_types is None:
transport_types = TransportType.all()
args.update({"transportTypes": ",".join([product.name for product in transport_types])})
result = await MvgApi.__api(Base.FIB, Endpoint.FIB_DEPARTURE, args)
assert isinstance(result, list)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ def test_faraway() -> None:
print("BASIC: ", station, departures, end="\n\n")


def test_village() -> None:
"""Test: basic usage"""
station = MvgApi.station('Egmating, Schule')
assert station['id'] == "de:09175:4212"
if station:
mvgapi = MvgApi(station['id'])
departures = mvgapi.departures()
assert len(departures) > 0
print("BASIC: ", station, departures, end="\n\n")


def test_nearby() -> None:
"""Test: station by coordinates"""
station = MvgApi.nearby(48.1, 11.5)
Expand Down

0 comments on commit 0d79bfe

Please sign in to comment.