Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
switch.py
Go to the documentation of this file.
1## @file
2## @brief ESPHome binary switch platform schema and code generation.
3## @ingroup hioc_codegen
4##
5## Defines the experimental on/off switch integration and wires it to the shared hub.
6## Shared device-binding logic lives in platform_common.py; only switch-specific entity
7## construction/registration stays here. The hub-level "Accept Foreign Pairing (Key Extraction)"
8## switch is unrelated to this platform — it has no device to bind to, so it is not exposed
9## through `switch:` at all; see `accept_foreign_pairing` in `__init__.py`.
10
11import esphome.codegen as cg
12import esphome.config_validation as cv
13from esphome.components import switch
14from esphome.const import CONF_ID
15
16from . import home_io_control_ns
17from .platform_common import (
18 create_companion_sensors,
19 inject_companion_sensor_ids,
20 platform_schema_extension,
21 wire_device_binding,
22 CONF_HOME_IO_CONTROL_ID,
23)
24
25DEPENDENCIES = ["home_io_control"]
26
27IOHomeSwitch = home_io_control_ns.class_("IOHomeSwitch", switch.Switch, cg.Component)
28
29
31 return inject_companion_sensor_ids(config, CONF_ID)
32
33
34CONFIG_SCHEMA = cv.All(
35 # Switches are exposed as binary entities; a richer state model needs real-device evidence
36 # before it should be surfaced in the YAML schema.
37 switch.switch_schema(IOHomeSwitch)
38 .extend(platform_schema_extension())
39 .extend(cv.COMPONENT_SCHEMA),
40 _inject_companion_ids,
41)
42
43
44async def to_code(config):
45 var = cg.new_Pvariable(config[CONF_ID])
46 await cg.register_component(var, config)
47 await switch.register_switch(var, config)
48
49 parent = await cg.get_variable(config[CONF_HOME_IO_CONTROL_ID])
50 # The runtime entity stays small: Python codegen only wires it to the shared controller and
51 # provides the validated IO-homecontrol device ID.
52 await wire_device_binding(var, parent, config)
53 await create_companion_sensors(config, parent)
_inject_companion_ids(config)
Definition switch.py:30