Skip to content

Conversation

@allenporter
Copy link
Contributor

Proposed change

Fix a bug in rainbird device migration that results in additional devices when the serial number is zero. The new check prevents migration when the device id is already in the correct format. Adds a test that was able to reproduce the issue before fixing.

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

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

Code owner commands

Code owners of rainbird 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 rainbird 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 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 fixes a bug in the rainbird device migration logic that creates duplicate devices when the serial number is zero and the MAC address has a leading zero. The fix prevents migration when device IDs are already in the correct format by checking if the unique_id starts with the MAC address before attempting migration.

Key changes:

  • Adds a check to skip migration if the device ID already uses the MAC address format
  • Includes a comprehensive test case that reproduces the issue with a serial number of "0" and a MAC address starting with "01"

Reviewed Changes

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

File Description
homeassistant/components/rainbird/__init__.py Adds logic to skip migration when device ID is already in correct MAC address format
tests/components/rainbird/test_init.py Adds test case to verify fix for duplicate device creation during reload with zero serial number
Comments suppressed due to low confidence (1)

tests/components/rainbird/test_init.py:454

  • The test function name 'test_reload_migration_with_leading_zero_mac' is misleading. The test is actually about preventing duplicate devices when serial number is zero, not specifically about leading zeros in MAC addresses. Consider renaming to 'test_migration_prevents_duplicates_with_zero_serial' or similar.
async def test_reload_migration_with_leading_zero_mac(

@allenporter allenporter added this to the 2025.7.3 milestone Jul 19, 2025
@zweckj zweckj merged commit 2577d9f into home-assistant:dev Jul 19, 2025
34 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 20, 2025
@joostlek joostlek modified the milestones: 2025.7.3, 2025.7.4 Jul 21, 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.

Rainbird devices being duplicated on every reload

5 participants