Skip to content

Conversation

heindrichpaul
Copy link

@heindrichpaul heindrichpaul commented Sep 2, 2025

Breaking change

YAML configuration for Nederlandse Spoorwegen is now deprecated and will be removed in a future release. The integration automatically migrates existing YAML configuration and creates repair notifications to guide users. To complete the migration:

  1. Remove the nederlandse_spoorwegen: section from your configuration.yaml
  2. Remove any sensor: entries with platform: nederlandse_spoorwegen
  3. Restart Home Assistant to clear the repair notifications

Your existing routes and settings are automatically preserved in the new UI-based configuration.

Proposed change

This PR modernizes the Nederlandse Spoorwegen integration by implementing a complete config flow with options management, replacing the legacy YAML configuration system. Key improvements include:

  • Config Flow Implementation: Full UI-based configuration with validation
  • Options Flow: Runtime route management without restart requirements
  • Data Coordinator Pattern: Centralized data fetching with proper error handling
  • YAML Migration Support: Automatic import of existing YAML configuration with repair notifications
  • Enhanced Error Handling: Better user feedback for connection and authentication issues
  • Improved UX: Proper selector widgets for station selection and time formats
  • Code Quality: Comprehensive test coverage (152 tests, 74% coverage) and Home Assistant standards compliance

The integration automatically imports existing YAML configuration, so users experience no disruption to their existing sensors and automations.

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:

heindrichpaul and others added 30 commits June 27, 2025 07:09
…chpaul/core into feature/improving_NS_integration
…ng and remove quality scale file, Will create another PR to add this
Co-authored-by: Norbert Rittel <norbert@rittel.de>
Removed duplications

Co-authored-by: Norbert Rittel <norbert@rittel.de>
- Implement unit tests for the init module, covering setup and unload entry success and failure scenarios.
- Create tests for repair notifications to ensure proper issue creation during platform and integration migration.
- Add comprehensive tests for the sensor platform, including various scenarios for trip data and attributes.
- Introduce utility tests for validation functions, time formatting, and station cache validation.
- Implement unit tests for the init module, covering setup and unload entry success and failure scenarios.
- Create tests for repair notifications to ensure proper issue creation during platform and integration migration.
- Add comprehensive tests for the sensor platform, including various scenarios for trip data and attributes.
- Introduce utility tests for validation functions, time formatting, and station cache validation.

Signed-off-by: Heindrich Paul <heindrich.paul@gmail.com>
…eindrichpaul/core into feature/ns-config-flow-and-coordinator

Signed-off-by: Heindrich Paul <heindrich.paul@gmail.com>
@Copilot Copilot AI review requested due to automatic review settings September 2, 2025 09:40
@heindrichpaul heindrichpaul requested a review from a team as a code owner September 2, 2025 09:40
@home-assistant
Copy link

home-assistant bot commented Sep 2, 2025

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

Code owner commands

Code owners of nederlandse_spoorwegen 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 nederlandse_spoorwegen 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.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modernizes the Nederlandse Spoorwegen integration by implementing a complete config flow with UI-based configuration, replacing the legacy YAML configuration system. The integration moves from legacy to Bronze quality scale with comprehensive test coverage and modern Home Assistant standards compliance.

Key improvements include:

  • Config flow implementation with proper UI-based setup and options flow for route management
  • Data coordinator pattern with centralized data fetching and error handling
  • Automatic YAML migration with repair notifications to guide users through the transition

Reviewed Changes

Copilot reviewed 23 out of 25 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
homeassistant/components/nederlandse_spoorwegen/__init__.py Complete rewrite implementing config flow setup, YAML migration support, and repair issue management
homeassistant/components/nederlandse_spoorwegen/api.py New API wrapper with proper error handling and station data management
homeassistant/components/nederlandse_spoorwegen/config_flow.py New config flow implementation with user setup, import flow, and options management
homeassistant/components/nederlandse_spoorwegen/coordinator.py New data update coordinator with centralized data fetching and validation
homeassistant/components/nederlandse_spoorwegen/sensor.py Rewritten to use coordinator pattern instead of legacy platform setup
homeassistant/components/nederlandse_spoorwegen/utils.py New utility functions for validation, normalization, and data handling
homeassistant/components/nederlandse_spoorwegen/const.py Constants definition for the integration
homeassistant/components/nederlandse_spoorwegen/strings.json Localization strings for UI elements and error messages
homeassistant/components/nederlandse_spoorwegen/manifest.json Updated to Bronze quality scale with config flow support
homeassistant/components/nederlandse_spoorwegen/quality_scale.yaml Bronze tier compliance documentation
tests/components/nederlandse_spoorwegen/ Comprehensive test suite with 74% coverage across all modules
script/hassfest/quality_scale.py Removed integration from exemption list for Bronze requirements
requirements_test_all.txt Added nsapi dependency for testing
CODEOWNERS Added additional codeowner for the integration
Comments suppressed due to low confidence (1)

homeassistant/components/nederlandse_spoorwegen/coordinator.py:1

  • Remove the comment on line 62. Inline comments like this that explain basic usage are unnecessary noise in production code. The parameter name and context make its purpose clear.
"""Data update coordinator for Nederlandse Spoorwegen integration."""

Copy link
Member

@abmantis abmantis left a comment

Choose a reason for hiding this comment

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

Thanks for modernizing this integration!
Since this is quite a big PR, I would suggest splitting this up into smaller PRs. For example:

  • Adding tests for the current version
  • Adding the config flow and import flow
  • Adding the coordinator
  • Add the quality scale
  • ...

That will help getting this modernization in, since those smaller PRs are much easier to review :)

@heindrichpaul
Copy link
Author

Thanks for modernizing this integration! Since this is quite a big PR, I would suggest splitting this up into smaller PRs. For example:

  • Adding tests for the current version
  • Adding the config flow and import flow
  • Adding the coordinator
  • Add the quality scale
  • ...

That will help getting this modernization in, since those smaller PRs are much easier to review :)

Thanks for the comment and review. I am currently working on this PR while staying in contact with @joostlek

@heindrichpaul
Copy link
Author

When an user with an existing config updates he/she will be greeted with this repair notification
Screenshot 2025-09-03 at 13 33 13

Screenshot 2025-09-03 at 13 33 19

The integration would also migrate their existing routes to the new sub-entries. As seen below.
Screenshot 2025-09-03 at 13 32 10

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.

3 participants