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

On-demand update of swiss public transport sensor #16723

Merged
merged 4 commits into from
Sep 20, 2018

Conversation

vikramgorla
Copy link
Contributor

@vikramgorla vikramgorla commented Sep 19, 2018

Description:

Changing Swiss Public Transport sensor to update it's values only when required (only after the train has crossed)

Related issue (if applicable): fixes #9012
(Linking to old issue as the issue has not dissapeared completely and this pull request is extension of previous fix to change it from 90 seconds to on-demand)
Closes home-assistant-ecosystem/python-opendata-transport#3

Checklist:

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

If the code does not interact with devices:

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

…has crossed).

Looking at the documentation on https://transport.opendata.ch/docs.html, delay information is available only on stationboard, so no need to query often if there is no "real"time info.
…catch client errors like throttling rejection (HTTP 429)
@fabaff fabaff changed the title on-demand update of swiss public transport sensor On-demand update of swiss public transport sensor Sep 20, 2018
Copy link
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

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

Thanks 🐦

sensor:
  - platform: swiss_public_transport
    name: Train
    from: Bern
    to: Biel

@fabaff fabaff merged commit fcb84d9 into home-assistant:dev Sep 20, 2018
@ghost ghost removed the in progress label Sep 20, 2018
@@ -111,7 +112,7 @@ def device_state_attributes(self):
ATTR_DEPARTURE_TIME2: self._opendata.connections[2]['departure'],
ATTR_START: self._opendata.from_name,
ATTR_TARGET: self._opendata.to_name,
ATTR_REMAINING_TIME: '{}'.format(remaining_time),
ATTR_REMAINING_TIME: '{}'.format(self._remaining_time),
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to store relative (to now) times in the state machine as they spam it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, it is an existing attribute. I don't use it / dont see a need for it - don't know what is the adoption.
Agree this does not necessarily be in state machine and can be calculated in a template only by whom who needs it.
Do you recommend deprecating this attribute?

Copy link
Member

Choose a reason for hiding this comment

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

I would say so yes. @fabaff do you agree?

@balloob balloob mentioned this pull request Sep 28, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants