Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
button.py
Go to the documentation of this file.
1## @file
2## @brief ESPHome pairing-button schema and code generation.
3## @ingroup hioc_codegen
4##
5## Exposes the Home Assistant button entity that starts device discovery and pairing.
6
7import esphome.codegen as cg
8from esphome.components import button
9import esphome.config_validation as cv
10from esphome.const import CONF_ID, ENTITY_CATEGORY_CONFIG
11
12from . import home_io_control_ns, IOHomeControlComponent, CONF_HOME_IO_CONTROL_ID
13
14DEPENDENCIES = ["home_io_control"]
15
16IOHomeDiscoverButton = home_io_control_ns.class_(
17 "IOHomeDiscoverButton", button.Button, cg.Component
18)
19
20CONFIG_SCHEMA = (
21 button.button_schema(
22 IOHomeDiscoverButton,
23 entity_category=ENTITY_CATEGORY_CONFIG,
24 )
25 .extend(
26 {
27 cv.GenerateID(CONF_HOME_IO_CONTROL_ID): cv.use_id(
28 IOHomeControlComponent
29 ),
30 }
31 )
32 .extend(cv.COMPONENT_SCHEMA)
33)
34
35
36async def to_code(config):
37 var = cg.new_Pvariable(config[CONF_ID])
38 await cg.register_component(var, config)
39 await button.register_button(var, config)
40
41 parent = await cg.get_variable(config[CONF_HOME_IO_CONTROL_ID])
42 cg.add(var.set_parent(parent))