mirror of
https://github.com/esphome/esphome.git
synced 2025-09-19 19:52:20 +01:00
[mqtt] Fix KeyError when MQTT logging configured without explicit level (#10774)
This commit is contained in:
@@ -212,7 +212,7 @@ def has_mqtt_logging() -> bool:
|
|||||||
if CONF_TOPIC not in log_topic:
|
if CONF_TOPIC not in log_topic:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return log_topic[CONF_LEVEL] != "NONE"
|
return log_topic.get(CONF_LEVEL, None) != "NONE"
|
||||||
|
|
||||||
|
|
||||||
def has_mqtt() -> bool:
|
def has_mqtt() -> bool:
|
||||||
|
@@ -1226,6 +1226,18 @@ def test_has_mqtt_logging_no_log_topic() -> None:
|
|||||||
setup_core(config={})
|
setup_core(config={})
|
||||||
assert has_mqtt_logging() is False
|
assert has_mqtt_logging() is False
|
||||||
|
|
||||||
|
# Setup MQTT config with CONF_LOG_TOPIC but no CONF_LEVEL (regression test for #10771)
|
||||||
|
# This simulates the default configuration created by validate_config in the MQTT component
|
||||||
|
setup_core(
|
||||||
|
config={
|
||||||
|
CONF_MQTT: {
|
||||||
|
CONF_BROKER: "mqtt.local",
|
||||||
|
CONF_LOG_TOPIC: {CONF_TOPIC: "esphome/debug"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert has_mqtt_logging() is True
|
||||||
|
|
||||||
|
|
||||||
def test_has_mqtt() -> None:
|
def test_has_mqtt() -> None:
|
||||||
"""Test has_mqtt function."""
|
"""Test has_mqtt function."""
|
||||||
|
Reference in New Issue
Block a user