Skip to content

Normalize username check for file-based mode - #187

Merged
KJonline merged 1 commit into
devfrom
KJonline-patch-1
Nov 2, 2026
Merged

KJonline merged 1 commit into
devfrom
KJonline-patch-1

Conversation

@KJonline

@KJonline KJonline commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@KJonline
KJonline merged commit 0e53799 into dev Nov 2, 2026
4 of 5 checks passed
@KJonline
KJonline deleted the KJonline-patch-1 branch November 2, 2026 11:10
Comment thread src/session/discovery.py
username: If ``"use@file.com"``, switches the session to file-based mode.
"""
if username == "use@file.com":
if username.strip().lower() == "use@file.com":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Claude Code Review

Bug: username is typed str | None and defaults to None. Hive(username=None) is allowed (session/__init__.py:38), and start_session passes config.get("username", self.config.username) here (discovery.py:192). If the username is None, None.strip() raises AttributeError, so start_session() crashes. The same happens if config={"username": None}. Before this PR, the == comparison handled None.

Suggested fix:

Suggested change
if username.strip().lower() == "use@file.com":
if username and username.strip().lower() == "use@file.com":

Also note that hive_auth_async.py:82 and hive_auth.py:114 still use the exact == "use@file.com" check, so the normalisation is inconsistent. No test was added for the new behaviour (mixed case, whitespace, None).

@claude

claude Bot commented Nov 2, 2026

Copy link
Copy Markdown

🤖 Claude Code Review

Verdict: Request changes. The new check crashes when username is None.

Bugs

  • src/session/discovery.py:53: username.strip() raises AttributeError when username is None. That is the default for Hive(username=None), and start_session passes config.get("username", self.config.username). Fix: if username and username.strip().lower() == "use@file.com":.

Should fix

  • No tests cover the new behaviour (mixed case, whitespace, None). Coverage must stay at 99%.
  • src/api/hive_auth_async.py:82 and src/api/hive_auth.py:114 still compare username == "use@file.com" exactly. A username like " Use@File.com " would set config.file but not use_file in the auth classes, so the two checks disagree.

Home Assistant check: I tried to fetch homeassistant/components/hive/__init__.py from home-assistant/core but got HTTP 429, so I could not verify how it constructs Hive. As far as I know, HA passes a real username string, so the crash is most likely to show up for library users who construct Hive() without a username.

Not reviewed: The PR is a one-line change, and I reviewed all of it.


Automated review by Claude Code · workflow run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant