1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 05:12:21 +01: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:
Guillermo Ruffino
2021-05-14 20:35:39 -03:00
committed by GitHub
parent 4f6982fbc5
commit 3d6dcc9eee
3 changed files with 60 additions and 9 deletions

View File

@@ -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]