mondbaron / mvg

An unofficial interface to timetable information of the Münchner Verkehrsgesellschaft (MVG).
https://pypi.org/project/mvg
MIT License
17 stars 5 forks source link

raise ValueError("Invalid station.") #6

Open Nisbo opened 7 months ago

Nisbo commented 7 months ago

Dear all,

dont know if this is the right place, because I am using a Home Assistant addon which is including "mvg" https://github.com/MrGauz/home-assistant-munich-transport

I tried to get it running with my hometown. It is working with - name: "Hohenzollernplatz" - name: "Pasing" is also working

but I am not able to add S-Bahn station Olching

      - name: "de:09179:6110"
      - name: "Olching"
      - name: "Olching (Obb.) Olching"
      - name: "Olching, Olching (Obb.)"

non of the names above are working. same for "Eichenau".

Any idea, what is the correct name ?

MarcMuc commented 6 months ago

OK, I was too curious to wait and gave it a short try this morning.

I extracted the code from "sensor.py" which uses the MVG Api to fetch station information:

from __future__ import annotations
import logging
from typing import Optional

from mvg import MvgApi, MvgApiError

ort = "Olching"

try:
    station = MvgApi.station(ort)
except MvgApiError as e:
    print("Could not find %s: %s" % (ort, e))

print(f"OK: station ID for {ort}: {station}")

mvg_api = MvgApi(station['id'])
departures = mvg_api.departures(
    limit=5,
    offset=0,
)
departures = list(filter(lambda d: not bool(d['cancelled']), departures))

print(f"OK: departures for {station['name']}: {departures}")

With this tiny bit of code I get infos about the stations "Daglfing" and "Olching". But the "Olching" request fires some errors I can't interpret. But I think the error is not in the MVG API. It is in sensor.py.

Here are the results for Daglfing and Olching:

Daglfing: OK: station ID for Daglfing: {'id': 'de:09162:700', 'name': 'Daglfing', 'place': 'München', 'latitude': 48.14983, 'longitude': 11.64929} OK: departures for Daglfing: [{'time': 1703152200, 'planned': 1703152140, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703152260, 'planned': 1703152260, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703153340, 'planned': 1703153340, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703153460, 'planned': 1703153460, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703154540, 'planned': 1703154540, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703154660, 'planned': 1703154660, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703155740, 'planned': 1703155740, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703155860, 'planned': 1703155860, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703156940, 'planned': 1703156940, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703157060, 'planned': 1703157060, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703158140, 'planned': 1703158140, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703158260, 'planned': 1703158260, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703159340, 'planned': 1703159340, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703159460, 'planned': 1703159460, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703160540, 'planned': 1703160540, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703160660, 'planned': 1703160660, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703161740, 'planned': 1703161740, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703161860, 'planned': 1703161860, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703162940, 'planned': 1703162940, 'line': 'S8', 'destination': 'Herrsching', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703163060, 'planned': 1703163060, 'line': 'S8', 'destination': 'Flughafen München', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}]`

Olching: OK: station ID for Olching: {'id': 'de:09179:6110', 'name': 'Olching', 'place': 'Olching (Obb.)', 'latitude': 48.20988, 'longitude': 11.33429}

Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001CA3D85C5E0> Traceback (most recent call last): File "C:\Users\Marc\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in del self.close() File "C:\Users\Marc\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Users\Marc\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon self._check_closed() File "C:\Users\Marc\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001CA3D85C5E0> Traceback (most recent call last): File "C:\Users\Marc\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in del self.close() File "C:\Users\Marc\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Users\Marc\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon self._check_closed() File "C:\Users\Marc\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed

OK: departures for Olching: [{'time': 1703151900, 'planned': 1703151900, 'line': '843', 'destination': 'Fürstenfeldbruck (S)', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703151900, 'planned': 1703151900, 'line': '860', 'destination': 'Olching, Georgenstraße', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703151900, 'planned': 1703151900, 'line': '832', 'destination': 'Puchheim (S) Nord', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703152260, 'planned': 1703152260, 'line': '831', 'destination': 'Olching, Gewerbegebiet', 'type': 'Bus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703152440, 'planned': 1703152440, 'line': '831', 'destination': 'Graßlfing, Olchinger See', 'type': 'Bus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703152560, 'planned': 1703152560, 'line': '860', 'destination': 'Freiham (S) Süd', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703152680, 'planned': 1703152680, 'line': '835', 'destination': 'Esting, Kriegerdenkmal', 'type': 'Bus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703152740, 'planned': 1703152740, 'line': 'S3', 'destination': 'Holzkirchen', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703152980, 'planned': 1703152860, 'line': 'S3', 'destination': 'Mammendorf', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703153100, 'planned': 1703153100, 'line': '860', 'destination': 'Olching, Georgenstraße', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703153100, 'planned': 1703153100, 'line': '843', 'destination': 'Fürstenfeldbruck (S)', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703153460, 'planned': 1703153460, 'line': '831', 'destination': 'Olching, Gewerbegebiet', 'type': 'Bus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703153640, 'planned': 1703153640, 'line': '831', 'destination': 'Graßlfing, Olchinger See', 'type': 'Bus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703153760, 'planned': 1703153760, 'line': '860', 'destination': 'Freiham (S) Süd', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703153760, 'planned': 1703153760, 'line': '736', 'destination': 'Dachau (S)', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703153880, 'planned': 1703153880, 'line': '835', 'destination': 'Esting, Kriegerdenkmal', 'type': 'Bus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703153940, 'planned': 1703153940, 'line': 'S3', 'destination': 'Holzkirchen', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703154060, 'planned': 1703154060, 'line': 'S3', 'destination': 'Mammendorf', 'type': 'S-Bahn', 'icon': 'mdi:subway-variant', 'cancelled': False, 'messages': []}, {'time': 1703154300, 'planned': 1703154300, 'line': '843', 'destination': 'Fürstenfeldbruck (S)', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}, {'time': 1703154300, 'planned': 1703154300, 'line': '832', 'destination': 'Puchheim (S) Nord', 'type': 'Regionalbus', 'icon': 'mdi:bus', 'cancelled': False, 'messages': []}]

Nisbo commented 6 months ago

Thx for your investigation. I am also not able to follow the stack trace. Dont know where the ProactorBasePipeTransport is included and if the trace is complete.

However, I already started to create my own MVG Addon for Home Assistant by using my PHP Scripts from IP-Symcon. Maybe I will release it this week to the public. But I am new to Python and HA, so maybe its not 100% accurat. gg But it is working. :) I am using the globalid to get the results. A little bit more complicted during the setup, but leads to less problems.

290647231-29985729-abfa-4049-8c4b-6b375303ceb1 291342293-9bad6d00-67d2-4fad-9444-29b2dafcf646