Current-gen-schema (#2887)

* fix enum docs style

* schema fixes updates for 2023.2

* support multi key prop

* format fixes

* Format fixes

* set typed

* fix code quotes

* add platforms

---------

Co-authored-by: H. Árkosi Róbert <robreg@zsurob.hu>
This commit is contained in:
Guillermo Ruffino 2023-05-31 10:31:55 -03:00 committed by GitHub
parent 12f9aefeed
commit 0b041128a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 185 additions and 176 deletions

View File

@ -5,7 +5,7 @@ Haier Climate
:description: Instructions for setting up a Haier climate devices.
:image: air-conditioner.svg
The `haier` climate platform creates a Haier climate device.
The ``haier`` climate platform creates a Haier climate device.
The component can be used as a replacement of a Haier proprietary WiFi modules such as KZW-W001 and KZW-W002.
This component requires a :ref:`uart` to be setup.
@ -33,7 +33,7 @@ Configuration variables:
- **id** (*Optional*, :ref:`config-id`): Manually specify the ID used for code generation.
- **name** (**Required**, string): The name of the climate device.
- **update_interval** (*Optional*, :ref:`config-time`): How often device will be polled for status. Defaults to `5s`.
- **update_interval** (*Optional*, :ref:`config-time`): How often device will be polled for status. Defaults to ``5s``.
- **supported_swing_modes** (*Optional*, list): List of supported swing modes. Possible values are: ``VERTICAL``, ``HORIZONTAL``, ``BOTH``.
- All other options from :ref:`Climate <config-climate>`.

View File

@ -52,8 +52,8 @@ Configuration variables:
- **temperature_step** (*Optional*, float): The granularity with which the target temperature
can be controlled. Can be a single number, or split as below:
- **target_temperature** (**Required**, float)
- **current_temperature** (**Required**, float)
- **target_temperature** (**Required**, float): The granularity for target temperature
- **current_temperature** (**Required**, float): The granularity for current temperature
Advanced options:

View File

@ -90,18 +90,16 @@ Configuration variables:
- **deadband_parameters** (*Optional*): Enables a deadband to stabilise and minimise changes in the
output when the temperature is close to the target temperature. See `Deadband Setup`_.
- **threshold_low/threshold_high** (**Required**, float): Specifies a high/low
threshold defining the deadband
around the target temperature. For instance with `default_target_temperature` of ``21°C`` and
thresholds of ``+/-0.5°C``, the deadband will be
- **threshold_high/threshold_low** (**Required**, float): Specifies a high/low
threshold defining the deadband around the target temperature. For instance with
``default_target_temperature`` of ``21°C`` and thresholds of ``+/-0.5°C``, the deadband will be
between ``20.5°C - 21.5°C``. The PID controller will limit output changes within the deadband.
- **kp_multiplier** (*Optional*, float): Set the ``kp`` gain when inside the deadband. Defaults to ``0``.
- **ki_multiplier** (*Optional*, float): Set the ``ki`` gain when inside the deadband. Defaults to ``0``.
- **kd_multiplier** (*Optional*, float): Set the ``kd`` gain when inside the deadband. Recommended this
is set to ``0``. Defaults to ``0``.
- **kp_multiplier** (**Optional**, float): Set the ``kp`` gain when inside the deadband. Defaults to ``0``.
- **ki_multiplier** (**Optional**, float): Set the ``ki`` gain when inside the deadband. Defaults to ``0``.
- **kd_multiplier** (**Optional**, float): Set the ``kd`` gain when inside the deadband. Recommended this
is set to 0. Defaults to ``0``.
- **deadband_output_averaging_samples** (**Optional**, int): Typically when inside the deadband the PID Controller has
- **deadband_output_averaging_samples** (*Optional*, int): Typically when inside the deadband the PID Controller has
reached a state of equilibrium, so it advantageous to use a higher number of output samples
like 10-30 samples. Defaults to ``1`` which is no sampling/averaging.
@ -116,7 +114,7 @@ To set up a PID climate controller, you need a couple of components:
- A :ref:`Sensor <config-sensor>` to read the current temperature (``sensor``).
- At least one :ref:`float output <config-output>` to drive for heating or cooling (or both).
This could for example be a PWM output via :doc:`/components/output/sigma_delta` or :doc:`/components/output/slow_pwm` that drives a heating unit.
This could for example be a PWM output via :doc:`/components/output/sigma_delta_output` or :doc:`/components/output/slow_pwm` that drives a heating unit.
Please note the output *must* be controllable with continuous value (not only ON/OFF, but any state
in between for example 50% heating power).
@ -435,7 +433,7 @@ See Also
- Åström, K. J. and T. Hägglund (1984a), 'Automatic tuning of simple regulators',
Proceedings of IFAC 9th World Congress, Budapest, 1867-1872
- :doc:`/components/climate/index`
- :doc:`/components/output/sigma_delta`
- :doc:`/components/output/sigma_delta_output`
- :doc:`/components/output/slow_pwm`
- `Principles of PID <https://blog.opticontrols.com/archives/344>`__
- :apiref:`pid/pid_climate.h`

View File

@ -50,8 +50,8 @@ Configuration variables:
connected with diodes. Defaults to ``false``.
Binary Sensors
--------------
Binary Sensor
-------------
Individual keys can be added independently to ESPHome as ``binary_sensor``:

View File

@ -48,7 +48,7 @@ Configuration variables:
- **disabled** (*Optional*, boolean): Set to true to disable mDNS usage. Defaults to false.
- **services** (*Optional*, list): List of additional services to expose.
- **service** (*Required*, string): Name of extra service
- **protocol** (*Required*, string): Protocol of service (_udp or _tcp)
- **port** (*Optional*, int): Port number of extra service
- **txt** (*Optional*, mapping): Additional text records to add to service
- **service** (**Required**, string): Name of extra service.
- **protocol** (**Required**, string): Protocol of service (_udp or _tcp).
- **port** (*Optional*, int): Port number of extra service.
- **txt** (*Optional*, mapping): Additional text records to add to service.

View File

@ -98,7 +98,7 @@ This action turns the output with the given ID off when executed.
***************************
This action sets the float output to the given level when executed. Note: This only
works with floating point outputs like :doc:`/components/output/esp8266_pwm`, :doc:`/components/output/ledc`, :doc:`/components/output/sigma_delta`, :doc:`/components/output/slow_pwm`.
works with floating point outputs like :doc:`/components/output/esp8266_pwm`, :doc:`/components/output/ledc`, :doc:`/components/output/sigma_delta_output`, :doc:`/components/output/slow_pwm`.
.. code-block:: yaml

View File

@ -70,7 +70,7 @@ Example:
.. note::
If the duty cycle is not constrained to a maximum value, the
:doc:`/components/output/sigma_delta` component offers faster updates and
:doc:`/components/output/sigma_delta_output` component offers faster updates and
greater control over the switching frequency. This is better for loads that
need some time to fully change between on and off, like eletric thermal
actuator heads or fans.
@ -81,7 +81,7 @@ See Also
- :doc:`/components/output/index`
- :doc:`/components/output/esp8266_pwm`
- :doc:`/components/output/ledc`
- :doc:`/components/output/sigma_delta`
- :doc:`/components/output/sigma_delta_output`
- :doc:`/components/light/monochromatic`
- :doc:`/components/fan/speed`
- :doc:`/components/power_supply`

View File

@ -204,13 +204,13 @@ Remote code selection (exactly one of these has to be included):
- **canalsat**: Trigger on a decoded CanalSat remote code with the given data.
- **device** (**Required**, int): The device to trigger on, see dumper output for more info.
- **address** (**Optional**, int): The address (or subdevice) to trigger on, see dumper output for more info. Defaults to ``0``
- **address** (*Optional*, int): The address (or subdevice) to trigger on, see dumper output for more info. Defaults to ``0``
- **command** (**Required**, int): The command to listen for.
- **canalsatld**: Trigger on a decoded CanalSatLD remote code with the given data.
- **device** (**Required**, int): The device to trigger on, see dumper output for more info.
- **address** (**Optional**, int): The address (or subdevice) to trigger on, see dumper output for more info. Defaults to ``0``
- **address** (*Optional*, int): The address (or subdevice) to trigger on, see dumper output for more info. Defaults to ``0``
- **command** (**Required**, int): The command to listen for.
- **coolix**: Trigger on a decoded Coolix remote code with the given data.

View File

@ -122,7 +122,7 @@ This :ref:`action <config-action>` sends a CanalSat infrared remote code to a re
Configuration variables:
- **device** (**Required**, int): The device to send to, see dumper output for more details.
- **address** (**Optional**, int): The address (or subdevice) to send to, see dumper output for more details. Defaults to ``0``
- **address** (*Optional*, int): The address (or subdevice) to send to, see dumper output for more details. Defaults to ``0``
- **command** (**Required**, int): The command to send.
- All other options from :ref:`remote_transmitter-transmit_action`.
@ -149,7 +149,7 @@ This :ref:`action <config-action>` sends a CanalSatLD infrared remote code to a
Configuration variables:
- **device** (**Required**, int): The device to send to, see dumper output for more details.
- **address** (**Optional**, int): The address (or subdevice) to send to, see dumper output for more details. Defaults to ``0``
- **address** (*Optional*, int): The address (or subdevice) to send to, see dumper output for more details. Defaults to ``0``
- **command** (**Required**, int): The command to send.
- All other options from :ref:`remote_transmitter-transmit_action`.

View File

@ -96,8 +96,8 @@ Configuration variables:
- **id** (*Optional*, :ref:`config-id`): Manually specify the ID used for code generation.
- **resolution** (*Optional*, string): the resolution of this sensor. Defaults to ``16 bits``.
- **16 bits**
- **12 bits**
- ``16 bits``
- ``12 bits``
Multiplexer and Gain

View File

@ -36,19 +36,19 @@ The :ref:`I²C Bus <i2c>` is required to be set up in your configuration for thi
Configuration variables:
------------------------
- **temperature** (*Required*): The information for the Temperature sensor.
- **temperature** (**Required**): The information for the Temperature sensor.
- **name** (**Required**, string): The name for the temperature sensor.
- **id** (*Optional*, :ref:`config-id`): Set the ID of this sensor for use in lambdas.
- All other options from :ref:`Sensor <config-sensor>`.
- **co2** (*Required*): The information for the CO₂ sensor.
- **co2** (**Required**): The information for the CO₂ sensor.
- **name** (**Required**, string): The name for the CO₂eq sensor.
- **id** (*Optional*, :ref:`config-id`): Set the ID of this sensor for use in lambdas.
- All other options from :ref:`Sensor <config-sensor>`.
- **Pressure** (*Required*): The information for the Pressure sensor.
- **pressure** (**Required**): The information for the Pressure sensor.
- **name** (**Required**, string): The name for the Pressure sensor.
- **id** (*Optional*, :ref:`config-id`): Set the ID of this sensor for use in lambdas.

View File

@ -415,7 +415,7 @@ Configuration variables:
``skip_initial``
****************
A simple skip filter; `skip_initial: N` skips the first `N` sensor readings and passes on the
A simple skip filter; ``skip_initial: N`` skips the first ``N`` sensor readings and passes on the
rest. This can be used when the sensor needs a few readings to 'warm up'. After the initial
readings have been skipped, this filter does nothing.

View File

@ -66,14 +66,13 @@ A configured modbus component is optional. It will be automatically created.
Configuration variables:
- **ph**: Measured pH value
- **temperature**: Measured temperature value
- **dis1**: Measured DIS 1 value
- **dis2**: Measured DIS 2 value
- **redox**: Measured Redox value
- **ec**: Measured EC value
- **oci**: Measured OCI value
- **ph** (*Optional*): Measured pH value.
- **temperature** (*Optional*): Measured temperature value.
- **dis1** (*Optional*): Measured DIS 1 value.
- **dis2** (*Optional*): Measured DIS 2 value.
- **redox** (*Optional*): Measured Redox value.
- **ec** (*Optional*): Measured EC value.
- **oci** (*Optional*): Measured OCI value.
All sensors are *Optional* and support all other options from :ref:`Sensor <config-sensor>`.

View File

@ -75,7 +75,7 @@ and binary sensors.
Value between ``0.75m`` and ``6m`` inclusive. Defaults to ``4.5m``.
- **gX_move_threshold** (*Optional*, int): Threshold for the Xth gate for motion detection (X => 0 to 8).
Above this level for the considered gate (distance), movement detection will be triggered. Defaults to ``see table below``.
- **gX _still_threshold** (*Optional*, int): Threshold for the Xth gate for still detection. (X => 0 to 8).
- **gX_still_threshold** (*Optional*, int): Threshold for the Xth gate for still detection. (X => 0 to 8).
Above this level for the considered gate (distance), still detection will be triggered. Defaults to ``see table below``.
.. list-table:: Default values for gate threshold

View File

@ -203,7 +203,7 @@ Configuration variables:
- **sensors** (**Required**): A list of :ref:`Sensor <config-sensor>` definitions that include a ``lambda`` to do the decoding and return a ``float`` value.
- **lambda** (**Required**, :ref:`lambda <config-lambda>`): Code to parse a value from the incoming data packets and return it.
The data packet is in a `std::vector<uint8_t>` called `x`.
The data packet is in a ``std::vector<uint8_t>`` called ``x``.
``custom`` VBus binary sensors
@ -218,7 +218,7 @@ Configuration variables:
- **binary_sensors** (**Required**): A list of :ref:`Binary Sensor <config-binary_sensor>` definitions that include a ``lambda`` to do the decoding and return a ``bool`` value.
- **lambda** (**Required**, :ref:`lambda <config-lambda>`): Code to parse a value from the incoming data packets and return it.
The data packet is in a `std::vector<uint8_t>` called `x`.
The data packet is in a ``std::vector<uint8_t>`` called ``x``.
To determine the correct values for the parameters above, visit `packet definitions list <http://danielwippermann.github.io/resol-vbus/#/vsf>`__. In the search field of the **Packets** table, enter the name of your device.

View File

@ -499,7 +499,7 @@ Output Components
BLE Binary Output, components/output/ble_client, bluetooth.svg
Modbus Output, components/output/modbus_controller, modbus.png
Custom Output, components/output/custom, language-cpp.svg
Sigma-Delta Output, components/output/sigma_delta, sigma-delta.svg
Sigma-Delta Output, components/output/sigma_delta_output, sigma-delta.svg
Template Output, components/output/template, description.svg
BP1658CJ, components/output/bp1658cj, bp1658cj.svg
BP5758D, components/output/bp5758d, bp5758d.svg

View File

@ -81,6 +81,8 @@ PLATFORMS_TITLES = {
"Stepper": "stepper",
"Switch": "switch",
"I²C": "i2c",
"Media Player": "media_player",
"Microphone": "microphone",
}
CUSTOM_DOCS = {
@ -196,6 +198,8 @@ CUSTOM_DOCS = {
},
}
REQUIRED_OPTIONAL_TYPE_REGEX = r"(\(((\*\*Required\*\*)|(\*Optional\*))(,\s(.*))*)\):\s"
def get_node_title(node):
return list(node.traverse(nodes.title))[0].astext()
@ -250,7 +254,6 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
]
else: # sub component, e.g. output/esp8266_pwm
# components here might have a core / hub, eg. dallas, ads1115
# and then they can be a binary_sensor, sensor, etc.
self.platform = self.path[1]
@ -775,7 +778,6 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
and (self.props or self.multi_component)
and self.bullet_list_level > 1
):
self.prop_stack.append((self.current_prop, node))
self.accept_props = True
return
@ -844,7 +846,7 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
try:
name_type = markdown[: markdown.index(": ") + 2]
ntr = re.search(
r"(\(((\*\*Required\*\*)|(\*Optional\*))(,\s(.*))*)\):\s",
REQUIRED_OPTIONAL_TYPE_REGEX,
name_type,
re.IGNORECASE,
)
@ -875,7 +877,6 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
return markdown
def update_prop(self, node, props):
prop_name = None
for s_prop, n in self.prop_stack:
@ -901,10 +902,10 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
found = True
if enum_docs:
enum_docs = enum_docs.strip()
if "values_docs" not in inner:
inner["values_docs"] = {name: enum_docs}
if inner["values"][name] is None:
inner["values"][name] = {"docs": enum_docs}
else:
inner["values_docs"][name] = enum_docs
inner["values"][name]["docs"] = enum_docs
statistics.props_documented += 1
statistics.enums_good += 1
if not found:
@ -941,12 +942,19 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
return prop_name, False
# Example properties formats are:
# **name** (**Required**, string): Long Description...
# **name** (*Optional*, string): Long Description... Defaults to ``value``.
# **name** (*Optional*): Long Description... Defaults to ``value``.
# **prop_name** (**Required**, string): Long Description...
# **prop_name** (*Optional*, string): Long Description... Defaults to ``value``.
# **prop_name** (*Optional*): Long Description... Defaults to ``value``.
# **prop_name** can be a list of names separated by / e.g. **name1/name2** (*Optional*) see climate/pid/ threshold_low/threshold_high
PROP_NAME_REGEX = r"\*\*(\w*(?:/\w*)*)\*\*"
FULL_ITEM_PROP_NAME_TYPE_REGEX = (
r"\* " + PROP_NAME_REGEX + r"\s" + REQUIRED_OPTIONAL_TYPE_REGEX
)
ntr = re.search(
r"\* \*\*(\w*)\*\*\s(\(((\*\*Required\*\*)|(\*Optional\*))(,\s(.*))*)\):\s",
FULL_ITEM_PROP_NAME_TYPE_REGEX,
name_type,
re.IGNORECASE,
)
@ -956,14 +964,14 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
param_type = ntr.group(7)
else:
s2 = re.search(
r"\* \*\*(\w*)\*\*\s(\(((\*\*Required\*\*)|(\*Optional\*))(,\s(.*))*)\):\s",
FULL_ITEM_PROP_NAME_TYPE_REGEX,
markdown,
re.IGNORECASE,
)
if s2:
# this is e.g. when a property has a list inside, and the list inside are the options.
# just validate **prop_name**
s3 = re.search(r"\* \*\*(\w*)\*\*:\s", name_type)
s3 = re.search(r"\* " + PROP_NAME_REGEX + r"*:\s", name_type)
if s3 is not None:
prop_name = s3.group(1)
else:
@ -977,61 +985,61 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
)
return prop_name, False
k = str(prop_name)
prop_names = str(prop_name)
for k in prop_names.split("/"):
config_var = props.get(k)
config_var = props.get(k)
if not config_var:
# Create docs for common properties when descriptions are overridden
# in the most specific component.
if not config_var:
# Create docs for common properties when descriptions are overridden
# in the most specific component.
if k in [
"id",
"name",
"internal",
# i2c
"address",
"i2c_id",
# polling component
"update_interval",
# uart
"uart_id",
# light
"effects",
"gamma_correct",
"default_transition_length",
"flash_transition_length",
"color_correct",
# display
"lambda",
"pages",
"rotation",
# spi
"spi_id",
"cs_pin",
# output (binary/float output)
"inverted",
"power_supply",
# climate
"receiver_id",
]:
config_var = props[k] = {}
else:
if self.path[1] == "esphome" and k in [
# deprecated esphome
"platform",
"board",
"arduino_version",
"esp8266_restore_from_flash",
if k in [
"id",
"name",
"internal",
# i2c
"address",
"i2c_id",
# polling component
"update_interval",
# uart
"uart_id",
# light
"effects",
"gamma_correct",
"default_transition_length",
"flash_transition_length",
"color_correct",
# display
"lambda",
"pages",
"rotation",
# spi
"spi_id",
"cs_pin",
# output (binary/float output)
"inverted",
"power_supply",
# climate
"receiver_id",
]:
return prop_name, True
return prop_name, False
config_var = props[k] = {}
else:
if self.path[1] == "esphome" and k in [
# deprecated esphome
"platform",
"board",
"arduino_version",
"esp8266_restore_from_flash",
]:
return prop_name, True
return prop_name, False
desc = markdown[markdown.index(": ") + 2 :].strip()
if param_type:
desc = "**" + param_type + "**: " + desc
desc = markdown[markdown.index(": ") + 2 :].strip()
if param_type:
desc = "**" + param_type + "**: " + desc
config_var["docs"] = desc
config_var["docs"] = desc
statistics.props_documented += 1
@ -1084,7 +1092,11 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
def _find_extended(self, component, key):
for extended in component.get("extends", []):
schema = self.visitor.get_component_schema(extended).get("schema", {})
c = self.visitor.get_component_schema(extended)
if c.get("type") == "typed":
p = self.visitor.Props(self.visitor, c)
return p[key]
schema = c.get("schema", {})
for k, cv in schema.get("config_vars", {}).items():
if k == key:
return SetObservable(
@ -1124,7 +1136,7 @@ class SchemaGeneratorVisitor(nodes.NodeVisitor):
)
def _set_typed(self, inner_key, original_dict, key, value):
if inner_key == self.component.get("typed_key"):
if inner_key == self.component.get("typed_key", "type"):
self.component[key] = value
else:
for tk, tv in self.component["types"].items():