mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 06:33:51 +00:00
Add more json schema generation features (#1690)
* some enums * extract enums, light effects remote_receiver etc * more pins schema * update to core changes
This commit is contained in:
committed by
GitHub
parent
4f6982fbc5
commit
3d6dcc9eee
@@ -1,3 +1,4 @@
|
||||
from esphome.jsonschema import jschema_extractor
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import automation
|
||||
@@ -452,7 +453,11 @@ def addressable_flicker_effect_to_code(config, effect_id):
|
||||
|
||||
|
||||
def validate_effects(allowed_effects):
|
||||
@jschema_extractor("effects")
|
||||
def validator(value):
|
||||
# pylint: disable=comparison-with-callable
|
||||
if value == jschema_extractor:
|
||||
return (allowed_effects, EFFECTS_REGISTRY)
|
||||
value = cv.validate_registry("effect", EFFECTS_REGISTRY)(value)
|
||||
errors = []
|
||||
names = set()
|
||||
|
||||
@@ -46,7 +46,13 @@ from esphome.core import (
|
||||
TimePeriodMinutes,
|
||||
)
|
||||
from esphome.helpers import list_starts_with, add_class_to_obj
|
||||
from esphome.jsonschema import jschema_composite, jschema_registry, jschema_typed
|
||||
from esphome.jsonschema import (
|
||||
jschema_composite,
|
||||
jschema_extractor,
|
||||
jschema_registry,
|
||||
jschema_typed,
|
||||
)
|
||||
|
||||
from esphome.voluptuous_schema import _Schema
|
||||
from esphome.yaml_util import make_data_base
|
||||
|
||||
@@ -1121,7 +1127,12 @@ def one_of(*values, **kwargs):
|
||||
if kwargs:
|
||||
raise ValueError
|
||||
|
||||
@jschema_extractor("one_of")
|
||||
def validator(value):
|
||||
# pylint: disable=comparison-with-callable
|
||||
if value == jschema_extractor:
|
||||
return values
|
||||
|
||||
if string_:
|
||||
value = string(value)
|
||||
value = value.replace(" ", space)
|
||||
@@ -1161,7 +1172,12 @@ def enum(mapping, **kwargs):
|
||||
assert isinstance(mapping, dict)
|
||||
one_of_validator = one_of(*mapping, **kwargs)
|
||||
|
||||
@jschema_extractor("enum")
|
||||
def validator(value):
|
||||
# pylint: disable=comparison-with-callable
|
||||
if value == jschema_extractor:
|
||||
return mapping
|
||||
|
||||
value = one_of_validator(value)
|
||||
value = add_class_to_obj(value, core.EnumValue)
|
||||
value.enum_value = mapping[value]
|
||||
|
||||
Reference in New Issue
Block a user