-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
Add Entur departure information sensor #17286
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ATTR_EXPECTED_IN = 'due_in' | ||
ATTR_NEXT_UP_IN = 'next_due_in' | ||
|
||
API_CLIENT_ID = 'home-assistant' |
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.
So, all instances are going to use the same ID?
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.
The purpose of the client-name is for tracking of which applications are using the API, and are required for each request to the API to not get blocked from contacting the API. In other words it should be unique for the application and not the instance.
Translated from the norwegian only documentation:
ET-Client-Name
Description of the client that makes the request. Should be a value that describes the application that performs the API call. The value should include company / organization followed by dash and application name - "company-applicationName".
Source: https://www.entur.org/dev/api/header/
Changed the name of the const to reflect that its a name instead of id. Chose the name homeassistant-homeassistant
as "organization" and application name is the same for HA.
Does it sound reasonable?
Thanks.
if self._times[CONF_TRANSPORT_MODE] == 'air': | ||
return 'mdi:airplane' | ||
|
||
return 'mdi: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.
How about a dict lookup? Perhaps something like this:
ICONS = {'bus': 'mdi:bus', 'air': 'mdi:airplane', 'water': 'mdi:ferry'}
return [v for k, v in ICONS.items() if self._times[CONF_TRANSPORT_MODE] in k][0]
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 implemented the dict, but implemented the lookup through the dict.get
method with a default. I think this is easier to read and immediately understand the line of code. Hope that's OK.
Thanks.
def setUp(self): | ||
"""Initialize values for this testcase class.""" | ||
self.hass = get_test_home_assistant() | ||
self.config = VALID_CONFIG |
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.
Just use the constant directly. No need for the instance attribute.
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.
Looks good! @fabaff?
Great job! I would like to display the ferry timetables for NSR:StopPlace:58664. The problem is that this is also a stopplace for busses going in all directions. Not sure if this can be filtered by the Entur's GraphQL? If not, maybe add a filter to for-loop before adding the entities? The attached picture show that the route changes from "16-713 Flakk ferjekai" to "350 Rissa/Osen" on the next. I would like this sensor to only show the 16-713 route for current and next. For the "sensor.transport_rrvik_ferjekai_platform_71720". i'm not really sure whats going on, as the next ferry departure should be 09:30. The "next_due_at" time (09:25) is for the "350 Rissa/Osen" and not the "16-713 Rørvik ferjekai" as the sensor states. |
Please open an issue if you suspect a bug. If you want to suggest an enhancement please open a feature request in the Feature Requests section of our community forum. Merged PRs should not be used for enhancement discussion or bug reports. Thanks! |
Description:
Adding support for realtime departure information about public transport in Norway. Fetches timing information from the open api of entur once a minute to show how long before next bus, ferry, train or similar is leaving the station.
Long time user of home assistant here, and in the spirit of hacktoberfest i wanted to give a bit back to this awesome project! So first time contributing here and first time writing something proper in python, so be gentle with me. If something is not 100% correctly done or similar, its probably because I don't know better, and any tips are welcome!
Pull request in home-assistant.io with documentation: home-assistant/home-assistant.io#6643
Example entry for
configuration.yaml
:Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices: