8000 SMA add DHCP strictness by erwindouna · Pull Request #145753 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

SMA add DHCP strictness #145753

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

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

Conversation

erwindouna
Copy link
Contributor
@erwindouna erwindouna commented May 8000 27, 2025

Breaking change

Proposed change

Potential bugfix for #145024
This needs some testing during the Beta week, so let's hope we have some volunteers - DHCP testing is hard on DEV.

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

  • 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 @kellerza, @rklomp, mind taking a look at this pull request as it has been labeled with an integration (sma) you are listed as a code owner for? Thanks!

Code owner commands

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

@erwindouna
Copy link
Contributor Author

Note: don't review or merge this yet, since it's used for a custom component and people can help to check if this works. :)

@jbouwh
Copy link
Contributor
jbouwh commented May 28, 2025

If an existing entry is in capitals, this change might lead to a duplicate config entry. So may be we should check if there are existing entries for the mac address?

@erwindouna
Copy link
Contributor Author
erwindouna commented May 28, 2025

If an existing entry is in capitals, this change might lead to a duplicate config entry. So may be we should check if there are existing entries for the mac address?

In the end that is what we want to achieve, we're currently checking on the unique_id only. What I noticed yesterday, was that my inverter, who was installed in 2024, with unique_id 123456 (this is normally the serial number) and the same inverter was found and when creating on the 27th of May of 2025, it got unique_id sma123456. Same MAC address. So apparently it comes in with lower case.
Maybe the self._async_abort_entries_match({CONF_MAC: self._discovery_data[CONF_MAC]}) should be introduced, prior to the unique_id check?

@jbouwh
Copy link
Contributor
jbouwh commented May 28, 2025

If an existing entry is in capitals, this change might lead to a duplicate config entry. So may be we should check if there are existing entries for the mac address?

In the end that is what we want to achieve, we're currently checking on the unique_id only. What I noticed yesterday, was that my inverter, who was installed in 2024, with unique_id 123456 (this is normally the serial number) and the same inverter was found and when creating on the 27th of May of 2025, it got unique_id sma123456. Same MAC address. So apparently it comes in with lower case. Maybe the self._async_abort_entries_match({CONF_MAC: self._discovery_data[CONF_MAC]}) should be introduced, prior to the unique_id check?

It would help to avoid duplicate entries I guess.

@jbouwh
Copy link
Contributor
jbouwh commented May 28, 2025

May be we can update an existing entry with the Mac address if the unique ID matches?
I have done something similar for inconform

@erwindouna
Copy link
Contributor Author

May be we can update an existing entry with the Mac address if the unique ID matches? I have done something similar for inconform

Like here? https://github.com/erwindouna/ha-core/blob/1a44472a0329f4e80e03b6f7cac5f4272e94cc44/homeassistant/components/incomfort/config_flow.py#L121

@erwindouna
Copy link
Contributor Author

This has been confirmed as a fix. Let's await a few more users' responses.

@erwindouna erwindouna marked this pull request as ready for review May 28, 2025 09:35
@erwindouna erwindouna requested a review from kellerza as a code owner May 28, 2025 09:35
@jbouwh
Copy link
Contributor
jbouwh commented May 28, 2025

Can we add a test for the new code? Also include a case where some an old entry exists and is to be converted to a dynamical host.


# Manual installations not always provide a MAC address
# This is the first gatekeeper to avoid duplicates
self._async_abort_entries_match({CONF_HOST: self._discovery_data[CONF_HOST]})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be removed in a next iteration.

if serial_number.startswith("sma"):
serial_number = serial_number.removeprefix("sma")
serial_number = serial_number.split("-", 1)[0]
await self.async_set_unique_id(serial_number)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a migration needed for all the existing entries that may have a dash in their unique ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first glance it doesn't look like it. The manual setup entries have been configured without the "sma" prefix and the dash.
I am not 100% familiar with the exact range of serial numbers, nor can I find the proper information - it's as bit on reverse engineering and what I can find in pyama.

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.

4 participants
0