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

Merged
merged 16 commits into from Nov 30, 2018

Conversation

@hfurubotten
Copy link
Contributor

hfurubotten commented Oct 9, 2018

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:

# Example configuration.yaml entry
sensor:
  - platform: entur_public_transport
    stop_ids:
      - 'NSR:StopPlace:548'   # Bergen train station
      - 'NSR:StopPlace:737'   # Trondheim airport
      - 'NSR:StopPlace:5850'  # Grorud T bus stop
      - 'NSR:StopPlace:58652' # Mortavika ferry 
      - 'NSR:StopPlace:27639' # Sør-Hidle quay 
      - 'NSR:Quay:48550'      # Fiskepiren bus stop platform 1

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.
@homeassistant

This comment was marked as resolved.

Copy link

homeassistant commented Oct 9, 2018

Hello @hfurubotten,

When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es).

The commits that are missing a linked GitHub account are the following:

Unfortunately, we are unable to accept this pull request until this situation is corrected.

Here are your options:

  1. If you had an email address set for the commit that simply wasn't linked to your GitHub account you can link that email now and it will retroactively apply to your commits. The simplest way to do this is to click the link to one of the above commits and look for a blue question mark in a blue circle in the top left. Hovering over that bubble will show you what email address you used. Clicking on that button will take you to your email address settings on GitHub. Just add the email address on that page and you're all set. GitHub has more information about this option in their help center.

  2. If you didn't use an email address at all, it was an invalid email, or it's one you can't link to your GitHub, you will need to change the authorship information of the commit and your global Git settings so this doesn't happen again going forward. GitHub provides some great instructions on how to change your authorship information in their help center.

    • If you only made a single commit you should be able to run
      git commit --amend --author="Author Name <email@address.com>"
      
      (substituting Author Name and email@address.com for your actual information) to set the authorship information.
    • If you made more than one commit and the commit with the missing authorship information is not the most recent one you have two options:
      1. You can re-create all commits missing authorship information. This is going to be the easiest solution for developers that aren't extremely confident in their Git and command line skills.
      2. You can use this script that GitHub provides to rewrite history. Please note: this should be used only if you are very confident in your abilities and understand its impacts.
    • Whichever method you choose, I will come by to re-check the pull request once you push the fixes to this branch.

We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community.

Thanks, I look forward to checking this PR again soon! ❤️

@homeassistant

This comment was marked as resolved.

Copy link

homeassistant commented Oct 9, 2018

Hi @hfurubotten,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@homeassistant homeassistant added cla-signed and removed cla-needed labels Oct 9, 2018

@bachya bachya added the Hacktoberfest label Oct 9, 2018

@hfurubotten hfurubotten referenced this pull request Oct 9, 2018

Merged

Documentation for entur public transport sensor #6643

2 of 2 tasks complete

@hfurubotten hfurubotten force-pushed the hfurubotten:dev branch from 39eaa72 to fb51e81 Oct 10, 2018

@hfurubotten hfurubotten changed the title Added Entur departure information sensor. Add Entur departure information sensor. Oct 10, 2018

Show resolved Hide resolved homeassistant/components/sensor/entur_public_transport.py Outdated
ATTR_EXPECTED_IN = 'due_in'
ATTR_NEXT_UP_IN = 'next_due_in'

API_CLIENT_ID = 'home-assistant'

This comment has been minimized.

@fabaff

fabaff Nov 12, 2018

Member

So, all instances are going to use the same ID?

This comment has been minimized.

@hfurubotten

hfurubotten Nov 13, 2018

Contributor

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.

Show resolved Hide resolved homeassistant/components/sensor/entur_public_transport.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/entur_public_transport.py Outdated
if self._times[CONF_TRANSPORT_MODE] == 'air':
return 'mdi:airplane'

return 'mdi:bus'

This comment has been minimized.

@fabaff

fabaff Nov 12, 2018

Member

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]

This comment has been minimized.

@hfurubotten

hfurubotten Nov 13, 2018

Contributor

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.

Show resolved Hide resolved homeassistant/components/sensor/entur_public_transport.py Outdated

@MartinHjelmare MartinHjelmare changed the title Add Entur departure information sensor. Add Entur departure information sensor Nov 13, 2018

def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Nov 13, 2018

Member

Just use the constant directly. No need for the instance attribute.

@MartinHjelmare
Copy link
Member

MartinHjelmare left a comment

Looks good! @fabaff?

hfurubotten added some commits Oct 9, 2018

@hfurubotten hfurubotten force-pushed the hfurubotten:dev branch from ac5f7e4 to 8dd85d8 Nov 14, 2018

@fabaff

fabaff approved these changes Nov 29, 2018

@fabaff fabaff merged commit 4bee3f7 into home-assistant:dev Nov 30, 2018

5 checks passed

Hound No violations found. Woof!
WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.1%) to 92.929%
Details

@wafflebot wafflebot bot removed the in progress label Nov 30, 2018

mxworm added a commit to mxworm/home-assistant that referenced this pull request Dec 1, 2018

Merge branch 'dev' of https://github.com/home-assistant/home-assistant
…into dev

* 'dev' of https://github.com/home-assistant/home-assistant: (122 commits)
  Reintroduce unique_id for Netatmo sensor (home-assistant#18774)
  Fix ordinal filter in template (home-assistant#18878)
  fixed state case for rtorrent (home-assistant#18778)
  Updated UVC camera component to support SSL connections (home-assistant#18829)
  Added new filters for templates (home-assistant#18125)
  Add support for zha device registry (home-assistant#18755)
  Add tests for directv platform (home-assistant#18590)
  Fix issues with 17track.net sensor names (home-assistant#18860)
  Bump py17track to 2.1.1 (home-assistant#18861)
  RFC: Call services directly (home-assistant#18720)
  Fix flaky geofency test (home-assistant#18855)
  Update of volvooncall component (home-assistant#18702)
  Always set hass_user (home-assistant#18844)
  Hotfix for Fibaro wall plug (home-assistant#18845)
  Add services description (home-assistant#18839)
  update netatmo library (home-assistant#18823)
  Revert change to MQTT discovery_hash introduced in home-assistant#18169 (home-assistant#18763)
  bump gtts-token to 1.1.3 (home-assistant#18824)
  Add Entur departure information sensor (home-assistant#17286)
  Bump python_awair to 0.0.3 (home-assistant#18819)
  ...

@balloob balloob referenced this pull request Dec 12, 2018

Merged

0.84 #19215

@dico

This comment has been minimized.

Copy link

dico commented Dec 21, 2018

Great job!
Is it or should it be possible to filter route/transport-type?

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.

ha_sensors_02

@MartinHjelmare

This comment has been minimized.

Copy link
Member

MartinHjelmare commented Dec 21, 2018

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!

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Dec 21, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.