def to_code(config): rhs = App.make_deep_sleep_component() deep_sleep = Pvariable(config[CONF_ID], rhs) if CONF_SLEEP_DURATION in config: add(deep_sleep.set_sleep_duration(config[CONF_SLEEP_DURATION])) if CONF_WAKEUP_PIN in config: for pin in gpio_input_pin_expression(config[CONF_WAKEUP_PIN]): yield add(deep_sleep.set_wakeup_pin(pin)) if CONF_WAKEUP_PIN_MODE in config: add( deep_sleep.set_wakeup_pin_mode( WAKEUP_PIN_MODES[config[CONF_WAKEUP_PIN_MODE]])) if CONF_RUN_DURATION in config: add(deep_sleep.set_run_duration(config[CONF_RUN_DURATION])) if CONF_ESP32_EXT1_WAKEUP in config: conf = config[CONF_ESP32_EXT1_WAKEUP] mask = 0 for pin in conf[CONF_PINS]: mask |= 1 << pin[CONF_NUMBER] struct = StructInitializer( Ext1Wakeup, ('mask', mask), ('wakeup_mode', EXT1_WAKEUP_MODES[conf[CONF_MODE]])) add(deep_sleep.set_ext1_wakeup(struct)) setup_component(deep_sleep, config)
def exp_mqtt_message(config): if config is None: return optional(TemplateArguments(MQTTMessage)) exp = StructInitializer(MQTTMessage, ('topic', config[CONF_TOPIC]), ('payload', config.get(CONF_PAYLOAD, "")), ('qos', config[CONF_QOS]), ('retain', config[CONF_RETAIN])) return exp
def setup_binary_sensor_core_(binary_sensor_var, config): if CONF_INTERNAL in config: add(binary_sensor_var.set_internal(CONF_INTERNAL)) if CONF_DEVICE_CLASS in config: add(binary_sensor_var.set_device_class(config[CONF_DEVICE_CLASS])) if CONF_INVERTED in config: add(binary_sensor_var.set_inverted(config[CONF_INVERTED])) if CONF_FILTERS in config: for filters in setup_filters(config[CONF_FILTERS]): yield add(binary_sensor_var.add_filters(filters)) for conf in config.get(CONF_ON_PRESS, []): rhs = binary_sensor_var.make_press_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_RELEASE, []): rhs = binary_sensor_var.make_release_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_CLICK, []): rhs = binary_sensor_var.make_click_trigger(conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH]) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_DOUBLE_CLICK, []): rhs = binary_sensor_var.make_double_click_trigger( conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH]) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_MULTI_CLICK, []): timings = [] for tim in conf[CONF_TIMING]: timings.append( StructInitializer( MultiClickTriggerEvent, ('state', tim[CONF_STATE]), ('min_length', tim[CONF_MIN_LENGTH]), ('max_length', tim.get(CONF_MAX_LENGTH, 4294967294)), )) rhs = App.register_component( binary_sensor_var.make_multi_click_trigger(timings)) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) if CONF_INVALID_COOLDOWN in conf: add(trigger.set_invalid_cooldown(conf[CONF_INVALID_COOLDOWN])) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_STATE, []): rhs = binary_sensor_var.make_state_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, bool_, conf) setup_mqtt_component(binary_sensor_var.Pget_mqtt(), config)
def manual_ip(config): if config is None: return None return StructInitializer( ManualIP, ('static_ip', safe_ip(config[CONF_STATIC_IP])), ('gateway', safe_ip(config[CONF_GATEWAY])), ('subnet', safe_ip(config[CONF_SUBNET])), ('dns1', safe_ip(config.get(CONF_DNS1))), ('dns2', safe_ip(config.get(CONF_DNS2))), )