CONF_ADDRESSABLE_LAMBDA = "addressable_lambda" CONF_ADDRESSABLE_RAINBOW = "addressable_rainbow" CONF_ADDRESSABLE_COLOR_WIPE = "addressable_color_wipe" CONF_ADDRESSABLE_SCAN = "addressable_scan" CONF_ADDRESSABLE_TWINKLE = "addressable_twinkle" CONF_ADDRESSABLE_RANDOM_TWINKLE = "addressable_random_twinkle" CONF_ADDRESSABLE_FIREWORKS = "addressable_fireworks" CONF_ADDRESSABLE_FLICKER = "addressable_flicker" CONF_AUTOMATION = "automation" BINARY_EFFECTS = [] MONOCHROMATIC_EFFECTS = [] RGB_EFFECTS = [] ADDRESSABLE_EFFECTS = [] EFFECTS_REGISTRY = Registry() def register_effect(name, effect_type, default_name, schema, *extra_validators): schema = cv.Schema(schema).extend({ cv.Optional(CONF_NAME, default=default_name): cv.string_strict, }) validator = cv.All(schema, *extra_validators) return EFFECTS_REGISTRY.register(name, effect_type, validator) def register_binary_effect(name, effect_type, default_name, schema, *extra_validators): # binary effect can be used for all lights
return decorator def declare_protocol(name): data = ns.struct(f"{name}Data") binary_sensor_ = ns.class_(f"{name}BinarySensor", RemoteReceiverBinarySensorBase) trigger = ns.class_(f"{name}Trigger", RemoteReceiverTrigger) action = ns.class_(f"{name}Action", RemoteTransmitterActionBase) dumper = ns.class_(f"{name}Dumper", RemoteTransmitterDumper) return data, binary_sensor_, trigger, action, dumper BINARY_SENSOR_REGISTRY = Registry( binary_sensor.BINARY_SENSOR_SCHEMA.extend({ cv.GenerateID(CONF_RECEIVER_ID): cv.use_id(RemoteReceiverBase), })) validate_binary_sensor = cv.validate_registry_entry("remote receiver", BINARY_SENSOR_REGISTRY) TRIGGER_REGISTRY = SimpleRegistry() DUMPER_REGISTRY = Registry({ cv.Optional(CONF_RECEIVER_ID): cv.invalid( "This has been removed in ESPHome 1.20.0 and the dumper attaches directly to the parent receiver." ), }) def validate_dumpers(value): if isinstance(value, str) and value.lower() == "all":
cg.Component) MultiClickTriggerEvent = binary_sensor_ns.struct('MultiClickTriggerEvent') StateTrigger = binary_sensor_ns.class_('StateTrigger', automation.Trigger.template(bool)) BinarySensorPublishAction = binary_sensor_ns.class_('BinarySensorPublishAction', automation.Action) # Condition BinarySensorCondition = binary_sensor_ns.class_('BinarySensorCondition', Condition) # Filters Filter = binary_sensor_ns.class_('Filter') DelayedOnFilter = binary_sensor_ns.class_('DelayedOnFilter', Filter, cg.Component) DelayedOffFilter = binary_sensor_ns.class_('DelayedOffFilter', Filter, cg.Component) InvertFilter = binary_sensor_ns.class_('InvertFilter', Filter) LambdaFilter = binary_sensor_ns.class_('LambdaFilter', Filter) FILTER_REGISTRY = Registry() validate_filters = cv.validate_registry('filter', FILTER_REGISTRY) @FILTER_REGISTRY.register('invert', InvertFilter, {}) def invert_filter_to_code(config, filter_id): yield cg.new_Pvariable(filter_id) @FILTER_REGISTRY.register('delayed_on', DelayedOnFilter, cv.positive_time_period_milliseconds) def delayed_on_filter_to_code(config, filter_id): var = cg.new_Pvariable(filter_id, config) yield cg.register_component(var, {}) yield var
return decorator def declare_protocol(name): data = ns.struct('{}Data'.format(name)) binary_sensor_ = ns.class_('{}BinarySensor'.format(name), RemoteReceiverBinarySensorBase) trigger = ns.class_('{}Trigger'.format(name), RemoteReceiverTrigger) action = ns.class_('{}Action'.format(name), RemoteTransmitterActionBase) dumper = ns.class_('{}Dumper'.format(name), RemoteTransmitterDumper) return data, binary_sensor_, trigger, action, dumper BINARY_SENSOR_REGISTRY = Registry( binary_sensor.BINARY_SENSOR_SCHEMA.extend({ cv.GenerateID(CONF_RECEIVER_ID): cv.use_id(RemoteReceiverBase), })) validate_binary_sensor = cv.validate_registry_entry('remote receiver', BINARY_SENSOR_REGISTRY) TRIGGER_REGISTRY = SimpleRegistry() DUMPER_REGISTRY = Registry({ cv.GenerateID(CONF_RECEIVER_ID): cv.use_id(RemoteReceiverBase), }) def validate_dumpers(value): if isinstance(value, string_types) and value.lower() == 'all': return validate_dumpers(list(DUMPER_REGISTRY.keys())) return cv.validate_registry('dumper', DUMPER_REGISTRY)(value)
import esphome.codegen as cg import esphome.config_validation as cv import esphome.const as ehc from esphome.core import coroutine from esphome.util import Registry from . import const as c from . import cpp_types as t PAYLOAD_SETTER_REGISTRY = Registry(None, ehc.CONF_ID) def register_payload_setter(name, payloadtype_type, schema): return PAYLOAD_SETTER_REGISTRY.register(name, payloadtype_type, schema) validate_payload_setter_list = cv.validate_registry('payload', PAYLOAD_SETTER_REGISTRY) @coroutine def build_payload_setter(full_config, template_arg, args): registry_entry, config = cg.extract_registry_entry_config( PAYLOAD_SETTER_REGISTRY, full_config) builder = registry_entry.coroutine_fun yield builder(config, config[ehc.CONF_ID], template_arg, args) @coroutine def build_payload_setter_list(config, templ, arg_type): payloads = []
return validator({conf: value}) return validate def register_action(name, action_type, schema): return ACTION_REGISTRY.register(name, action_type, schema) def register_condition(name, condition_type, schema): return CONDITION_REGISTRY.register(name, condition_type, schema) Action = cg.esphome_ns.class_("Action") Trigger = cg.esphome_ns.class_("Trigger") ACTION_REGISTRY = Registry() Condition = cg.esphome_ns.class_("Condition") CONDITION_REGISTRY = Registry() validate_action = cv.validate_registry_entry("action", ACTION_REGISTRY) validate_action_list = cv.validate_registry("action", ACTION_REGISTRY) validate_condition = cv.validate_registry_entry("condition", CONDITION_REGISTRY) validate_condition_list = cv.validate_registry("condition", CONDITION_REGISTRY) def validate_potentially_and_condition(value): if isinstance(value, list): with cv.remove_prepend_path(["and"]): return validate_condition({"and": value}) return validate_condition(value)