mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 08:55:22 +01:00
Don't allow debug component if you don't have at least debug logging level (#4076)
This commit is contained in:
parent
d067c8f80b
commit
81b4078871
2 changed files with 21 additions and 11 deletions
|
@ -1,11 +1,15 @@
|
||||||
import esphome.config_validation as cv
|
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
|
import esphome.config_validation as cv
|
||||||
|
import esphome.final_validate as fv
|
||||||
|
from esphome.components import logger
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_ID,
|
|
||||||
CONF_DEVICE,
|
|
||||||
CONF_FREE,
|
|
||||||
CONF_FRAGMENTATION,
|
|
||||||
CONF_BLOCK,
|
CONF_BLOCK,
|
||||||
|
CONF_DEVICE,
|
||||||
|
CONF_FRAGMENTATION,
|
||||||
|
CONF_FREE,
|
||||||
|
CONF_ID,
|
||||||
|
CONF_LEVEL,
|
||||||
|
CONF_LOGGER,
|
||||||
CONF_LOOP_TIME,
|
CONF_LOOP_TIME,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,6 +43,18 @@ CONFIG_SCHEMA = cv.Schema(
|
||||||
).extend(cv.polling_component_schema("60s"))
|
).extend(cv.polling_component_schema("60s"))
|
||||||
|
|
||||||
|
|
||||||
|
def _final_validate(_):
|
||||||
|
logger_conf = fv.full_config.get()[CONF_LOGGER]
|
||||||
|
severity = logger.LOG_LEVEL_SEVERITY.index(logger_conf[CONF_LEVEL])
|
||||||
|
if severity < logger.LOG_LEVEL_SEVERITY.index("DEBUG"):
|
||||||
|
raise cv.Invalid(
|
||||||
|
"The debug component requires the logger to be at least at DEBUG level"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
FINAL_VALIDATE_SCHEMA = _final_validate
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
|
|
|
@ -41,12 +41,6 @@ void DebugComponent::dump_config() {
|
||||||
std::string reset_reason;
|
std::string reset_reason;
|
||||||
device_info.reserve(256);
|
device_info.reserve(256);
|
||||||
|
|
||||||
#ifndef ESPHOME_LOG_HAS_DEBUG
|
|
||||||
ESP_LOGE(TAG, "Debug Component requires debug log level!");
|
|
||||||
this->status_set_error();
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGCONFIG(TAG, "Debug component:");
|
ESP_LOGCONFIG(TAG, "Debug component:");
|
||||||
#ifdef USE_TEXT_SENSOR
|
#ifdef USE_TEXT_SENSOR
|
||||||
LOG_TEXT_SENSOR(" ", "Device info", this->device_info_);
|
LOG_TEXT_SENSOR(" ", "Device info", this->device_info_);
|
||||||
|
|
Loading…
Reference in a new issue