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

Add config flow to NMBS #121548

Merged
merged 31 commits into from
Jan 11, 2025
Merged

Add config flow to NMBS #121548

merged 31 commits into from
Jan 11, 2025

Conversation

silamon
Copy link
Contributor

@silamon silamon commented Jul 8, 2024

Breaking change

Removes support for configuration by configuration.yml file.

The "name" and "station_live" options cannot longer be configured. The config flow will setup 2 disabled sensors for the "station_from" and "station_to" provided in the config flow. You can set a custom "name" after setting up the config flow.

Proposed change

Adds a config flow for nmbs integration. The configuration.yml had combined options allowing to specify a connection between 2 stations, additionally one can add a specific configuration option to have a sensor showing the next first departing train in a specific station.

The config flow only supports the "connection" and setups 2 disabled "liveboard" for the "from" and "to" sensors. Here is a overview:

configuration.yaml option description config flow type config flow parameter
station_from (required) The station where the connection departs. connection station_from
station_to (required) The station where the connection arrives. connection station_to
station_live (optional) Setting this will create another sensor to monitor the liveboard in a station. --
exclude_vias (optional, default: false) Setting this will not show connections for which you have to transfer to another station. connection exclude_vias
name (optional) Name to use in the frontend. --
show_on_map (optional, default: false) Show the station on the map. connection show_on_map

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.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Jul 8, 2024

Hey there @thibmaek, mind taking a look at this pull request as it has been labeled with an integration (nmbs) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of nmbs can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign nmbs Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@joostlek
Copy link
Member

joostlek commented Jul 8, 2024

Is the liveboard a current available feature?

@silamon
Copy link
Contributor Author

silamon commented Jul 8, 2024

Is the liveboard a current available feature?

Yes. By configuring the station live parameter in the configuration yaml you get the next train to depart as additional sensor.

homeassistant/components/nmbs/__init__.py Show resolved Hide resolved
homeassistant/components/nmbs/__init__.py Show resolved Hide resolved
homeassistant/components/nmbs/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/config_flow.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft August 10, 2024 14:00
@home-assistant
Copy link

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.

@silamon silamon marked this pull request as ready for review August 11, 2024 07:21
@home-assistant home-assistant bot requested a review from joostlek August 11, 2024 07:21
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.

Oh I still had some comments from a while back.

I still feel like liveboard shouldn't be its own entry and we can just combine that with the normal entry

homeassistant/components/nmbs/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/config_flow.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft September 8, 2024 10:41
@silamon silamon marked this pull request as ready for review November 23, 2024 09:01
@home-assistant home-assistant bot requested a review from joostlek November 23, 2024 09:01
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.

I am missing a test:

  • Where we try to setup an already set up entry that already exists, which should abort
  • Where do the same but then with importing

tests/components/nmbs/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/nmbs/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/nmbs/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/nmbs/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/nmbs/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/nmbs/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/nmbs/test_config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/nmbs/config_flow.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft December 17, 2024 17:17
@silamon silamon marked this pull request as ready for review December 21, 2024 15:21
@home-assistant home-assistant bot requested a review from joostlek December 21, 2024 15:21
@silamon
Copy link
Contributor Author

silamon commented Dec 21, 2024

Not clear at the moment if we can take updated unique ids right now, or later since now the localized names are used in the unique id.

@jcoetsie
Copy link

jcoetsie commented Jan 5, 2025

I did a test of this too.

Having a setup between station A and B and the same between station A and B but now also with vias does not work.

It says Location is already configured. The error is unclear, it must be more To/From combination already exists

This also means one cannot configure two sensors for both direct and indirect trains. Must we not create both OR allow both to be created? Should unique id not contain if it is with vias?

Another one is the functionality of the state of the sensor. Why do we keep duration? Isn't departure time including delays more relevant?

@silamon
Copy link
Contributor Author

silamon commented Jan 6, 2025

I did a test of this too.

Having a setup between station A and B and the same between station A and B but now also with vias does not work.

It says Location is already configured. The error is unclear, it must be more To/From combination already exists

This also means one cannot configure two sensors for both direct and indirect trains. Must we not create both OR allow both to be created? Should unique id not contain if it is with vias?

Another one is the functionality of the state of the sensor. Why do we keep duration? Isn't departure time including delays more relevant?

True that, that was a problem before as well as both would make the same sensor anyway. I will look into it.
Currently the functionality of the sensor is kept, not to make even more changes into already big pull request.

@joostlek
Copy link
Member

Maybe such thing can be solved with config sub entries, which might land soon

@joostlek joostlek merged commit b9259b6 into home-assistant:dev Jan 11, 2025
65 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants