Skip to content
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

New deutsche_bahn component #1355

Merged
merged 1 commit into from
Feb 25, 2016
Merged

Conversation

deisi
Copy link
Contributor

@deisi deisi commented Feb 21, 2016

Uses the schiene API to communicate with the web server of bahn.de
and pulls information about a specific connection from bahn.de
webpage. The departure time of the next train for the given connection is shown.
In case of delay, the delay is also shown. Additional ATTRIBUTES are used to
inform about e.g. the type of the train, price and if it is ontime.

Usage:

sensor:
  platform: deutsche_bahn
    from: name_of_start_station
    to: name_of_final_station

Problems:
I'm testing it for quite some time, but I have never seen the ATTRIBUTES in case
of a delayed train. The ATTRIBUTES are directly passed from the schiene API. So this
use case has not been tested yet.

Bahn AG is not supporting the schiene api unlike in the case of swiss_public_transport.
It's not guaranteed that schiene will work forever, in fact it can happen that Bahn AG will
intentionally brake the API at some point. In the past Bahn AG has not always been very supportive
to the open source community.

@balloobbot
Copy link

This is an automated response to help you succeed in getting this PR merged.

  • Whenever CI fails, the reason for failing will be at the bottom of the log. Each Python version performs different tests so it can be that only Python 3.5 fails. Your PR cannot be merged unless CI is green!
  • Always make sure your fork is up to date before you create a new branch. No "merge upstream" or "merge dev" commits. Also rebase on the dev branch before creating a PR.
  • Squash your commits when the PR is ready to be merged.

If your code communicates with devices:

  • Use a 3rd party library for communication. Add dependencies via REQUIREMENTS variable (example).
  • Only import your 3rd party dependencies inside functions that use it (example).
  • Run script/gen_requirements_all.py to update requirements_all.txt.
  • Add your new files to .coveragerc

If your code does not depend on external devices:

  • Write tests to verify your code works

@deisi
Copy link
Contributor Author

deisi commented Feb 21, 2016

when I run

./script/gen_requirements_all.py

I get

Traceback (most recent call last):
  File "./script/gen_requirements_all.py", line 131, in <module>
    main()
  File "./script/gen_requirements_all.py", line 115, in main
    data = gather_modules()
  File "./script/gen_requirements_all.py", line 57, in gather_modules
    for package in sorted(explore_module('homeassistant.components', True)):
  File "./script/gen_requirements_all.py", line 32, in explore_module
    found.extend(explore_module(name, False))
  File "./script/gen_requirements_all.py", line 21, in explore_module
    module = importlib.import_module(package)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/usr/lib/python3.5/site-packages/homeassistant-0.10.1-py3.5.egg/homeassistant/components/motor/__init__.py", line 14, in <module>
    from homeassistant.const import (
ImportError: cannot import name 'SERVICE_OPEN'

This also happens in the dev branch. So I think this is not due to my new component. Am I right?

@fabaff
Copy link
Member

fabaff commented Feb 21, 2016

script/gen_requirements_all.py for works me in dev.

This line is wired: File "/usr/lib/python3.5/site-packages/homeassistant-0.10.1-py3.5.egg/homeassistant/components/motor/__init__.py", line 14, in <module>. Could it be that that you are no longer in your venv or have multiple installations of HA.

There are some other issues which makes the CI fail.

lint runtests: commands[1] | pylint homeassistant
************* Module homeassistant.components.sensor.deutsche_bahn
W: 67, 0: Bad indentation. Found 12 spaces, expected 8 (bad-indentation)
C: 80, 0: Missing class docstring (missing-docstring)
C: 90, 4: Missing method docstring (missing-docstring)
W: 99,16: Specify string format arguments as logging function parameters (logging-not-lazy)
R: 80, 0: Too few public methods (1/2) (too-few-public-methods)

@fabaff
Copy link
Member

fabaff commented Feb 21, 2016

Bahn AG is not supporting the schiene api unlike in the case of swiss_public_transport.
It's not guaranteed that schiene will work forever, in fact it can happen that Bahn AG will
intentionally brake the API at some point. In the past Bahn AG has not always been very supportive
to the open source community.

This is a generic problem. We have most of time no assurances that an API will be available forever. Blockchain.info changed their API (#1242) and now the Bitcoin senor can not be used.

@deisi
Copy link
Contributor Author

deisi commented Feb 21, 2016

Could it be that that you are no longer in your venv or have multiple installations of HA.

The situation is a bit complicated. I run HA on Arch Linux witch comes with python 3.5. I want to use Z-Wave. There is a bug in Z-Wave so I can not use python 3.5 and thus I use a virtual env with python 3.4 to run HA.
I used the default python3.5 to run /script/gen_requirements_all.py. I now tried to run the script from the virtual env with python3.4, but I get the same error.

Since I'm developing I run everything from the clone of my git repo, but there is also a pip installed version on the system. Is this the problem?

edit:
@fabaff okay I found it. The error was due to the two installations of HA. Now I get a new problem. gen_requirements_all.py tells me

******* ERROR
Errors while importing:  homeassistant.components.light.pswitch,
homeassistant.components.switch.pswitch
Make sure you import 3rd party libraries inside methods.

But I have nothing to to with a pswitch???

@fabaff okay, forget it my foo from old days got to solve this on my own

@deisi
Copy link
Contributor Author

deisi commented Feb 21, 2016

Can somebody help me with the reason why Travis still fails? I tells me:

Please run script/gen_requirements_all.py

ERROR: InvocationError: '/home/travis/build/balloob/home-assistant/.tox/requirements/bin/python script/gen_requirements_all.py validate'

___________________________________ summary ____________________________________

ERROR:   requirements: commands failed

but by now I can run the script/gen_requirements_all.py on my local machine.

@@ -153,6 +154,7 @@ omit =
homeassistant/components/thermostat/homematic.py
homeassistant/components/thermostat/proliphix.py
homeassistant/components/thermostat/radiotherm.py

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this blank line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay removed it

@deisi
Copy link
Contributor Author

deisi commented Feb 22, 2016

So I passed the checks :)
Now I have made a big mess with my pull request and I'm supposed to squash them. Problem is, I don't know how. A part of the work has been done on github within the browser and these changes are not in the branch of the fork that I created for the pull request in the first place. Any suggestions?

{'delay_departure': 0,
'delay_arrival': 0})
if delay['delay_departure'] != 0:
self._state += ''.join([' + ', str(delay['delay_departure'])])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be the most complex string concatenation possible in Python. Try this:

self._state += " + {}".format(delay['delay_departure'])

@balloob
Copy link
Member

balloob commented Feb 23, 2016

You can only squash commits on your computer. Check out the branch locally, use git pull to pull down the latest changes and use rebase to squash the commits. After that you'll have to force push to overwrite the multiple commits in this branch.

And if all else fails, follow this xkcd

@deisi
Copy link
Contributor Author

deisi commented Feb 23, 2016

👍 Okay, I follow this if it doesn't work.

Uses the (schiene)[https://pypi.python.org/pypi/schiene/0.14] API to communicate with the webserver of bahn.de
and pulls iformation about a specific connection from the (bahn.de)[http://www.bahn.de/p/view/index.shtml]
webpage. The departure time of the next train for the given connection is shown.
In case of delay, the delay is also shown. Additional `ATTRIBUTES` are used to
inform about e.g. the type of the train, price and if it is ontime.

Usage:

    sensor:
      platform: deutsche_bahn
        from: name_of_start_station
	  to: name_of_final_station

Problems:
I'm testing it for quite some time, but I have never seen the `ATTRIBUTES` in case
of a delayed train. The `ATTRIBUTES` are directly passed from the `schiene` API. So this
usecase has not been tested yet.

deutsche_bahn ist not supporting the `schiene` api unlike in the swiss_public_transport case.
It's not guaranteed that `schiene` will work forever, infact it can happen that Bahn AG will
intentionally brake the API at some point. In the past Bahn AG has not allways been very supportive
to the opensource community.
@deisi
Copy link
Contributor Author

deisi commented Feb 24, 2016

All suggestions are in and it is squashed. I think it can be merged now.

@balloob
Copy link
Member

balloob commented Feb 25, 2016

Nice! 🐬

balloob added a commit that referenced this pull request Feb 25, 2016
@balloob balloob merged commit dc02370 into home-assistant:dev Feb 25, 2016
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
@deisi deisi deleted the deutsche_bahn branch May 22, 2017 18:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants