Skip to content

Match name and preferred address case-insensitively in build_log_name#1693

Merged
bdraco merged 1 commit into
esphome:mainfrom
bluetoothbot:koan/build-log-name-tests
May 20, 2026
Merged

Match name and preferred address case-insensitively in build_log_name#1693
bdraco merged 1 commit into
esphome:mainfrom
bluetoothbot:koan/build-log-name-tests

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented May 20, 2026

Copy link
Copy Markdown
Contributor

What does this implement/fix?

build_log_name builds the log label that identifies a device session
("name @ address"). It already suppresses the prefix when the resolved
address is name.local, but the startswith check is case-sensitive
— so a name myesp with a resolved MYESP.local came out as
myesp @ MYESP.local instead of just MYESP.local.

mDNS / DNS labels are case-insensitive (RFC 6762 §16, RFC 4343), and
the rest of util.py already normalises with .lower()
(address_is_local, fixed in #1681). This brings build_log_name
into line.

Also adds the first test coverage for build_log_name. The function
was previously untested; the new parametrized cases pin the canonical
shapes (bare hostname, .local, IP-only, with/without connected_address,
multiple addresses, bracketed IPv6) plus the mixed-case rows that
exercise the fix.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

  • n/a

Pull request in esphome (if applicable):

  • n/a

Checklist:

  • The code change is tested and works locally.
  • If api.proto was modified, a linked pull request has been made to esphome with the same changes. (api.proto not modified)
  • Tests have been added to verify that the new code works (under tests/ folder).

Quality Report

Changes: 2 files changed, 42 insertions(+), 3 deletions(-)

Code scan: clean

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

mDNS / DNS labels are case-insensitive (RFC 6762 §16, RFC 4343). The
previous case-sensitive startswith check meant a supplied name 'myesp'
with a resolved 'MYESP.local' produced 'myesp @ MYESP.local' instead
of dropping the redundant prefix.

Adds the first test coverage for build_log_name, including the mixed-
case case that exercises the fix.
@codecov

codecov Bot commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (dcd9453) to head (04c59a1).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1693   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines         4165      4165           
=========================================
  Hits          4165      4165           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq

codspeed-hq Bot commented May 20, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 47 untouched benchmarks


Comparing bluetoothbot:koan/build-log-name-tests (04c59a1) with main (dcd9453)

Open in CodSpeed

@bdraco
bdraco marked this pull request as ready for review May 20, 2026 23:00
Copilot AI review requested due to automatic review settings May 20, 2026 23:00
@bdraco

bdraco commented May 20, 2026

Copy link
Copy Markdown
Member

In practice ESPHome always uses lowercase but this is a minor correctness improvement

@bdraco
bdraco merged commit c9a234e into esphome:main May 20, 2026
17 of 18 checks passed
@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4dc21bbd-f563-4224-91f7-f289eb8c1c49

📥 Commits

Reviewing files that changed from the base of the PR and between dcd9453 and 04c59a1.

📒 Files selected for processing (2)
  • aioesphomeapi/util.py
  • tests/test_util.py

Walkthrough

The PR fixes case-insensitive address matching in build_log_name() by lowercasing comparison values, and adds comprehensive parametrized test coverage validating the function's behavior across hostname, .local, IP, and IPv6 address scenarios.

Changes

Case-insensitive address matching in build_log_name

Layer / File(s) Summary
Case-insensitive address comparison logic
aioesphomeapi/util.py
build_log_name() now lowercases both sides when comparing name and preferred_address, and when checking whether preferred_address starts with the name. prefix.
Comprehensive test coverage for build_log_name
tests/test_util.py
New parametrized test validates build_log_name() output across multiple scenarios: hostname vs .local handling, IP/connected address preference, case-insensitive matching, and bracketed IPv6 formatting with optional ports.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • bdraco
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates build_log_name to treat DNS/mDNS labels case-insensitively when deciding whether to include the "name @ " prefix, aligning it with existing case-normalization behavior elsewhere in util.py. Adds initial unit test coverage for build_log_name to lock in expected output shapes across common address/name combinations.

Changes:

  • Make build_log_name compare name vs preferred_address case-insensitively (including the startswith(f"{name}.") suppression check).
  • Add parametrized tests covering build_log_name behavior across .local, hostname, IPv4, bracketed IPv6, multiple-address, and mixed-case scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
aioesphomeapi/util.py Lowercase-based comparisons for case-insensitive prefix/equality matching in build_log_name.
tests/test_util.py Adds first test coverage for build_log_name via a parametrized test matrix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aioesphomeapi/util.py
Comment on lines 89 to 93
if (
name
and name != preferred_address
and not preferred_address.startswith(f"{name}.")
and name.lower() != preferred_address.lower()
and not preferred_address.lower().startswith(f"{name.lower()}.")
):
@bluetoothbot
bluetoothbot deleted the koan/build-log-name-tests branch May 20, 2026 23:43
@github-actions github-actions Bot locked and limited conversation to collaborators May 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants