-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Platform for Munich public transport departure times #6704
Conversation
@DavidMStraub, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @rmkraus to be potential reviewers. |
Nothing is too local 👍 |
import homeassistant.helpers.config_validation as cv | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
# A typo in the file name of the PyPI version prevents installation from PyPI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to open an issue for this on their repo so we can migrate to use the PyPi version in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, just replaced it with the PyPI version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few changes, code looks good 👍
self._line = line | ||
self.data = MVGLiveData(station, destination, line, | ||
offset, ubahn, tram, bus, sbahn) | ||
self.update() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't call update
here but instead pass True
as a second parameter to add_devices
# Details info is not useful. | ||
# Having a more consistent interface simplifies | ||
# usage of Template sensors later on | ||
con.pop('productsymbol') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's usually not a good idea to mutate data that you fetch from a library. They might store a reference in a cache that is now no longer what they expect it to be. Create new dictionaries instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hints! I think I fixed everything.
_departures = self.mvg.getlivedata(station=self._station, | ||
ubahn=self._ubahn, | ||
tram=self._tram, | ||
bus=self._bus, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line over-indented for visual indent
try: | ||
_departures = self.mvg.getlivedata(station=self._station, | ||
ubahn=self._ubahn, | ||
tram=self._tram, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line over-indented for visual indent
"""Update the connection data.""" | ||
try: | ||
_departures = self.mvg.getlivedata(station=self._station, | ||
ubahn=self._ubahn, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line over-indented for visual indent
_LOGGER.warning("Returned data not understood.") | ||
return | ||
_keys = ['destination', 'linename', 'time', 'direction', 'product'] | ||
self.departures = [{k: int(v) if k == 'time' and v.is_integer() else v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is unmaintainable. Please make it a for loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Refactored and simplified.
def update(self): | ||
"""Get the latest data and update the state.""" | ||
self.data.update() | ||
if not self.data.departures: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case can never happen because you always have an empty dictionary in your list, meaning it will always test truthy. (only an empty list is False)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Refactored the code now - in fact, no need for the list as we're only interested in the 1st item.
continue | ||
# now select the relevant data | ||
_nextdep = {} | ||
for k in ['destination', 'linename', 'time', 'direction', 'product']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (81 > 79 characters)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐦
I'm not sure if this is too local to become an official component but for me it's very useful so I thought I'd share it anyway.
Description:
The MVG live service (http://www.mvg-live.de) provides real-time departure information for the Munich public transort system (bus, tram, subway, suburban rail). This platform provides a sensor for the time to the next departure (optionally the next departure after an offset, e.g. the time it takes you to walk to the bus stop) at a stop or station. The destination and line number are given in the attributes. Optionally, specific lines or destinations can be selected.
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2311
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.