|
2 | 2 | import esphome.config_validation as cv
|
3 | 3 | import voluptuous as vol
|
4 | 4 | from esphome import automation, pins
|
5 |
| -from esphome.const import CONF_ID, CONF_TRIGGER_ID |
6 | 5 | from esphome.components import binary_sensor
|
| 6 | +from esphome.const import CONF_ID, CONF_TRIGGER_ID |
7 | 7 |
|
8 | 8 | DEPENDENCIES = ["preferences"]
|
9 | 9 | MULTI_CONF = True
|
|
44 | 44 | CONF_DRY_CONTACT_CLOSE_SENSOR = "dry_contact_close_sensor"
|
45 | 45 | CONF_DRY_CONTACT_SENSOR_GROUP = "dry_contact_sensor_group"
|
46 | 46 |
|
| 47 | + |
47 | 48 | def validate_protocol(config):
|
48 |
| - if config.get(CONF_PROTOCOL, None) == PROTOCOL_DRYCONTACT and (CONF_DRY_CONTACT_CLOSE_SENSOR not in config or CONF_DRY_CONTACT_OPEN_SENSOR not in config): |
49 |
| - raise cv.Invalid("dry_contact_close_sensor and dry_contact_open_sensor are required when using protocol drycontact") |
50 |
| - if config.get(CONF_PROTOCOL, None) != PROTOCOL_DRYCONTACT and (CONF_DRY_CONTACT_CLOSE_SENSOR in config or CONF_DRY_CONTACT_OPEN_SENSOR in config): |
51 |
| - raise cv.Invalid("dry_contact_close_sensor and dry_contact_open_sensor are only valid when using protocol drycontact") |
52 |
| -# if config.get(CONF_PROTOCOL, None) == PROTOCOL_DRYCONTACT and CONF_DRY_CONTACT_OPEN_SENSOR not in config: |
53 |
| -# raise cv.Invalid("dry_contact_open_sensor is required when using protocol drycontact") |
| 49 | + if config.get(CONF_PROTOCOL, None) == PROTOCOL_DRYCONTACT and ( |
| 50 | + CONF_DRY_CONTACT_CLOSE_SENSOR not in config |
| 51 | + or CONF_DRY_CONTACT_OPEN_SENSOR not in config |
| 52 | + ): |
| 53 | + raise cv.Invalid( |
| 54 | + "dry_contact_close_sensor and dry_contact_open_sensor are required when using protocol drycontact" |
| 55 | + ) |
| 56 | + if config.get(CONF_PROTOCOL, None) != PROTOCOL_DRYCONTACT and ( |
| 57 | + CONF_DRY_CONTACT_CLOSE_SENSOR in config |
| 58 | + or CONF_DRY_CONTACT_OPEN_SENSOR in config |
| 59 | + ): |
| 60 | + raise cv.Invalid( |
| 61 | + "dry_contact_close_sensor and dry_contact_open_sensor are only valid when using protocol drycontact" |
| 62 | + ) |
| 63 | + # if config.get(CONF_PROTOCOL, None) == PROTOCOL_DRYCONTACT and CONF_DRY_CONTACT_OPEN_SENSOR not in config: |
| 64 | + # raise cv.Invalid("dry_contact_open_sensor is required when using protocol drycontact") |
54 | 65 | return config
|
55 | 66 |
|
| 67 | + |
56 | 68 | CONFIG_SCHEMA = cv.All(
|
57 | 69 | cv.Schema(
|
58 |
| - { |
59 |
| - cv.GenerateID(): cv.declare_id(RATGDO), |
60 |
| - cv.Optional( |
61 |
| - CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO |
62 |
| - ): pins.gpio_output_pin_schema, |
63 |
| - cv.Optional( |
64 |
| - CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO |
65 |
| - ): pins.gpio_input_pin_schema, |
66 |
| - cv.Optional(CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST): cv.Any( |
67 |
| - cv.none, pins.gpio_input_pin_schema |
68 |
| - ), |
69 |
| - cv.Optional(CONF_DISCRETE_OPEN_PIN): pins.gpio_output_pin_schema, |
70 |
| - cv.Optional(CONF_DISCRETE_CLOSE_PIN): pins.gpio_output_pin_schema, |
71 |
| - cv.Optional(CONF_ON_SYNC_FAILED): automation.validate_automation( |
72 |
| - { |
73 |
| - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SyncFailed), |
74 |
| - } |
75 |
| - ), |
76 |
| - cv.Optional(CONF_PROTOCOL, default=PROTOCOL_SECPLUSV2): cv.All(vol.In( |
77 |
| - SUPPORTED_PROTOCOLS |
78 |
| - )), |
79 |
| - # cv.Inclusive(CONF_DRY_CONTACT_OPEN_SENSOR,CONF_DRY_CONTACT_SENSOR_GROUP): cv.use_id(binary_sensor.BinarySensor), |
80 |
| - # cv.Inclusive(CONF_DRY_CONTACT_CLOSE_SENSOR,CONF_DRY_CONTACT_SENSOR_GROUP): cv.use_id(binary_sensor.BinarySensor), |
81 |
| - cv.Optional(CONF_DRY_CONTACT_OPEN_SENSOR): cv.use_id(binary_sensor.BinarySensor), |
82 |
| - cv.Optional(CONF_DRY_CONTACT_CLOSE_SENSOR): cv.use_id(binary_sensor.BinarySensor), |
83 |
| - } |
| 70 | + { |
| 71 | + cv.GenerateID(): cv.declare_id(RATGDO), |
| 72 | + cv.Optional( |
| 73 | + CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO |
| 74 | + ): pins.gpio_output_pin_schema, |
| 75 | + cv.Optional( |
| 76 | + CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO |
| 77 | + ): pins.gpio_input_pin_schema, |
| 78 | + cv.Optional(CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST): cv.Any( |
| 79 | + cv.none, pins.gpio_input_pin_schema |
| 80 | + ), |
| 81 | + cv.Optional(CONF_DISCRETE_OPEN_PIN): pins.gpio_output_pin_schema, |
| 82 | + cv.Optional(CONF_DISCRETE_CLOSE_PIN): pins.gpio_output_pin_schema, |
| 83 | + cv.Optional(CONF_ON_SYNC_FAILED): automation.validate_automation( |
| 84 | + { |
| 85 | + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SyncFailed), |
| 86 | + } |
| 87 | + ), |
| 88 | + cv.Optional(CONF_PROTOCOL, default=PROTOCOL_SECPLUSV2): cv.All( |
| 89 | + vol.In(SUPPORTED_PROTOCOLS) |
| 90 | + ), |
| 91 | + # cv.Inclusive(CONF_DRY_CONTACT_OPEN_SENSOR,CONF_DRY_CONTACT_SENSOR_GROUP): cv.use_id(binary_sensor.BinarySensor), |
| 92 | + # cv.Inclusive(CONF_DRY_CONTACT_CLOSE_SENSOR,CONF_DRY_CONTACT_SENSOR_GROUP): cv.use_id(binary_sensor.BinarySensor), |
| 93 | + cv.Optional(CONF_DRY_CONTACT_OPEN_SENSOR): cv.use_id( |
| 94 | + binary_sensor.BinarySensor |
| 95 | + ), |
| 96 | + cv.Optional(CONF_DRY_CONTACT_CLOSE_SENSOR): cv.use_id( |
| 97 | + binary_sensor.BinarySensor |
| 98 | + ), |
| 99 | + } |
84 | 100 | ).extend(cv.COMPONENT_SCHEMA),
|
85 | 101 | validate_protocol,
|
86 | 102 | )
|
@@ -109,11 +125,18 @@ async def to_code(config):
|
109 | 125 | cg.add(var.set_input_obst_pin(pin))
|
110 | 126 |
|
111 | 127 | if CONF_DRY_CONTACT_OPEN_SENSOR in config and config[CONF_DRY_CONTACT_OPEN_SENSOR]:
|
112 |
| - dry_contact_open_sensor = await cg.get_variable(config[CONF_DRY_CONTACT_OPEN_SENSOR]) |
| 128 | + dry_contact_open_sensor = await cg.get_variable( |
| 129 | + config[CONF_DRY_CONTACT_OPEN_SENSOR] |
| 130 | + ) |
113 | 131 | cg.add(var.set_dry_contact_open_sensor(dry_contact_open_sensor))
|
114 | 132 |
|
115 |
| - if CONF_DRY_CONTACT_CLOSE_SENSOR in config and config[CONF_DRY_CONTACT_CLOSE_SENSOR]: |
116 |
| - dry_contact_close_sensor = await cg.get_variable(config[CONF_DRY_CONTACT_CLOSE_SENSOR]) |
| 133 | + if ( |
| 134 | + CONF_DRY_CONTACT_CLOSE_SENSOR in config |
| 135 | + and config[CONF_DRY_CONTACT_CLOSE_SENSOR] |
| 136 | + ): |
| 137 | + dry_contact_close_sensor = await cg.get_variable( |
| 138 | + config[CONF_DRY_CONTACT_CLOSE_SENSOR] |
| 139 | + ) |
117 | 140 | cg.add(var.set_dry_contact_close_sensor(dry_contact_close_sensor))
|
118 | 141 |
|
119 | 142 | for conf in config.get(CONF_ON_SYNC_FAILED, []):
|
|
0 commit comments