def to_code(config): rhs = App.make_esp32_ble_tracker() ble = Pvariable(config[CONF_ID], rhs) if CONF_SCAN_INTERVAL in config: add(ble.set_scan_interval(config[CONF_SCAN_INTERVAL])) setup_component(ble, config)
def delay_action_to_code(config, action_id, template_arg, args): rhs = App.register_component(DelayAction.new(template_arg)) type = DelayAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config, args, uint32): yield add(action.set_delay(template_)) yield action
def to_code(config): rhs = App.make_bh1750_sensor(config[CONF_NAME], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) bh1750 = Pvariable(config[CONF_ID], rhs) if CONF_RESOLUTION in config: add(bh1750.set_resolution(BH1750_RESOLUTIONS[config[CONF_RESOLUTION]])) sensor.setup_sensor(bh1750, config) setup_component(bh1750, config)
def to_code(config): rhs = App.make_apds9960(config.get(CONF_UPDATE_INTERVAL)) var = Pvariable(config[CONF_ID], rhs) if CONF_ADDRESS in config: add(var.set_address(config[CONF_ADDRESS])) setup_component(var, config)
def to_code(config): rhs = App.init_i2c(config[CONF_SDA], config[CONF_SCL], config.get(CONF_SCAN)) i2c = Pvariable(config[CONF_ID], rhs) if CONF_FREQUENCY in config: add(i2c.set_frequency(config[CONF_FREQUENCY])) setup_component(i2c, config)
def to_code(config): rhs = App.make_mqtt_subscribe_sensor(config[CONF_NAME], config[CONF_TOPIC]) subs = Pvariable(config[CONF_ID], rhs) if CONF_QOS in config: add(subs.set_qos(config[CONF_QOS])) sensor.setup_sensor(subs, config) setup_component(subs, config)
def to_code(config): rhs = App.make_dht12_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) dht = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(dht.Pget_temperature_sensor(), config[CONF_TEMPERATURE]) sensor.setup_sensor(dht.Pget_humidity_sensor(), config[CONF_HUMIDITY]) setup_component(dht, config)
def to_code(config): rhs = App.init_ota() ota = Pvariable(config[CONF_ID], rhs) if CONF_PASSWORD in config: add(ota.set_auth_password(config[CONF_PASSWORD])) if CONF_PORT in config: add(ota.set_port(config[CONF_PORT])) if config[CONF_SAFE_MODE]: add(ota.start_safe_mode())
def to_code(config): rhs = App.init_web_server(config.get(CONF_PORT)) web_server = Pvariable(config[CONF_ID], rhs) if CONF_CSS_URL in config: add(web_server.set_css_url(config[CONF_CSS_URL])) if CONF_JS_URL in config: add(web_server.set_js_url(config[CONF_JS_URL])) setup_component(web_server, config)
def to_code(config): rhs = App.init_log( config.get(CONF_BAUD_RATE), config.get(CONF_TX_BUFFER_SIZE), HARDWARE_UART_TO_UART_SELECTION[config.get(CONF_HARDWARE_UART)]) log = Pvariable(config[CONF_ID], rhs) if CONF_LEVEL in config: add(log.set_global_log_level(LOG_LEVELS[config[CONF_LEVEL]])) for tag, level in config.get(CONF_LOGS, {}).items(): add(log.set_log_level(tag, LOG_LEVELS[level]))
def build_automation_(trigger, args, config): arg_types = [arg[0] for arg in args] templ = TemplateArguments(*arg_types) rhs = App.make_automation(templ, trigger) type = Automation.template(templ) obj = Pvariable(config[CONF_AUTOMATION_ID], rhs, type=type) for actions in build_actions(config[CONF_THEN], templ, args): yield None add(obj.add_actions(actions)) yield obj
def while_action_to_code(config, action_id, template_arg, args): for conditions in build_conditions(config[CONF_CONDITION], template_arg, args): yield None rhs = WhileAction.new(template_arg, conditions) type = WhileAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for actions in build_actions(config[CONF_THEN], template_arg, args): yield None add(action.add_then(actions)) yield action
def to_code(config): rhs = App.make_sht3xd_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) sht3xd = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(sht3xd.Pget_temperature_sensor(), config[CONF_TEMPERATURE]) sensor.setup_sensor(sht3xd.Pget_humidity_sensor(), config[CONF_HUMIDITY]) setup_component(sht3xd, config)
def stepper_report_position_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_report_position_action(template_arg) type = ReportPositionAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_POSITION], args, int32): yield None add(action.set_position(template_)) yield action
def sensor_template_publish_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_sensor_publish_action(template_arg) type = SensorPublishAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_STATE], args, float_): yield None add(action.set_state(template_)) yield action
def servo_write_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = ServoWriteAction.new(template_arg, var) type = ServoWriteAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_LEVEL], args, float_): yield None add(action.set_value(template_)) yield action
def stepper_set_target_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_set_target_action(template_arg) type = SetTargetAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_TARGET], args, int32): yield None add(action.set_target(template_)) yield action
def to_code(config): rhs = App.make_sntp_component() sntp = Pvariable(config[CONF_ID], rhs) if CONF_SERVERS in config: servers = config[CONF_SERVERS] servers += [''] * (3 - len(servers)) add(sntp.set_servers(*servers)) time_.setup_time(sntp, config) setup_component(sntp, config)
def to_code(config): rhs = App.init_uart(config[CONF_BAUD_RATE]) var = Pvariable(config[CONF_ID], rhs) if CONF_TX_PIN in config: add(var.set_tx_pin(config[CONF_TX_PIN])) if CONF_RX_PIN in config: add(var.set_rx_pin(config[CONF_RX_PIN])) setup_component(var, config)
def output_set_level_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_set_level_action(template_arg) type = SetLevelAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_LEVEL], args, float_): yield None add(action.set_level(template_)) yield action
def to_code(config): rhs = App.make_mpu6050_sensor(config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) mpu = Pvariable(config[CONF_ID], rhs) if CONF_ACCEL_X in config: conf = config[CONF_ACCEL_X] rhs = mpu.Pmake_accel_x_sensor(conf[CONF_NAME]) sensor.register_sensor(rhs, conf) if CONF_ACCEL_Y in config: conf = config[CONF_ACCEL_Y] rhs = mpu.Pmake_accel_y_sensor(conf[CONF_NAME]) sensor.register_sensor(rhs, conf) if CONF_ACCEL_Z in config: conf = config[CONF_ACCEL_Z] rhs = mpu.Pmake_accel_z_sensor(conf[CONF_NAME]) sensor.register_sensor(rhs, conf) if CONF_GYRO_X in config: conf = config[CONF_GYRO_X] rhs = mpu.Pmake_gyro_x_sensor(conf[CONF_NAME]) sensor.register_sensor(rhs, conf) if CONF_GYRO_Y in config: conf = config[CONF_GYRO_Y] rhs = mpu.Pmake_gyro_y_sensor(conf[CONF_NAME]) sensor.register_sensor(rhs, conf) if CONF_GYRO_Z in config: conf = config[CONF_GYRO_Z] rhs = mpu.Pmake_gyro_z_sensor(conf[CONF_NAME]) sensor.register_sensor(rhs, conf) if CONF_TEMPERATURE in config: conf = config[CONF_TEMPERATURE] rhs = mpu.Pmake_temperature_sensor(conf[CONF_NAME]) sensor.register_sensor(rhs, conf) setup_component(mpu, config)
def to_code(config): pin = config[CONF_PIN] if pin == 'VCC': pin = 0 rhs = App.make_adc_sensor(config[CONF_NAME], pin, config.get(CONF_UPDATE_INTERVAL)) adc = Pvariable(config[CONF_ID], rhs) if CONF_ATTENUATION in config: add(adc.set_attenuation(ATTENUATION_MODES[config[CONF_ATTENUATION]])) sensor.setup_sensor(adc, config) setup_component(adc, config)
def to_code(config): frequency = config.get(CONF_FREQUENCY) if frequency is None and CONF_BIT_DEPTH in config: frequency = 1000 rhs = App.make_ledc_output(config[CONF_PIN], frequency, config.get(CONF_BIT_DEPTH)) ledc = Pvariable(config[CONF_ID], rhs) if CONF_CHANNEL in config: add(ledc.set_channel(config[CONF_CHANNEL])) output.setup_output_platform(ledc, config) setup_component(ledc, config)
def to_code(config): uuid = config[CONF_UUID].hex uuid_arr = [RawExpression('0x{}'.format(uuid[i:i + 2])) for i in range(0, len(uuid), 2)] rhs = App.make_esp32_ble_beacon(uuid_arr) ble = Pvariable(config[CONF_ID], rhs) if CONF_MAJOR in config: add(ble.set_major(config[CONF_MAJOR])) if CONF_MINOR in config: add(ble.set_minor(config[CONF_MINOR])) setup_component(ble, config)
def to_code(config): for pin in gpio_output_pin_expression(config[CONF_PIN]): yield rhs = App.make_esp8266_pwm_output(pin) gpio = Pvariable(config[CONF_ID], rhs) if CONF_FREQUENCY in config: add(gpio.set_frequency(config[CONF_FREQUENCY])) output.setup_output_platform(gpio, config) setup_component(gpio, config)
def to_code(config): for out in get_variable(config[CONF_OUTPUT]): yield rhs = App.register_component(Servo.new(out)) servo = Pvariable(config[CONF_ID], rhs) add(servo.set_min_level(config[CONF_MIN_LEVEL])) add(servo.set_idle_level(config[CONF_IDLE_LEVEL])) add(servo.set_max_level(config[CONF_MAX_LEVEL])) setup_component(servo, config)
def display_page_show_to_code(config, action_id, template_arg, args): type = DisplayPageShowAction.template(template_arg) action = Pvariable(action_id, type.new(), type=type) if isinstance(config[CONF_ID], core.Lambda): for template_ in templatable(config[CONF_ID], args, DisplayPagePtr): yield None add(action.set_page(template_)) else: for var in get_variable(config[CONF_ID]): yield None add(action.set_page(var)) yield action
def to_code(config): rhs = App.make_bmp085_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_PRESSURE][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) bmp = Pvariable(config[CONF_ID], rhs) if CONF_ADDRESS in config: add(bmp.set_address(HexIntLiteral(config[CONF_ADDRESS]))) sensor.setup_sensor(bmp.Pget_temperature_sensor(), config[CONF_TEMPERATURE]) sensor.setup_sensor(bmp.Pget_pressure_sensor(), config[CONF_PRESSURE]) setup_component(bmp, config)
def light_turn_off_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_turn_off_action(template_arg) type = TurnOffAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) if CONF_TRANSITION_LENGTH in config: for template_ in templatable(config[CONF_TRANSITION_LENGTH], args, uint32): yield None add(action.set_transition_length(template_)) yield action
def to_code(config): for pin in gpio_output_pin_expression(config[CONF_PIN]): yield rhs = App.make_remote_transmitter_component(pin) transmitter = Pvariable(config[CONF_ID], rhs) if CONF_CARRIER_DUTY_PERCENT in config: add( transmitter.set_carrier_duty_percent( config[CONF_CARRIER_DUTY_PERCENT])) setup_component(transmitter, config)