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

Refactor NextBus integration to use new API #121133

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

ViViDboarder
Copy link
Contributor

@ViViDboarder ViViDboarder commented Jul 3, 2024

Adds back support for agencies no longer in the old API by updating py-nextbusnext ViViDboarder/py_nextbusnext@v1.0.2...v2.0.3 which is using a new, undocumented API.

Breaking change

This removes the messages, directions, and attribution attributes from the sensor. The new API doesn't provide these in the request response. messages now has it's own API and could be added as it's own sensor, but that would be another patch.

Some existing sensors may be broken today because of deprecated Agency names. This patch will not migrate them as the migration path is ambiguous. Setting up again should work though.

Proposed change

Upgrade py-nextbusnext to v2.0.3 to utilize new API.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

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

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

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@ViViDboarder
Copy link
Contributor Author

The failed test was a flake, not related to my changes.

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Jul 7, 2024
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Can you please elaborate on these 2 things:

  • Adds back support for removed agencies
  • This removes the messages, directions, and attribution attributes from the sensor. Those may be added back in the future with additional refactoring

So we removed agencies and will bring them back again, and we now remove attributes to introduce them again on a later moment in time?

We should not do that. We should keep the user experience consistent and not make the user update their config every once in a while for no reason.

@home-assistant home-assistant bot marked this pull request as draft July 8, 2024 08:24
@home-assistant
Copy link

home-assistant bot commented Jul 8, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label Jul 8, 2024
@ViViDboarder
Copy link
Contributor Author

I've updated the description to elaborate on those points, but in summary: The old, public API appears to be phasing out. Many agencies are now missing. Instead, a new, undocumented API is being used by the website for fetching predictions.

This means that many existing users are now unable to get predictions via the old client.

The old API provided additional information along with predictions, such as directions, messages, and attribution. These are not present via the new API. Both messages and full names of directions associated would be possible with additional API calls, however those don't seem appropriate to add to this sensor as attributes for several reasons:

  • Messages aren't stop specific, so an agency or route level sensor would be more appropriate
  • Since this is an unofficial API, making these requests in tandem poses more risk to look like abuse, especially given messages do not change frequently
  • Directions are now included when selecting the route, so this attribute does not provide much detail
  • Getting display names for directions would require an additional request, thus posing the same risk listed above for messages
  • Attribution is not included at all anymore, as this is an unofficial API

@ViViDboarder ViViDboarder marked this pull request as ready for review July 8, 2024 17:24
@home-assistant home-assistant bot requested a review from joostlek July 8, 2024 17:24
@home-assistant home-assistant bot marked this pull request as draft July 21, 2024 10:37
This removes the `messages`, `directions`, and `attribution` attributes
from the sensor. Those may be added back in the future with additional
refactoring.

Some existing sensors may be broken today because of deprecated Agency
names. This patch will not migrate them as the migration path is
ambiguous. Setting up again should work though.
@ViViDboarder ViViDboarder marked this pull request as ready for review July 22, 2024 21:13
@home-assistant home-assistant bot requested a review from joostlek July 22, 2024 21:13
@joostlek
Copy link
Member

Since you're doing a rewrite, consider using aiohttp to make the library async and nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NextBus] - Predictions are "Unkown" with "Error getting predictions: None" in logs
3 participants