FULL_DISPLAY_SCHEMA = BASIC_DISPLAY_SCHEMA.extend({ cv.Optional(CONF_ROTATION): validate_rotation, cv.Optional(CONF_PAGES): cv.All( cv.ensure_list({ cv.GenerateID(): cv.declare_id(DisplayPage), cv.Required(CONF_LAMBDA): cv.lambda_, }), cv.Length(min=1), ), cv.Optional(CONF_ON_PAGE_CHANGE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(DisplayOnPageChangeTrigger), cv.Optional(CONF_FROM): cv.use_id(DisplayPage), cv.Optional(CONF_TO): cv.use_id(DisplayPage), }), }) async def setup_display_core_(var, config): if CONF_ROTATION in config: cg.add(var.set_rotation(DISPLAY_ROTATIONS[config[CONF_ROTATION]])) if CONF_PAGES in config: pages = [] for conf in config[CONF_PAGES]: lambda_ = await cg.process_lambda(conf[CONF_LAMBDA], [(DisplayBufferRef, "it")], return_type=cg.void)
CONF_RC522_ID = "rc522_id" rc522_ns = cg.esphome_ns.namespace("rc522") RC522 = rc522_ns.class_("RC522", cg.PollingComponent, i2c.I2CDevice) RC522Trigger = rc522_ns.class_("RC522Trigger", automation.Trigger.template(cg.std_string)) RC522_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(RC522), cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema, cv.Optional(CONF_ON_TAG): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(RC522Trigger), }), }).extend(cv.polling_component_schema("1s")) @coroutine def setup_rc522(var, config): yield cg.register_component(var, config) if CONF_RESET_PIN in config: reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN]) cg.add(var.set_reset_pin(reset)) for conf in config.get(CONF_ON_TAG, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID]) cg.add(var.register_trigger(trigger))
logger.is_log_level, }), validate_message_just_topic, ), cv.Optional(CONF_SSL_FINGERPRINTS): cv.All(cv.only_on_esp8266, cv.ensure_list(validate_fingerprint)), cv.Optional(CONF_KEEPALIVE, default="15s"): cv.positive_time_period_seconds, cv.Optional(CONF_REBOOT_TIMEOUT, default="15min"): cv.positive_time_period_milliseconds, cv.Optional(CONF_ON_MESSAGE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MQTTMessageTrigger), cv.Required(CONF_TOPIC): cv.subscribe_topic, cv.Optional(CONF_QOS, default=0): cv.mqtt_qos, cv.Optional(CONF_PAYLOAD): cv.string_strict, }), cv.Optional(CONF_ON_JSON_MESSAGE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MQTTJsonMessageTrigger), cv.Required(CONF_TOPIC): cv.subscribe_topic, cv.Optional(CONF_QOS, default=0): cv.mqtt_qos, }), }), validate_config,
except pytz.UnknownTimeZoneError: # pylint: disable=broad-except return value return convert_tz(pytz_obj) TIME_SCHEMA = cv.Schema( { cv.Optional(CONF_TIMEZONE, default=detect_tz): validate_tz, cv.Optional(CONF_ON_TIME): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CronTrigger), cv.Optional(CONF_SECONDS): validate_cron_seconds, cv.Optional(CONF_MINUTES): validate_cron_minutes, cv.Optional(CONF_HOURS): validate_cron_hours, cv.Optional(CONF_DAYS_OF_MONTH): validate_cron_days_of_month, cv.Optional(CONF_MONTHS): validate_cron_months, cv.Optional(CONF_DAYS_OF_WEEK): validate_cron_days_of_week, cv.Optional(CONF_CRON): validate_cron_raw, cv.Optional(CONF_AT): validate_time_at, }, validate_cron_keys, ), cv.Optional(CONF_ON_TIME_SYNC): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SyncTrigger), } ), } ).extend(cv.polling_component_schema("15min"))
CONF_IDLE_ACTION, CONF_SENSOR, ) bang_bang_ns = cg.esphome_ns.namespace("bang_bang") BangBangClimate = bang_bang_ns.class_("BangBangClimate", climate.Climate, cg.Component) BangBangClimateTargetTempConfig = bang_bang_ns.struct("BangBangClimateTargetTempConfig") CONFIG_SCHEMA = cv.All( climate.CLIMATE_SCHEMA.extend( { cv.GenerateID(): cv.declare_id(BangBangClimate), cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor), cv.Required(CONF_DEFAULT_TARGET_TEMPERATURE_LOW): cv.temperature, cv.Required(CONF_DEFAULT_TARGET_TEMPERATURE_HIGH): cv.temperature, cv.Required(CONF_IDLE_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_COOL_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_HEAT_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_AWAY_CONFIG): cv.Schema( { cv.Required(CONF_DEFAULT_TARGET_TEMPERATURE_LOW): cv.temperature, cv.Required(CONF_DEFAULT_TARGET_TEMPERATURE_HIGH): cv.temperature, } ), } ).extend(cv.COMPONENT_SCHEMA), cv.has_at_least_one_key(CONF_COOL_ACTION, CONF_HEAT_ACTION), ) async def to_code(config):
# Actions Sim800LSendSmsAction = sim800l_ns.class_("Sim800LSendSmsAction", automation.Action) Sim800LDialAction = sim800l_ns.class_("Sim800LDialAction", automation.Action) CONF_ON_SMS_RECEIVED = "on_sms_received" CONF_RECIPIENT = "recipient" CONF_MESSAGE = "message" CONFIG_SCHEMA = cv.All( cv.Schema({ cv.GenerateID(): cv.declare_id(Sim800LComponent), cv.Optional(CONF_ON_SMS_RECEIVED): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(Sim800LReceivedMessageTrigger), }), }).extend(cv.polling_component_schema("5s")).extend( uart.UART_DEVICE_SCHEMA)) FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema("sim800l", require_tx=True, require_rx=True) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await uart.register_uart_device(var, config) for conf in config.get(CONF_ON_SMS_RECEIVED, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
"DECREMENT": NumberOperation.NUMBER_OP_DECREMENT, "TO_MIN": NumberOperation.NUMBER_OP_TO_MIN, "TO_MAX": NumberOperation.NUMBER_OP_TO_MAX, } icon = cv.icon NUMBER_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend( cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend({ cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTNumberComponent), cv.GenerateID(): cv.declare_id(Number), cv.Optional(CONF_ON_VALUE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(NumberStateTrigger), }), cv.Optional(CONF_ON_VALUE_RANGE): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ValueRangeTrigger), cv.Optional(CONF_ABOVE): cv.templatable(cv.float_), cv.Optional(CONF_BELOW): cv.templatable(cv.float_), }, cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW), ), cv.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string_strict, cv.Optional(CONF_MODE, default="AUTO"): cv.enum(NUMBER_MODES, upper=True),
import esphome.codegen as cg import esphome.config_validation as cv from esphome import automation from esphome.components import cover from esphome.const import CONF_CLOSE_ACTION, CONF_CLOSE_DURATION, CONF_ID, CONF_OPEN_ACTION, \ CONF_OPEN_DURATION, CONF_STOP_ACTION time_based_ns = cg.esphome_ns.namespace('time_based') TimeBasedCover = time_based_ns.class_('TimeBasedCover', cover.Cover, cg.Component) CONFIG_SCHEMA = cover.COVER_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(TimeBasedCover), cv.Required(CONF_STOP_ACTION): automation.validate_automation(single=True), cv.Required(CONF_OPEN_ACTION): automation.validate_automation(single=True), cv.Required(CONF_OPEN_DURATION): cv.positive_time_period_milliseconds, cv.Required(CONF_CLOSE_ACTION): automation.validate_automation(single=True), cv.Required(CONF_CLOSE_DURATION): cv.positive_time_period_milliseconds, }).extend(cv.COMPONENT_SCHEMA) def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield cover.register_cover(var, config) yield automation.build_automation(var.get_stop_trigger(), [], config[CONF_STOP_ACTION]) cg.add(var.set_open_duration(config[CONF_OPEN_DURATION])) yield automation.build_automation(var.get_open_trigger(), [], config[CONF_OPEN_ACTION])
try: value = ELEVATION_MAP[cv.one_of(*ELEVATION_MAP, lower=True, space='_')] except cv.Invalid: pass value = cv.angle(value) return cv.float_range(min=-180, max=180)(value) CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(Sun), cv.GenerateID(CONF_TIME_ID): cv.use_id(time.RealTimeClock), cv.Required(CONF_LATITUDE): cv.float_range(min=-90, max=90), cv.Required(CONF_LONGITUDE): cv.float_range(min=-180, max=180), cv.Optional(CONF_ON_SUNRISE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SunTrigger), cv.Optional(CONF_ELEVATION, default=0.0): elevation, }), cv.Optional(CONF_ON_SUNSET): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SunTrigger), cv.Optional(CONF_ELEVATION, default=0.0): elevation, }), }) def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) time_ = yield cg.get_variable(config[CONF_TIME_ID]) cg.add(var.set_time(time_)) cg.add(var.set_latitude(config[CONF_LATITUDE])) cg.add(var.set_longitude(config[CONF_LONGITUDE]))
cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTSensorComponent), vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string_strict, vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ACCURACY_DECIMALS): vol.Coerce(int), vol.Optional(CONF_EXPIRE_AFTER): vol.All(cv.requires_component('mqtt'), vol.Any(None, cv.positive_time_period_milliseconds)), vol.Optional(CONF_FILTERS): FILTERS_SCHEMA, vol.Optional(CONF_ON_VALUE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(SensorStateTrigger), }), vol.Optional(CONF_ON_RAW_VALUE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(SensorRawStateTrigger), }), vol.Optional(CONF_ON_VALUE_RANGE): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(ValueRangeTrigger), vol.Optional(CONF_ABOVE): cv.float_, vol.Optional(CONF_BELOW): cv.float_,
LightRestoreMode.LIGHT_RESTORE_INVERTED_DEFAULT_ON, "RESTORE_AND_OFF": LightRestoreMode.LIGHT_RESTORE_AND_OFF, "RESTORE_AND_ON": LightRestoreMode.LIGHT_RESTORE_AND_ON, } LIGHT_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend( cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend({ cv.GenerateID(): cv.declare_id(LightState), cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTJSONLightComponent), cv.Optional(CONF_RESTORE_MODE, default="restore_default_off"): cv.enum(RESTORE_MODES, upper=True, space="_"), cv.Optional(CONF_ON_TURN_ON): auto.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LightTurnOnTrigger), }), cv.Optional(CONF_ON_TURN_OFF): auto.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LightTurnOffTrigger), }), cv.Optional(CONF_ON_STATE): auto.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LightStateTrigger), }), }) BINARY_LIGHT_SCHEMA = LIGHT_SCHEMA.extend({ cv.Optional(CONF_EFFECTS):
from esphome import automation from esphome.components import output from esphome.const import CONF_ID, CONF_TYPE from .. import template_ns TemplateBinaryOutput = template_ns.class_('TemplateBinaryOutput', output.BinaryOutput) TemplateFloatOutput = template_ns.class_('TemplateFloatOutput', output.FloatOutput) CONF_BINARY = 'binary' CONF_FLOAT = 'float' CONF_WRITE_ACTION = 'write_action' CONFIG_SCHEMA = cv.typed_schema({ CONF_BINARY: output.BINARY_OUTPUT_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(TemplateBinaryOutput), cv.Required(CONF_WRITE_ACTION): automation.validate_automation(single=True), }), CONF_FLOAT: output.FLOAT_OUTPUT_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(TemplateFloatOutput), cv.Required(CONF_WRITE_ACTION): automation.validate_automation(single=True), }), }, lower=True) def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) if config[CONF_TYPE] == CONF_BINARY: yield automation.build_automation(var.get_trigger(), [(bool, 'state')], config[CONF_WRITE_ACTION]) else: yield automation.build_automation(var.get_trigger(), [(float, 'state')],
TemplateCoverRestoreMode = template_ns.enum('TemplateCoverRestoreMode') RESTORE_MODES = { 'NO_RESTORE': TemplateCoverRestoreMode.COVER_NO_RESTORE, 'RESTORE': TemplateCoverRestoreMode.COVER_RESTORE, 'RESTORE_AND_CALL': TemplateCoverRestoreMode.COVER_RESTORE_AND_CALL, } CONF_HAS_POSITION = 'has_position' CONFIG_SCHEMA = cover.COVER_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(TemplateCover), cv.Optional(CONF_LAMBDA): cv.returning_lambda, cv.Optional(CONF_OPTIMISTIC, default=False): cv.boolean, cv.Optional(CONF_ASSUMED_STATE, default=False): cv.boolean, cv.Optional(CONF_HAS_POSITION, default=False): cv.boolean, cv.Optional(CONF_OPEN_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_CLOSE_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_STOP_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_TILT_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_TILT_LAMBDA): cv.returning_lambda, cv.Optional(CONF_POSITION_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_RESTORE_MODE, default='RESTORE'): cv.enum(RESTORE_MODES, upper=True), }).extend(cv.COMPONENT_SCHEMA) def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield cover.register_cover(var, config) if CONF_LAMBDA in config: template_ = yield cg.process_lambda(config[CONF_LAMBDA], [],
import voluptuous as vol from esphome import automation from esphome.automation import ACTION_REGISTRY, maybe_simple_id import esphome.config_validation as cv from esphome.const import CONF_ID from esphome.cpp_generator import Pvariable, get_variable from esphome.cpp_types import Action, Trigger, esphome_ns Script = esphome_ns.class_('Script', Trigger.template()) ScriptExecuteAction = esphome_ns.class_('ScriptExecuteAction', Action) ScriptStopAction = esphome_ns.class_('ScriptStopAction', Action) CONFIG_SCHEMA = automation.validate_automation({ vol.Required(CONF_ID): cv.declare_variable_id(Script), }) def to_code(config): for conf in config: trigger = Pvariable(conf[CONF_ID], Script.new()) automation.build_automations(trigger, [], conf) CONF_SCRIPT_EXECUTE = 'script.execute' SCRIPT_EXECUTE_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID): cv.use_variable_id(Script), })
cv.Optional(CONF_BAUD_RATE, default=115200): cv.positive_int, cv.Optional(CONF_TX_BUFFER_SIZE, default=512): cv.validate_bytes, cv.Optional(CONF_HARDWARE_UART, default='UART0'): uart_selection, cv.Optional(CONF_LEVEL, default='DEBUG'): is_log_level, cv.Optional(CONF_LOGS, default={}): cv.Schema({ cv.string: is_log_level, }), cv.Optional(CONF_ON_MESSAGE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LoggerMessageTrigger), cv.Optional(CONF_LEVEL, default='WARN'): is_log_level, }), cv.SplitDefault(CONF_ESP8266_STORE_LOG_STRINGS_IN_FLASH, esp8266=True): cv.All(cv.only_on_esp8266, cv.boolean), }).extend(cv.COMPONENT_SCHEMA), validate_local_no_higher_than_global) @coroutine_with_priority(90.0) def to_code(config): baud_rate = config[CONF_BAUD_RATE] rhs = Logger.new( baud_rate, config[CONF_TX_BUFFER_SIZE], HARDWARE_UART_TO_UART_SELECTION[config[CONF_HARDWARE_UART]]) log = cg.Pvariable(config[CONF_ID], rhs) cg.add(log.pre_setup())
cv.GenerateID(): cv.declare_id(Sensor), cv.Optional(CONF_UNIT_OF_MEASUREMENT): unit_of_measurement, cv.Optional(CONF_ICON): icon, cv.Optional(CONF_ACCURACY_DECIMALS): accuracy_decimals, cv.Optional(CONF_DEVICE_CLASS): device_class, cv.Optional(CONF_STATE_CLASS): validate_state_class, cv.Optional(CONF_LAST_RESET_TYPE): validate_last_reset_type, cv.Optional(CONF_FORCE_UPDATE, default=False): cv.boolean, cv.Optional(CONF_EXPIRE_AFTER): cv.All( cv.requires_component("mqtt"), cv.Any(None, cv.positive_time_period_milliseconds), ), cv.Optional(CONF_FILTERS): validate_filters, cv.Optional(CONF_ON_VALUE): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SensorStateTrigger), } ), cv.Optional(CONF_ON_RAW_VALUE): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SensorRawStateTrigger), } ), cv.Optional(CONF_ON_VALUE_RANGE): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ValueRangeTrigger), cv.Optional(CONF_ABOVE): cv.float_, cv.Optional(CONF_BELOW): cv.float_, }, cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW), ),
cg.add(var.set_useragent(config[CONF_USERAGENT])) await cg.register_component(var, config) HTTP_REQUEST_ACTION_SCHEMA = cv.Schema({ cv.GenerateID(): cv.use_id(HttpRequestComponent), cv.Required(CONF_URL): cv.templatable(validate_url), cv.Optional(CONF_HEADERS): cv.All(cv.Schema({cv.string: cv.templatable(cv.string)})), cv.Optional(CONF_VERIFY_SSL, default=True): cv.boolean, cv.Optional(CONF_ON_RESPONSE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(HttpRequestResponseTrigger) }), }).add_extra(validate_secure_url) HTTP_REQUEST_GET_ACTION_SCHEMA = automation.maybe_conf( CONF_URL, HTTP_REQUEST_ACTION_SCHEMA.extend({ cv.Optional(CONF_METHOD, default="GET"): cv.one_of("GET", upper=True), }), ) HTTP_REQUEST_POST_ACTION_SCHEMA = automation.maybe_conf( CONF_URL, HTTP_REQUEST_ACTION_SCHEMA.extend({ cv.Optional(CONF_METHOD, default="POST"): cv.one_of("POST", upper=True), cv.Exclusive(CONF_BODY, "body"):
cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend({ cv.GenerateID(): cv.declare_id(FanState), cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTFanComponent), cv.Optional(CONF_OSCILLATION_STATE_TOPIC): cv.All(cv.requires_component("mqtt"), cv.publish_topic), cv.Optional(CONF_OSCILLATION_COMMAND_TOPIC): cv.All(cv.requires_component("mqtt"), cv.subscribe_topic), cv.Optional(CONF_SPEED_STATE_TOPIC): cv.All(cv.requires_component("mqtt"), cv.publish_topic), cv.Optional(CONF_SPEED_COMMAND_TOPIC): cv.All(cv.requires_component("mqtt"), cv.subscribe_topic), cv.Optional(CONF_ON_TURN_ON): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(FanTurnOnTrigger), }), cv.Optional(CONF_ON_TURN_OFF): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(FanTurnOffTrigger), }), }) async def setup_fan_core_(var, config): cg.add(var.set_name(config[CONF_NAME])) cg.add(var.set_disabled_by_default(config[CONF_DISABLED_BY_DEFAULT])) if CONF_INTERNAL in config: cg.add(var.set_internal(config[CONF_INTERNAL]))
return timings device_class = cv.one_of(*DEVICE_CLASSES, lower=True, space="_") BINARY_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend( { cv.GenerateID(): cv.declare_id(BinarySensor), cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id( mqtt.MQTTBinarySensorComponent ), cv.Optional(CONF_DEVICE_CLASS): device_class, cv.Optional(CONF_FILTERS): validate_filters, cv.Optional(CONF_ON_PRESS): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PressTrigger), } ), cv.Optional(CONF_ON_RELEASE): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ReleaseTrigger), } ), cv.Optional(CONF_ON_CLICK): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ClickTrigger), cv.Optional( CONF_MIN_LENGTH, default="50ms" ): cv.positive_time_period_milliseconds, cv.Optional( CONF_MAX_LENGTH, default="350ms"
spi.SPIDevice) PN532Trigger = binary_sensor.binary_sensor_ns.class_( 'PN532Trigger', Trigger.template(std_string)) CONFIG_SCHEMA = vol.Schema({ cv.GenerateID(): cv.declare_variable_id(PN532Component), cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent), vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, vol.Optional(CONF_ON_TAG): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(PN532Trigger), }), }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): for spi_ in get_variable(config[CONF_SPI_ID]): yield for cs in gpio_output_pin_expression(config[CONF_CS_PIN]): yield rhs = App.make_pn532_component(spi_, cs, config.get(CONF_UPDATE_INTERVAL)) pn532 = Pvariable(config[CONF_ID], rhs) for conf_ in config.get(CONF_ON_TAG, []): trigger = Pvariable(conf_[CONF_TRIGGER_ID], pn532.make_trigger()) automation.build_automation(trigger, std_string, conf_)
"SwitchTurnOnTrigger", automation.Trigger.template() ) SwitchTurnOffTrigger = switch_ns.class_( "SwitchTurnOffTrigger", automation.Trigger.template() ) icon = cv.icon SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend( { cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTSwitchComponent), cv.Optional(CONF_ICON): icon, cv.Optional(CONF_INVERTED): cv.boolean, cv.Optional(CONF_ON_TURN_ON): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SwitchTurnOnTrigger), } ), cv.Optional(CONF_ON_TURN_OFF): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SwitchTurnOffTrigger), } ), } ) @coroutine def setup_switch_core_(var, config): cg.add(var.set_name(config[CONF_NAME])) if CONF_INTERNAL in config:
cv.All(pins.internal_gpio_input_pin_schema, pins.validate_has_interrupt), cv.Required(CONF_PIN_B): cv.All(pins.internal_gpio_input_pin_schema, pins.validate_has_interrupt), cv.Optional(CONF_PIN_RESET): pins.internal_gpio_output_pin_schema, cv.Optional(CONF_RESOLUTION, default=1): cv.enum(RESOLUTIONS, int=True), cv.Optional(CONF_MIN_VALUE): cv.int_, cv.Optional(CONF_MAX_VALUE): cv.int_, cv.Optional(CONF_ON_CLOCKWISE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(RotaryEncoderClockwiseTrigger), }), cv.Optional(CONF_ON_ANTICLOCKWISE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(RotaryEncoderAnticlockwiseTrigger), }), }).extend(cv.COMPONENT_SCHEMA), validate_min_max_value, ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await sensor.register_sensor(var, config)
CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(APIServer), cv.Optional(CONF_PORT, default=6053): cv.port, cv.Optional(CONF_PASSWORD, default=''): cv.string_strict, cv.Optional(CONF_REBOOT_TIMEOUT, default='15min'): cv.positive_time_period_milliseconds, cv.Optional(CONF_SERVICES): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(UserServiceTrigger), cv.Required(CONF_SERVICE): cv.valid_name, cv.Optional(CONF_VARIABLES, default={}): cv.Schema({ cv.validate_id_name: cv.one_of(*SERVICE_ARG_NATIVE_TYPES, lower=True), }), }), }).extend(cv.COMPONENT_SCHEMA) @coroutine_with_priority(40.0) def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) cg.add(var.set_port(config[CONF_PORT])) cg.add(var.set_password(config[CONF_PASSWORD]))
CONFIG_SCHEMA = cv.All( sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 0, DEVICE_CLASS_EMPTY).extend({ cv.GenerateID(): cv.declare_id(BLESensor), cv.Required(CONF_SERVICE_UUID): esp32_ble_tracker.bt_uuid, cv.Required(CONF_CHARACTERISTIC_UUID): esp32_ble_tracker.bt_uuid, cv.Optional(CONF_DESCRIPTOR_UUID): esp32_ble_tracker.bt_uuid, cv.Optional(CONF_NOTIFY, default=False): cv.boolean, cv.Optional(CONF_ON_NOTIFY): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(BLESensorNotifyTrigger), }), }).extend(cv.polling_component_schema("60s")).extend( ble_client.BLE_CLIENT_SCHEMA)) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) if len(config[CONF_SERVICE_UUID]) == len( esp32_ble_tracker.bt_uuid16_format): cg.add( var.set_service_uuid16( esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID]))) elif len(config[CONF_SERVICE_UUID]) == len( esp32_ble_tracker.bt_uuid32_format): cg.add(
map_ = cg.std_ns.class_("map").template(cg.std_string, cg.std_string) return cg.new_Pvariable( filter_id, map_([(item[CONF_FROM], item[CONF_TO]) for item in config])) TEXT_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend( cv.MQTT_COMPONENT_SCHEMA).extend({ cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTTextSensor), cv.GenerateID(): cv.declare_id(TextSensor), cv.Optional(CONF_FILTERS): validate_filters, cv.Optional(CONF_ON_VALUE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(TextSensorStateTrigger), }), cv.Optional(CONF_ON_RAW_VALUE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(TextSensorStateRawTrigger), }), }) _UNDEF = object() def text_sensor_schema( class_: MockObjClass = _UNDEF, *, icon: str = _UNDEF,
# pylint: disable=invalid-name text_sensor_ns = esphome_ns.namespace('text_sensor') TextSensor = text_sensor_ns.class_('TextSensor', Nameable) TextSensorPtr = TextSensor.operator('ptr') MQTTTextSensor = text_sensor_ns.class_('MQTTTextSensor', mqtt.MQTTComponent) TextSensorStateTrigger = text_sensor_ns.class_('TextSensorStateTrigger', Trigger.template(std_string)) TextSensorPublishAction = text_sensor_ns.class_('TextSensorPublishAction', Action) TEXT_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({ cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTTextSensor), vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ON_VALUE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(TextSensorStateTrigger), }), }) TEXT_SENSOR_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(TEXT_SENSOR_SCHEMA.schema) def setup_text_sensor_core_(text_sensor_var, config): if CONF_INTERNAL in config: add(text_sensor_var.set_internal(config[CONF_INTERNAL])) if CONF_ICON in config: add(text_sensor_var.set_icon(config[CONF_ICON])) for conf in config.get(CONF_ON_VALUE, []): rhs = text_sensor_var.make_state_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
if config_req_action in config: return config raise cv.Invalid( f"At least one of {CONF_FAN_MODE_ON_ACTION}, {CONF_FAN_MODE_OFF_ACTION}, {CONF_FAN_MODE_AUTO_ACTION}, {CONF_FAN_MODE_LOW_ACTION}, {CONF_FAN_MODE_MEDIUM_ACTION}, {CONF_FAN_MODE_HIGH_ACTION}, {CONF_FAN_MODE_MIDDLE_ACTION}, {CONF_FAN_MODE_FOCUS_ACTION}, {CONF_FAN_MODE_DIFFUSE_ACTION} must be defined to use {CONF_MIN_FAN_MODE_SWITCHING_TIME}" ) return config CONFIG_SCHEMA = cv.All( climate.CLIMATE_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(ThermostatClimate), cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor), cv.Required(CONF_IDLE_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_COOL_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_SUPPLEMENTAL_COOLING_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_DRY_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_FAN_ONLY_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_HEAT_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_SUPPLEMENTAL_HEATING_ACTION): automation.validate_automation(single=True), cv.Optional(CONF_AUTO_MODE): automation.validate_automation(single=True), cv.Optional(CONF_COOL_MODE):
cv.Optional(CONF_ARDUINO_VERSION, default="recommended"): validate_arduino_version, cv.Optional(CONF_BUILD_PATH, default=default_build_path): cv.string, cv.Optional(CONF_PLATFORMIO_OPTIONS, default={}): cv.Schema({ cv.string_strict: cv.Any([cv.string], cv.string), }), cv.SplitDefault(CONF_ESP8266_RESTORE_FROM_FLASH, esp8266=False): cv.All(cv.only_on_esp8266, cv.boolean), cv.SplitDefault(CONF_BOARD_FLASH_MODE, esp8266="dout"): cv.one_of(*BUILD_FLASH_MODES, lower=True), cv.Optional(CONF_ON_BOOT): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(StartupTrigger), cv.Optional(CONF_PRIORITY, default=600.0): cv.float_, }), cv.Optional(CONF_ON_SHUTDOWN): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ShutdownTrigger), }), cv.Optional(CONF_ON_LOOP): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LoopTrigger), }), cv.Optional(CONF_INCLUDES, default=[]): cv.ensure_list(valid_include), cv.Optional(CONF_LIBRARIES, default=[]):
SetEqAction = dfplayer_ns.class_("SetEqAction", automation.Action) SleepAction = dfplayer_ns.class_("SleepAction", automation.Action) ResetAction = dfplayer_ns.class_("ResetAction", automation.Action) StartAction = dfplayer_ns.class_("StartAction", automation.Action) PauseAction = dfplayer_ns.class_("PauseAction", automation.Action) StopAction = dfplayer_ns.class_("StopAction", automation.Action) RandomAction = dfplayer_ns.class_("RandomAction", automation.Action) SetDeviceAction = dfplayer_ns.class_("SetDeviceAction", automation.Action) CONFIG_SCHEMA = cv.All( cv.Schema({ cv.GenerateID(): cv.declare_id(DFPlayer), cv.Optional(CONF_ON_FINISHED_PLAYBACK): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(DFPlayerFinishedPlaybackTrigger), }), }).extend(uart.UART_DEVICE_SCHEMA)) FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema("dfplayer", baud_rate=9600, require_tx=True) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await uart.register_uart_device(var, config) for conf in config.get(CONF_ON_FINISHED_PLAYBACK, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var) await automation.build_automation(trigger, [], conf)
SetupTrigger = nextion_ns.class_("SetupTrigger", automation.Trigger.template()) SleepTrigger = nextion_ns.class_("SleepTrigger", automation.Trigger.template()) WakeTrigger = nextion_ns.class_("WakeTrigger", automation.Trigger.template()) PageTrigger = nextion_ns.class_("PageTrigger", automation.Trigger.template()) CONFIG_SCHEMA = (display.BASIC_DISPLAY_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(Nextion), cv.Optional(CONF_TFT_URL): cv.All(cv.string, cv.only_with_arduino), cv.Optional(CONF_BRIGHTNESS, default=1.0): cv.percentage, cv.Optional(CONF_ON_SETUP): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SetupTrigger), }), cv.Optional(CONF_ON_SLEEP): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SleepTrigger), }), cv.Optional(CONF_ON_WAKE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(WakeTrigger), }), cv.Optional(CONF_ON_PAGE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PageTrigger),