Skip to content

Set station name as device name in GIOS#155741

Closed
mik-laj wants to merge 3 commits into
home-assistant:devfrom
mik-laj:gios-fix-3
Closed

Set station name as device name in GIOS#155741
mik-laj wants to merge 3 commits into
home-assistant:devfrom
mik-laj:gios-fix-3

Conversation

@mik-laj
Copy link
Copy Markdown
Contributor

@mik-laj mik-laj commented Nov 3, 2025

Breaking change

Proposed change

Previously, users could set custom device name using the Name field during configuration. This violates the guidelines, as the device name should be determined automatically and, if needed, the user can change it from the interface.

It is not breaking change, as we have migration that copy user-defined name from config entry to field name_by_user in device, but it is a forward-incompatible change.

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • 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.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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
Copy Markdown
Contributor

home-assistant Bot commented Nov 3, 2025

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

Code owner commands

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

@mik-laj
Copy link
Copy Markdown
Contributor Author

mik-laj commented Nov 3, 2025

@bieniu I'm wondering if it would be worth moving the code for other migrations to the async_migrate_entry method now so that this code doesn't run every time we setup entry. It is worth adding that we are bumping major version of config entry.

# We used to use int as config_entry unique_id, convert this to str.
if isinstance(entry.unique_id, int):
hass.config_entries.async_update_entry(entry, unique_id=str(station_id)) # type: ignore[unreachable]
# We used to use int in device_entry identifiers, convert this to str.
device_registry = dr.async_get(hass)
old_ids = (DOMAIN, station_id)
device_entry = device_registry.async_get_device(identifiers={old_ids}) # type: ignore[arg-type]
if device_entry and entry.entry_id in device_entry.config_entries:
new_ids = (DOMAIN, str(station_id))
device_registry.async_update_device(device_entry.id, new_identifiers={new_ids})

@mik-laj mik-laj marked this pull request as ready for review November 3, 2025 16:56
@mik-laj mik-laj requested a review from bieniu as a code owner November 3, 2025 16:56
Copilot AI review requested due to automatic review settings November 3, 2025 16:56
Copy link
Copy Markdown
Contributor

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 migrates the GIOS integration from user-configurable device names to automatically using station names from the API. The config entry is bumped from version 1 to version 2, with a migration path that preserves user-customized names.

Key changes:

  • Removes the CONF_NAME field from config flow and config entry data
  • Implements device name translation using the station name from the API
  • Adds config entry migration from v1 to v2 that preserves user-provided names in name_by_user

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
homeassistant/components/gios/init.py Adds async_migrate_entry function to migrate v1 config entries to v2, moving user-provided names to device.name_by_user
homeassistant/components/gios/config_flow.py Removes CONF_NAME field from config flow and bumps VERSION to 2
homeassistant/components/gios/sensor.py Updates GiosSensor to use translatable device names from API instead of CONF_NAME
homeassistant/components/gios/strings.json Adds device translation template for station names
tests/components/gios/init.py Updates test config entries to version 2 without CONF_NAME
tests/components/gios/test_config_flow.py Removes CONF_NAME from test config
tests/components/gios/test_init.py Adds migration test with parametrized scenarios and updates existing tests to version 2
tests/components/gios/test_sensor.py Updates entity IDs in tests to match new naming pattern
tests/components/gios/snapshots/test_sensor.ambr Updates snapshot entity IDs and friendly names
tests/components/gios/snapshots/test_diagnostics.ambr Updates diagnostic snapshot to version 2 without CONF_NAME

"homeassistant.components.gios.coordinator.Gios._get_indexes",
return_value=indexes,
),
):
Copy link
Copy Markdown
Contributor Author

@mik-laj mik-laj Nov 3, 2025

Choose a reason for hiding this comment

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

I'd like to avoid code duplication here, but I'll take care of that during the test refactor. See:
#155603 (comment)

@mik-laj mik-laj mentioned this pull request Nov 3, 2025
21 tasks
await init_integration(hass)

state = hass.states.get("sensor.home_pm2_5")
state = hass.states.get("sensor.station_test_name_1_pm2_5")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have a lot of changes in entity Ids in this PR, but that's okay because we don't change unique_id, so HA can still links entities

"""Config flow for GIOS."""

VERSION = 1
VERSION = 2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As we discussed, I don't like the idea of ​​incrementing the version for such a minor change and preventing users from downgrading if they need to. I'd try increasing only the minor_version.

@home-assistant home-assistant Bot marked this pull request as draft November 4, 2025 17:10
@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Nov 4, 2025

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.

@mik-laj mik-laj closed this Nov 5, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants