Repository navigation
fix: record token_created after device login - #175
matt-thepie wants to merge 3 commits into
Conversation
device_login() returned the AuthenticationResult without storing it, so auth.token_created stayed None and get_device_data() reported no issue time after a device login. The session then fell back to the epoch default for token_created and treated every start as an expired token (issue Pyhass#123). login() and sms_2fa() already go through _store_auth_result(); device_login() now does the same. Verified live: after a device login, start_session with the four-value device_data from get_device_data() now starts with the real expiry and performs no startup refresh. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #175 +/- ##
======================================
Coverage ? 99.96%
======================================
Files ? 30
Lines ? 2645
Branches ? 311
======================================
Hits ? 2644
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:
|
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
🤖 Claude Code ReviewLooks good: Bugs: none. Minor: Tests: the new test covers Project rules: only async source is changed, with no sync edits, no logging of tokens, and no data fixtures. The Home Assistant check: I fetched Not reviewed: I didn't run the test suite locally. Automated review by Claude Code · workflow run |
Summary
device_login()returned theAuthenticationResultwithout storing it, soauth.token_createdstayedNoneandget_device_data()reported no issue time after a device login. The session then fell back to the epoch default fortoken_createdand treated every start as an expired token.login()andsms_2fa()already go through_store_auth_result();device_login()now does the same.Part of #123. The two bugs reported there are already addressed on
dev(the forced refresh after_retry_loginis gone, andstart_sessionaccepts a fourthdevice_datavalue carryingtoken_created), but that fourth value wasNonewhenever the tokens came from a device login, which is every reauth and every library user following the README. This closes that gap.Home Assistant
Checked
homeassistant/components/hive/config_flow.pyand__init__.pyondev. The config flow storesself.data["device_data"] = await self.hive_auth.get_device_data()andself.data["tokens"] = self.tokens, and__init__.pypassesdict(entry.data)tostartSession. HA's first setup goes throughlogin()andsms_2fa(), which already recordtoken_created; this change makes the stored value correct on the device-login path too. No HA code callsdevice_logindirectly, and no return shape changes.Live verification
Against a real account, simulating an HA restart that reloads a JSON-serialised config entry:
device_data(2.0 flow)token_created=None→ epoch default → startup refreshdevice_data(legacy 1.0.9 entry)Both shapes start successfully in under a second on
deveither way; the fix removes the unnecessary refresh for the 2.0 shape.Tests
test_device_login_records_access_token_and_token_created🤖 Generated with Claude Code