Home IO Control
ESPHome add-on for IO-Homecontrol devices
Toggle main menu visibility
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 "Recover System Key" (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
11
import
esphome.codegen
as
cg
12
import
esphome.config_validation
as
cv
13
from
esphome.components
import
switch
14
from
esphome.const
import
CONF_ID
15
16
from
.
import
home_io_control_ns
17
from
.platform_common
import
(
18
create_companion_sensors,
19
inject_companion_sensor_ids,
20
platform_schema_extension,
21
validate_device_model,
22
warn_if_experimental_kind,
23
wire_device_binding,
24
CONF_HOME_IO_CONTROL_ID,
25
)
26
27
DEPENDENCIES = [
"home_io_control"
]
28
29
IOHomeSwitch = home_io_control_ns.class_(
"IOHomeSwitch"
, switch.Switch, cg.Component)
30
31
32
def
_inject_companion_ids
(config):
33
return
inject_companion_sensor_ids(config, CONF_ID)
34
35
36
CONFIG_SCHEMA = cv.All(
37
# Switches are exposed as binary entities; a richer state model needs real-device evidence
38
# before it should be surfaced in the YAML schema.
39
switch.switch_schema(IOHomeSwitch)
40
.extend(platform_schema_extension())
41
.extend(cv.COMPONENT_SCHEMA),
42
validate_device_model,
43
warn_if_experimental_kind,
44
_inject_companion_ids,
45
)
46
47
48
async def
to_code
(config):
49
var = cg.new_Pvariable(config[CONF_ID])
50
await cg.register_component(var, config)
51
await switch.register_switch(var, config)
52
53
parent = await cg.get_variable(config[CONF_HOME_IO_CONTROL_ID])
54
# The runtime entity stays small: Python codegen only wires it to the shared controller and
55
# provides the validated IO-homecontrol device ID.
56
await wire_device_binding(var, parent, config)
57
await create_companion_sensors(config, parent)
home_io_control.switch.to_code
to_code(config)
Definition
switch.py:48
home_io_control.switch._inject_companion_ids
_inject_companion_ids(config)
Definition
switch.py:32
components
home_io_control
switch.py
Generated by
1.18.0