Add validate to components (#1631)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Guillermo Ruffino
2021-05-30 19:06:45 -03:00
committed by GitHub
parent 482a3aebc9
commit c79d700d03
16 changed files with 174 additions and 36 deletions
+31 -1
View File
@@ -1,8 +1,11 @@
import logging
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
from esphome.components.output import FloatOutput
from esphome.const import CONF_ID, CONF_OUTPUT, CONF_TRIGGER_ID
from esphome.const import CONF_ID, CONF_OUTPUT, CONF_PLATFORM, CONF_TRIGGER_ID
_LOGGER = logging.getLogger(__name__)
CODEOWNERS = ["@glmnet"]
CONF_RTTTL = "rtttl"
@@ -33,6 +36,33 @@ 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]
PWM_GOOD = ["esp8266_pwm", "ledc"]
PWM_BAD = [
"ac_dimmer ",
"esp32_dac",
"slow_pwm",
"mcp4725",
"pca9685",
"tlc59208f",
"my9231",
"sm16716",
]
if platform in PWM_BAD:
raise ValueError(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."
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)