Skip to content

Fix address_is_local to match .local case-insensitively#1681

Merged
bdraco merged 2 commits into
esphome:mainfrom
bluetoothbot:koan/address-is-local-case-insensitive
May 20, 2026
Merged

Fix address_is_local to match .local case-insensitively#1681
bdraco merged 2 commits into
esphome:mainfrom
bluetoothbot:koan/address-is-local-case-insensitive

Conversation

@bluetoothbot
Copy link
Copy Markdown
Contributor

@bluetoothbot bluetoothbot commented May 20, 2026

What does this implement/fix?

What: address_is_local() now lowercases the address before
checking the .local suffix.

Why: mDNS / DNS names are case-insensitive (RFC 6762 §16,
RFC 4343), but the previous endswith(".local") was case-sensitive.
A peer advertising itself as MyESP.LOCAL or myesp.Local was not
recognised as a local address, which then perturbs the log-name
composition in build_log_name() (the (not name and address_is_local(address)) branch never fires, so the host part
isn't lifted out as the friendly name).

How: One-character behavioural change — .lower() before
.endswith(".local"). Trailing-dot handling (removesuffix("."))
is preserved.

Testing: New parametrized test_address_is_local cases pin the
case-insensitive behaviour (commit 1 fails against the old code,
commit 2 makes them pass). Full suite: 1075 passed, 2 skipped.

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):

Pull request in esphome (if applicable):

  • n/a — client-only change, no protocol or firmware-side impact.

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. (N/A — api.proto not touched.)
  • Tests have been added to verify that the new code works (under tests/ folder).

Quality Report

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

Code scan: clean

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

mDNS and DNS names are case-insensitive per RFC 6762 §16 / RFC 4343,
but address_is_local() does a case-sensitive endswith(".local") so
"MyESP.LOCAL" is rejected. These parametrized cases pin the expected
behaviour; they fail against the current implementation.
mDNS hostnames are case-insensitive (RFC 6762 §16, RFC 4343), but
address_is_local() used a case-sensitive endswith(".local") so an
address advertised as "MyESP.LOCAL" or with a mixed-case TLD was
not recognised as local. Lowercase before comparing.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1681   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines         4152      4152           
=========================================
  Hits          4152      4152           

☔ 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
Copy link
Copy Markdown

codspeed-hq Bot commented May 20, 2026

Merging this PR will not alter performance

✅ 40 untouched benchmarks


Comparing bluetoothbot:koan/address-is-local-case-insensitive (cc0868f) with main (f544437)

Open in CodSpeed

@bdraco bdraco marked this pull request as ready for review May 20, 2026 11:26
Copilot AI review requested due to automatic review settings May 20, 2026 11:26
@bdraco bdraco merged commit 40ef803 into esphome:main May 20, 2026
23 of 27 checks passed
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

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: c9e9fe2e-0f1b-4c62-bfe5-caf5aba3b24f

📥 Commits

Reviewing files that changed from the base of the PR and between f544437 and cc0868f.

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

Walkthrough

The PR updates the address_is_local() utility function to perform case-insensitive matching of the .local suffix for mDNS-style hostnames. The implementation change adds lowercasing to the normalized address, and comprehensive parametrized tests verify behavior across valid local domains, optional trailing dots, and rejection of non-local addresses.

Changes

Case-insensitive mDNS/local address detection

Layer / File(s) Summary
Case-insensitive .local suffix check
aioesphomeapi/util.py
address_is_local() now lowercases the normalized address before checking the .local suffix, enabling case-insensitive detection of local mDNS hostnames.
Local address detection tests
tests/test_util.py
Import updated to include address_is_local, and new parametrized test test_address_is_local validates case-insensitive .local matching, trailing-dot handling, and rejection of non-local hostnames.

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a 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 fixes address_is_local() so it treats .local as case-insensitive (consistent with DNS/mDNS), ensuring mixed-case mDNS hostnames are correctly recognized as local and therefore can be used as the friendly name source in build_log_name().

Changes:

  • Make address_is_local() lowercase the address before checking for the .local suffix (while preserving trailing-dot handling).
  • Add unit tests covering .local case-insensitive behavior and trailing-dot variants.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
aioesphomeapi/util.py Adjusts .local detection to be case-insensitive by lowercasing before the suffix check.
tests/test_util.py Adds parametrized tests verifying case-insensitive .local recognition and existing edge cases.

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

@bluetoothbot bluetoothbot deleted the koan/address-is-local-case-insensitive branch May 20, 2026 11:33
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.

3 participants