mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
[core] .local addresses are only resolvable if mDNS is enabled (#11508)
This commit is contained in:
@@ -207,14 +207,14 @@ def choose_upload_log_host(
|
|||||||
if has_mqtt_logging():
|
if has_mqtt_logging():
|
||||||
resolved.append("MQTT")
|
resolved.append("MQTT")
|
||||||
|
|
||||||
if has_api() and has_non_ip_address():
|
if has_api() and has_non_ip_address() and has_resolvable_address():
|
||||||
resolved.extend(_resolve_with_cache(CORE.address, purpose))
|
resolved.extend(_resolve_with_cache(CORE.address, purpose))
|
||||||
|
|
||||||
elif purpose == Purpose.UPLOADING:
|
elif purpose == Purpose.UPLOADING:
|
||||||
if has_ota() and has_mqtt_ip_lookup():
|
if has_ota() and has_mqtt_ip_lookup():
|
||||||
resolved.append("MQTTIP")
|
resolved.append("MQTTIP")
|
||||||
|
|
||||||
if has_ota() and has_non_ip_address():
|
if has_ota() and has_non_ip_address() and has_resolvable_address():
|
||||||
resolved.extend(_resolve_with_cache(CORE.address, purpose))
|
resolved.extend(_resolve_with_cache(CORE.address, purpose))
|
||||||
else:
|
else:
|
||||||
resolved.append(device)
|
resolved.append(device)
|
||||||
@@ -318,7 +318,17 @@ def has_resolvable_address() -> bool:
|
|||||||
"""Check if CORE.address is resolvable (via mDNS, DNS, or is an IP address)."""
|
"""Check if CORE.address is resolvable (via mDNS, DNS, or is an IP address)."""
|
||||||
# Any address (IP, mDNS hostname, or regular DNS hostname) is resolvable
|
# Any address (IP, mDNS hostname, or regular DNS hostname) is resolvable
|
||||||
# The resolve_ip_address() function in helpers.py handles all types via AsyncResolver
|
# The resolve_ip_address() function in helpers.py handles all types via AsyncResolver
|
||||||
return CORE.address is not None
|
if CORE.address is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if has_ip_address():
|
||||||
|
return True
|
||||||
|
|
||||||
|
if has_mdns():
|
||||||
|
return True
|
||||||
|
|
||||||
|
# .local mDNS hostnames are only resolvable if mDNS is enabled
|
||||||
|
return not CORE.address.endswith(".local")
|
||||||
|
|
||||||
|
|
||||||
def mqtt_get_ip(config: ConfigType, username: str, password: str, client_id: str):
|
def mqtt_get_ip(config: ConfigType, username: str, password: str, client_id: str):
|
||||||
|
|||||||
@@ -744,7 +744,7 @@ def test_choose_upload_log_host_ota_local_all_options() -> None:
|
|||||||
check_default=None,
|
check_default=None,
|
||||||
purpose=Purpose.UPLOADING,
|
purpose=Purpose.UPLOADING,
|
||||||
)
|
)
|
||||||
assert result == ["MQTTIP", "test.local"]
|
assert result == ["MQTTIP"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_serial_ports")
|
@pytest.mark.usefixtures("mock_serial_ports")
|
||||||
@@ -794,7 +794,7 @@ def test_choose_upload_log_host_ota_local_all_options_logging() -> None:
|
|||||||
check_default=None,
|
check_default=None,
|
||||||
purpose=Purpose.LOGGING,
|
purpose=Purpose.LOGGING,
|
||||||
)
|
)
|
||||||
assert result == ["MQTTIP", "MQTT", "test.local"]
|
assert result == ["MQTTIP", "MQTT"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_no_mqtt_logging")
|
@pytest.mark.usefixtures("mock_no_mqtt_logging")
|
||||||
@@ -1564,7 +1564,7 @@ def test_has_resolvable_address() -> None:
|
|||||||
setup_core(
|
setup_core(
|
||||||
config={CONF_MDNS: {CONF_DISABLED: True}}, address="esphome-device.local"
|
config={CONF_MDNS: {CONF_DISABLED: True}}, address="esphome-device.local"
|
||||||
)
|
)
|
||||||
assert has_resolvable_address() is True
|
assert has_resolvable_address() is False
|
||||||
|
|
||||||
# Test with mDNS disabled and regular DNS hostname (resolvable)
|
# Test with mDNS disabled and regular DNS hostname (resolvable)
|
||||||
setup_core(config={CONF_MDNS: {CONF_DISABLED: True}}, address="device.example.com")
|
setup_core(config={CONF_MDNS: {CONF_DISABLED: True}}, address="device.example.com")
|
||||||
|
|||||||
Reference in New Issue
Block a user