Skip to content

Conversation

alistair23
Copy link
Contributor

Breaking change

The integration now requires the AutoMower PIN when being setup. This ensure Home Assistant can communicate with more models of Mowers and with higher security levels.

Proposed change

All Automowers are setup with a 4 digit PIN. Depending the the model of the Automower and the security level set on the device by the user the PIN is required at boot and when performing certain operations.

The current Home Assistant integration doesn't require a PIN. It seems like higher security levels or certain models always require a PIN though. So the integration currently doesn't work for all models or configurations.

As such, let's request a PIN from users when setting up the integration so that we can use that for communicating with the mower. This should make the integration more robust for a range of different models and security levels as we can send the PIN as part of the BLE setup.

Fixes: #131321

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:

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

So why do we need this now and what happens to the old config entry data for people who already have this set up?

@home-assistant home-assistant bot marked this pull request as draft January 13, 2025 11:48
@home-assistant
Copy link

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.

@joostlek
Copy link
Member

Oh I read the description now (bad habit lol).

So I think instead of marking this a breaking change and have people setup their device again, let's create a way to update their configuration. There are 2 ways to do this and I need some more information about the PIN to know which one makes more sense:

  1. Reauth flow, where we ask the user to reauthenticate with the device, so the user can put in the PIN. Benefit of this is that we can have everyone set the PIN or the integration does not work (as in, that is not a benefit, but it does what it should without adding a lot of if CONF_PIN in entry.data for when you add more features in the future that require that PIN. But my question here would be, can the PIN change?
  2. A repair flow, where we kindly ask the user to provide a PIN and then just keep working like before. More graceful, but harder to maintain.

@joostlek joostlek changed the title components/husqvarna_automower_ble: Support PIN Ask for PIN in Husqvarna Autmower BLE integration Jan 13, 2025
@joostlek
Copy link
Member

Someone just told me that the PIN can be changed, so I would recommend using a reauth flow to allow the user to provide the new PIN

@alistair23 alistair23 force-pushed the alistair/husqvarna-pin branch 5 times, most recently from 0f7f606 to 6b8fb29 Compare February 18, 2025 12:51
@alistair23 alistair23 marked this pull request as ready for review February 18, 2025 12:58
@home-assistant home-assistant bot requested a review from joostlek February 18, 2025 12:58
@alistair23
Copy link
Contributor Author

I have updated this to use the reauth flow and updated the tests to ensure 100% test coverage on the new flow

@tim-devel
Copy link

Happy to test these changes if that helps. Spring is coming and my mower doesn't work until this change is merged. Would be great to have this merged for the April release! Thanks @alistair23

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

There were also other open comments

@home-assistant home-assistant bot marked this pull request as draft March 17, 2025 07:59
@alistair23 alistair23 force-pushed the alistair/husqvarna-pin branch 3 times, most recently from a32271c to 4188264 Compare March 19, 2025 11:04
@alistair23 alistair23 marked this pull request as ready for review March 19, 2025 11:15
@home-assistant home-assistant bot requested a review from joostlek March 19, 2025 11:15
@emontnemery emontnemery marked this pull request as ready for review August 21, 2025 13:03
@Copilot Copilot AI review requested due to automatic review settings August 21, 2025 13:03
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 adds PIN support to the Husqvarna Automower BLE integration, making it a breaking change that requires users to provide a 4-digit PIN when setting up the integration. This change enables Home Assistant to communicate with more Automower models and security configurations that require PIN authentication.

Key Changes

  • Added PIN requirement to config flow with validation for 4-digit numeric format
  • Updated setup logic to handle PIN authentication and throw appropriate errors for invalid PINs
  • Enhanced test coverage for PIN validation, authentication failures, and reauth flows

Reviewed Changes

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

Show a summary per file
File Description
homeassistant/components/husqvarna_automower_ble/config_flow.py Major refactor to add PIN collection, validation, and authentication in user, Bluetooth, and reauth flows
homeassistant/components/husqvarna_automower_ble/__init__.py Updated setup to require PIN, pass it to Mower constructor, and handle authentication failures
homeassistant/components/husqvarna_automower_ble/strings.json Added PIN-related form fields, descriptions, and error messages
tests/components/husqvarna_automower_ble/test_config_flow.py Comprehensive test updates covering PIN validation, authentication errors, and flow scenarios
tests/components/husqvarna_automower_ble/test_init.py Added tests for missing PIN migration and invalid PIN handling
tests/components/husqvarna_automower_ble/conftest.py Updated mock config entry to include PIN field

"pin": "Mower PIN"
},
"data_description": {
"pin": "The PIN used to secure the mower"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"pin": "The PIN used to secure the mower"
"pin": "The PIN which has been set in the app's security settings."

"""Initialize the config flow."""
self.address: str | None
address: str | None = None
mower_name: str = "-"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a case when this default is used? I would rather suggest to use the ble address in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

The way the integration works now, this is used when first starting the discovery or user flows. I think it would be better to use the name in the BLE advertisement as name, but changing that is for another PR probably.

Agreed using the address is better 👍

@emontnemery
Copy link
Contributor

@CFenner I'm not sure The PIN which has been set in the app's security settings is necessarily an improvement, I think The PIN used to secure the mower is clear?

Copy link
Contributor

@CFenner CFenner left a comment

Choose a reason for hiding this comment

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

👍

Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
@emontnemery emontnemery removed the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Aug 22, 2025
@emontnemery
Copy link
Contributor

The reauth flow was not using the stored channel id, which was why the mower had to be in pairing mode when validating the PIN.
That's fixed in the latest commit, but maybe the text in the reauth flow should be adjusted.
It's now like this:

Please confirm the PIN for {name}.\nMake sure the mower is in pairing mode and the PIN is correct.

But pairing mode is probably never needed when just confirming the PIN.
Should we just shorten like this?

Please confirm the PIN for {name}.

@alistair23
Copy link
Contributor Author

The reauth flow was not using the stored channel id, which was why the mower had to be in pairing mode when validating the PIN. That's fixed in the latest commit, but maybe the text in the reauth flow should be adjusted. It's now like this:

Please confirm the PIN for {name}.\nMake sure the mower is in pairing mode and the PIN is correct.

But pairing mode is probably never needed when just confirming the PIN. Should we just shorten like this?

Please confirm the PIN for {name}.

Sounds good to me. It all looks good to me as well

@joostlek joostlek merged commit 6e45713 into home-assistant:dev Aug 27, 2025
34 checks passed
@alistair23 alistair23 deleted the alistair/husqvarna-pin branch August 27, 2025 10:53
@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 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.

Cant connect to Gardena Sileno City 250