Repository navigation
fix: normalise username case before Cognito login - #179
Conversation
Hive's Cognito pool treats the email as case-sensitive, so a capitalised address (for example from mobile autocapitalisation) fails with HiveInvalidPassword even though the account exists. Store the username trimmed and lower-cased via a property on both auth classes, so the constructor and start_session's reassignment from the Home Assistant config entry are both covered. Fixes home-assistant/core#185593 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #179 +/- ##
======================================
Coverage ? 99.96%
======================================
Files ? 30
Lines ? 2655
Branches ? 310
======================================
Hits ? 2654
Misses ? 0
Partials ? 1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
🤖 Claude Code ReviewVerdict: looks good, no blocking issues. Lower-casing and trimming the username in both auth classes is consistent and tested. Bugs: none found. Minor
Home Assistant check: I fetched Not reviewed: I did not run the test suite. The Codecov report shows the changed lines are covered. Automated review by Claude Code · workflow run |
Problem
home-assistant/core#185593: Hive login fails if the email is typed with any capital letter, for example when the iOS app autocapitalises the first letter. Hive's Cognito pool treats the username as case-sensitive and answers with
NotAuthorizedException, which surfaces asHiveInvalidPassword.Home Assistant only partly works around this.
config_flow.pylower-cases the username for the flow's ownAuth(...):but
self.data.update(user_input)keeps the typed value, and that is what is saved in the config entry. On every start,__init__.pypasses the entry to the library:and
start_sessioncopies it straight onto the auth object (self.auth.username = config["username"]), so any later password or device login uses the capitalised address and fails.Fix
HiveAuthAsyncandHiveAuthnow exposeusernameas a property whose setter stores the value trimmed and lower-cased. This covers both the constructor and the reassignment instart_session, with no Home Assistant change needed. File mode (use@file.com) is detected regardless of case as a side effect.Verification
Live, against a real Hive account with saved device credentials:
HiveInvalidPasswordHiveInvalidPasswordtests/unit/test_hive_auth_async.pyandtests/unit/test_hive_auth.pycover the constructor, reassignment, theUSERNAMEsent toInitiateAuth, and file-mode detection.PLR0917hits are pre-existing on untouched lines and also appear ondev..secrets.baselineupdated because the new property shifts an allowlisted line inhive_auth_async.py.Home Assistant impact
No public API change.
Auth,startSessionand the exceptions raised are unchanged, and nothing in the integration readsauth.usernameback. Checkedhomeassistant/components/hive/config_flow.pyand__init__.pyondev.🤖 Generated with Claude Code