mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 18:48:28 +02:00
Improve config final validation (#1917)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
import esphome.final_validate as fv
|
||||
from esphome import automation
|
||||
from esphome.components.output import FloatOutput
|
||||
from esphome.const import CONF_ID, CONF_OUTPUT, CONF_PLATFORM, CONF_TRIGGER_ID
|
||||
@@ -36,12 +37,8 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def validate(config, item_config):
|
||||
# Not adding this to FloatOutput as this is the only component which needs `update_frequency`
|
||||
|
||||
parent_config = config.get_config_by_id(item_config[CONF_OUTPUT])
|
||||
platform = parent_config[CONF_PLATFORM]
|
||||
|
||||
def validate_parent_output_config(value):
|
||||
platform = value.get(CONF_PLATFORM)
|
||||
PWM_GOOD = ["esp8266_pwm", "ledc"]
|
||||
PWM_BAD = [
|
||||
"ac_dimmer ",
|
||||
@@ -55,14 +52,25 @@ def validate(config, item_config):
|
||||
]
|
||||
|
||||
if platform in PWM_BAD:
|
||||
raise ValueError(f"Component rtttl cannot use {platform} as output component")
|
||||
raise cv.Invalid(f"Component rtttl cannot use {platform} as output component")
|
||||
|
||||
if platform not in PWM_GOOD:
|
||||
_LOGGER.warning(
|
||||
"Component rtttl is not known to work with the selected output type. Make sure this output supports custom frequency output method."
|
||||
"Component rtttl is not known to work with the selected output type. "
|
||||
"Make sure this output supports custom frequency output method."
|
||||
)
|
||||
|
||||
|
||||
FINAL_VALIDATE_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_OUTPUT): fv.id_declaration_match_schema(
|
||||
validate_parent_output_config
|
||||
)
|
||||
},
|
||||
extra=cv.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
|
||||
Reference in New Issue
Block a user