-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Ask for PIN in Husqvarna Automower BLE integration #135440
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
Ask for PIN in Husqvarna Automower BLE integration #135440
Conversation
d7a234e
to
86f32fd
Compare
There was a problem hiding this 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?
homeassistant/components/husqvarna_automower_ble/config_flow.py
Outdated
Show resolved
Hide resolved
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
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:
|
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 |
0f7f606
to
6b8fb29
Compare
I have updated this to use the reauth flow and updated the tests to ensure 100% test coverage on the new flow |
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 |
There was a problem hiding this 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
a32271c
to
4188264
Compare
There was a problem hiding this 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 |
homeassistant/components/husqvarna_automower_ble/config_flow.py
Outdated
Show resolved
Hide resolved
homeassistant/components/husqvarna_automower_ble/config_flow.py
Outdated
Show resolved
Hide resolved
"pin": "Mower PIN" | ||
}, | ||
"data_description": { | ||
"pin": "The PIN used to secure the mower" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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 = "-" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
@CFenner I'm not sure |
There was a problem hiding this 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>
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.
But pairing mode is probably never needed when just confirming the PIN.
|
Sounds good to me. It all looks good to me as well |
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
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: