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
wire_device_binding,
22
CONF_HOME_IO_CONTROL_ID,
23
)
24
25
DEPENDENCIES = [
"home_io_control"
]
26
27
IOHomeSwitch = home_io_control_ns.class_(
"IOHomeSwitch"
, switch.Switch, cg.Component)
28
29
30
def
_inject_companion_ids
(config):
31
return
inject_companion_sensor_ids(config, CONF_ID)
32
33
34
CONFIG_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
44
async 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)
home_io_control.switch.to_code
to_code(config)
Definition
switch.py:44
home_io_control.switch._inject_companion_ids
_inject_companion_ids(config)
Definition
switch.py:30
components
home_io_control
switch.py
Generated by
1.18.0