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

Handle missing or incorrect device name and unique id for ESPHome during manual add #95678

Merged
merged 11 commits into from
Jul 2, 2023

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jul 1, 2023

Proposed change

upstream changelog: esphome/aioesphomeapi@v15.0.1...v15.1.1

If we did not have the device name during setup we could never get the key from the dashboard. The device will send us its name if we try encryption which allows us to find the right key from the dashboard.

When the unique id was configured manually it would be uppercase, but zeroconf would discovery it lower case which would mean you could set up the same device multiple times and things would break.

This should help get users unstuck (this is common when users are using the device across subnets / remote / no mdns ) when they change the key and cannot get the device back online after deleting and trying to set it up again manually because they have trouble finding the right key.

This also brings the config flow coverage to 100%

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:

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 Black (black --fast 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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

If we did not have the device name during setup we could never
get the key from the dashboard. The device will send us
its name if we try encryption which allows us to find the
right key from the dashboard.

This should help get users unstuck when they change the key
and cannot get the device back online after deleting and
trying to set it up again manually
@home-assistant
Copy link

home-assistant bot commented Jul 1, 2023

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

Code owner commands

Code owners of esphome 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 esphome Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@bdraco bdraco changed the title Handle incorrect or missing device name for ESPHome noise encryption Handle incorrect or missing device name for ESPHome noise encryption during manual add Jul 1, 2023
@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

needs another round of functional testing

@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

Something isn't working right with preventing multiple of the same device.

Nothing is stopping my from setting it up twice

@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

That explains all the issues with conflicting devices

@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

the user step never sets the unique id 🤦

@bdraco bdraco added this to the 2023.7.0 milestone Jul 1, 2023
@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

Let's get that fixed

@bdraco bdraco changed the title Handle incorrect or missing device name for ESPHome noise encryption during manual add Handle missing device name and unique id for ESPHome noise encryption during manual add Jul 1, 2023
@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

I think self._device_info.mac_address probably needs to go through format_mac

@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

doesn't seem to be the problem... so something outside esphome maybe

@bdraco bdraco changed the title Handle missing device name and unique id for ESPHome noise encryption during manual add Handle missing device name for ESPHome noise encryption during manual add Jul 1, 2023
@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

nope that is the problem the zeroconf one is lowercase and the device info is upper case

@bdraco bdraco changed the title Handle missing device name for ESPHome noise encryption during manual add Handle missing device name and unique id for ESPHome during manual add Jul 1, 2023
@bdraco bdraco changed the title Handle missing device name and unique id for ESPHome during manual add Handle missing or incorrect device name and unique id for ESPHome during manual add Jul 1, 2023
@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

It was hard to find the issue because we have this code which fixes it after it sets up the dupe

            # Migrate config entry to new unique ID if necessary
            # This was changed in 2023.1
            if entry.unique_id != format_mac(device_info.mac_address):
                hass.config_entries.async_update_entry(
                    entry, unique_id=format_mac(device_info.mac_address)
                )

@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

opened esphome/esphome#5034 to start advertising if encryption is on so we don't have to probe.

Thats for the future though

@bdraco bdraco marked this pull request as ready for review July 1, 2023 20:31
@bdraco
Copy link
Member Author

bdraco commented Jul 1, 2023

Now I know how I broke my production system in testing a few months ago 🤦

@balloob balloob merged commit f0cb03e into dev Jul 2, 2023
@balloob balloob deleted the fix_device_name_esphome branch July 2, 2023 14:29
balloob pushed a commit that referenced this pull request Jul 3, 2023
…ing manual add (#95678)

* Handle incorrect or missing device name for ESPHome noise encryption

If we did not have the device name during setup we could never
get the key from the dashboard. The device will send us
its name if we try encryption which allows us to find the
right key from the dashboard.

This should help get users unstuck when they change the key
and cannot get the device back online after deleting and
trying to set it up again manually

* bump lib to get name

* tweak

* reduce number of connections

* less connections when we know we will fail

* coverage shows it works but it does not

* add more coverage

* fix test

* bump again
@github-actions github-actions bot locked and limited conversation to collaborators Jul 4, 2023
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.

4 participants