Ejemplo n.º 1
0
def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config):
    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]))

    for conf in config.get(CONF_ON_PRESS, []):
        rhs = binary_sensor_var.make_press_trigger()
        trigger = Pvariable(PressTrigger, 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(ReleaseTrigger, 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(ClickTrigger, 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(DoubleClickTrigger, conf[CONF_TRIGGER_ID], rhs)
        automation.build_automation(trigger, NoArg, conf)

    setup_mqtt_component(mqtt_var, config)
Ejemplo n.º 2
0
def setup_binary_sensor_core_(binary_sensor_var, mqtt_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:
        filters = None
        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)

    setup_mqtt_component(mqtt_var, config)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
def build_automation(trigger, arg_type, config):
    rhs = App.make_automation(trigger)
    obj = Pvariable(Automation.template(arg_type), config[CONF_AUTOMATION_ID],
                    rhs)
    if CONF_IF in config:
        add(obj.add_conditions(build_conditions(config[CONF_IF], arg_type)))
    add(obj.add_actions(build_actions(config[CONF_THEN], arg_type)))
Ejemplo n.º 5
0
def to_code(config):
    for conf in config:
        address = HexIntLiteral(conf[CONF_ADDRESS])
        rhs = App.make_ads1115_component(address)
        ads1115 = Pvariable(ADS1115_COMPONENT_CLASS, conf[CONF_ID], rhs)
        if CONF_RATE in conf:
            add(ads1115.set_rate(RawExpression(RATES[conf[CONF_RATE]])))
Ejemplo n.º 6
0
def setup_sensor_core_(sensor_var, mqtt_var, config):
    if CONF_UNIT_OF_MEASUREMENT in config:
        add(
            sensor_var.set_unit_of_measurement(
                config[CONF_UNIT_OF_MEASUREMENT]))
    if CONF_ICON in config:
        add(sensor_var.set_icon(config[CONF_ICON]))
    if CONF_ACCURACY_DECIMALS in config:
        add(sensor_var.set_accuracy_decimals(config[CONF_ACCURACY_DECIMALS]))
    if CONF_FILTERS in config:
        add(sensor_var.set_filters(setup_filters(config[CONF_FILTERS])))

    for conf in config.get(CONF_ON_VALUE, []):
        rhs = sensor_var.make_value_trigger()
        trigger = Pvariable(SensorValueTrigger, conf[CONF_TRIGGER_ID], rhs)
        automation.build_automation(trigger, float_, conf)
    for conf in config.get(CONF_ON_RAW_VALUE, []):
        rhs = sensor_var.make_raw_value_trigger()
        trigger = Pvariable(RawSensorValueTrigger, conf[CONF_TRIGGER_ID], rhs)
        automation.build_automation(trigger, float_, conf)
    for conf in config.get(CONF_ON_VALUE_RANGE, []):
        rhs = sensor_var.make_value_range_trigger()
        trigger = Pvariable(ValueRangeTrigger, conf[CONF_TRIGGER_ID], rhs)
        if CONF_ABOVE in conf:
            trigger.set_min(templatable(conf[CONF_ABOVE], float_, float_))
        if CONF_BELOW in conf:
            trigger.set_max(templatable(conf[CONF_BELOW], float_, float_))
        automation.build_automation(trigger, float_, conf)

    if CONF_EXPIRE_AFTER in config:
        if config[CONF_EXPIRE_AFTER] is None:
            add(mqtt_var.disable_expire_after())
        else:
            add(mqtt_var.set_expire_after(config[CONF_EXPIRE_AFTER]))
    setup_mqtt_component(mqtt_var, config)
Ejemplo n.º 7
0
def to_code(config):
    rhs = App.init_web_server(config.get(CONF_PORT))
    web_server = Pvariable('WebServer', 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]))
Ejemplo n.º 8
0
def to_code(config):
    rhs = App.init_i2c(config[CONF_SDA], config[CONF_SCL],
                       config.get(CONF_SCAN))
    i2c = Pvariable(I2CComponent, config[CONF_ID], rhs)
    if CONF_FREQUENCY in config:
        add(i2c.set_frequency(config[CONF_FREQUENCY]))
    if CONF_RECEIVE_TIMEOUT in config:
        add(i2c.set_receive_timeout(config[CONF_RECEIVE_TIMEOUT]))
Ejemplo n.º 9
0
def register_sensor(var, config):
    sensor_var = Pvariable(Sensor, config[CONF_ID], var, has_side_effects=True)
    rhs = App.register_sensor(sensor_var)
    mqtt_var = Pvariable(MQTTSensorComponent,
                         config[CONF_MQTT_ID],
                         rhs,
                         has_side_effects=True)
    setup_sensor_core_(sensor_var, mqtt_var, config)
Ejemplo n.º 10
0
def to_code(config):
    rhs = App.make_sntp_component()
    sntp = Pvariable(config[CONF_ID], rhs)
    if CONF_SERVERS in config:
        add(sntp.set_servers(*config[CONF_SERVERS]))

    time_.setup_time(sntp, config)
    setup_component(sntp, config)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
def to_code(config):
    for conf in config:
        rhs = App.make_power_supply(gpio_output_pin_expression(conf[CONF_PIN]))
        psu = Pvariable(PowerSupplyComponent, conf[CONF_ID], rhs)
        if CONF_ENABLE_TIME in conf:
            add(psu.set_enable_time(conf[CONF_ENABLE_TIME]))
        if CONF_KEEP_ON_TIME in conf:
            add(psu.set_keep_on_time(conf[CONF_KEEP_ON_TIME]))
Ejemplo n.º 13
0
def to_code(config):
    rhs = App.init_ota()
    ota = Pvariable(OTAComponent, config[CONF_ID], rhs)
    if CONF_PASSWORD in config:
        hash_ = hashlib.md5(config[CONF_PASSWORD].encode()).hexdigest()
        add(ota.set_auth_password_hash(hash_))
    if config[CONF_SAFE_MODE]:
        add(ota.start_safe_mode())
Ejemplo n.º 14
0
def setup_text_sensor(text_sensor_obj, mqtt_obj, config):
    sensor_var = Pvariable(config[CONF_ID],
                           text_sensor_obj,
                           has_side_effects=False)
    mqtt_var = Pvariable(config[CONF_MQTT_ID],
                         mqtt_obj,
                         has_side_effects=False)
    add_job(setup_text_sensor_core_, sensor_var, mqtt_var, config)
Ejemplo n.º 15
0
def setup_binary_sensor(binary_sensor_obj, mqtt_obj, config):
    binary_sensor_var = Pvariable(config[CONF_ID],
                                  binary_sensor_obj,
                                  has_side_effects=False)
    mqtt_var = Pvariable(config[CONF_MQTT_ID],
                         mqtt_obj,
                         has_side_effects=False)
    add_job(setup_binary_sensor_core_, binary_sensor_var, mqtt_var, config)
Ejemplo n.º 16
0
def to_code(config):
    rhs = App.init_log(config.get(CONF_BAUD_RATE))
    log = Pvariable(config[CONF_ID], rhs)
    if CONF_TX_BUFFER_SIZE in config:
        add(log.set_tx_buffer_size(config[CONF_TX_BUFFER_SIZE]))
    if CONF_LEVEL in config:
        add(log.set_global_log_level(LOG_LEVELS[config[CONF_LEVEL]]))
    for tag, level in config.get(CONF_LOGS, {}).iteritems():
        add(log.set_log_level(tag, LOG_LEVELS[level]))
Ejemplo n.º 17
0
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())
Ejemplo n.º 18
0
def delay_action_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    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, arg_type, uint32):
        yield
    add(action.set_delay(template_))
    yield action
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
def setup_binary_sensor(binary_sensor_obj, mqtt_obj, config):
    binary_sensor_var = Pvariable(BinarySensor,
                                  config[CONF_ID],
                                  binary_sensor_obj,
                                  has_side_effects=False)
    mqtt_var = Pvariable(MQTTBinarySensorComponent,
                         config[CONF_MQTT_ID],
                         mqtt_obj,
                         has_side_effects=False)
    setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config)
Ejemplo n.º 21
0
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(LEDCOutputComponent, config[CONF_ID], rhs)
    if CONF_CHANNEL in config:
        add(ledc.set_channel(config[CONF_CHANNEL]))
    output.setup_output_platform(ledc, config)
Ejemplo n.º 22
0
def setup_fan(fan_obj, mqtt_obj, config):
    fan_var = Pvariable(FanState,
                        config[CONF_ID],
                        fan_obj,
                        has_side_effects=False)
    mqtt_var = Pvariable(MQTTFanComponent,
                         config[CONF_MQTT_ID],
                         mqtt_obj,
                         has_side_effects=False)
    setup_fan_core_(fan_var, mqtt_var, config)
Ejemplo n.º 23
0
def setup_sensor(sensor_obj, mqtt_obj, config):
    sensor_var = Pvariable(Sensor,
                           config[CONF_ID],
                           sensor_obj,
                           has_side_effects=False)
    mqtt_var = Pvariable(MQTTSensorComponent,
                         config[CONF_MQTT_ID],
                         mqtt_obj,
                         has_side_effects=False)
    setup_sensor_core_(sensor_var, mqtt_var, config)
Ejemplo n.º 24
0
def to_code(config):
    for conf in config:
        rhs = App.make_pca9685_component(conf.get(CONF_FREQUENCY))
        pca9685 = Pvariable(PCA9685_COMPONENT_TYPE, conf[CONF_ID], rhs)
        if CONF_ADDRESS in conf:
            add(pca9685.set_address(HexIntLiteral(conf[CONF_ADDRESS])))
        if CONF_PHASE_BALANCER in conf:
            phase_balancer = RawExpression(u'PCA9685_PhaseBalancer_{}'.format(
                conf[CONF_PHASE_BALANCER]))
            add(pca9685.set_phase_balancer(phase_balancer))
Ejemplo n.º 25
0
def to_code(config):
    rhs = App.make_esp32_touch_component()
    touch = Pvariable(config[CONF_ID], rhs)
    if CONF_SETUP_MODE in config:
        add(touch.set_setup_mode(config[CONF_SETUP_MODE]))
    if CONF_IIR_FILTER in config:
        add(touch.set_iir_filter(config[CONF_IIR_FILTER]))
    if CONF_SLEEP_DURATION in config:
        sleep_duration = int(config[CONF_SLEEP_DURATION].total_microseconds *
                             0.15)
        add(touch.set_sleep_duration(sleep_duration))
    if CONF_MEASUREMENT_DURATION in config:
        measurement_duration = int(
            config[CONF_MEASUREMENT_DURATION].total_microseconds * 0.125)
        add(touch.set_measurement_duration(measurement_duration))
    if CONF_LOW_VOLTAGE_REFERENCE in config:
        value = LOW_VOLTAGE_REFERENCE[config[CONF_LOW_VOLTAGE_REFERENCE]]
        add(touch.set_low_voltage_reference(value))
    if CONF_HIGH_VOLTAGE_REFERENCE in config:
        value = HIGH_VOLTAGE_REFERENCE[config[CONF_HIGH_VOLTAGE_REFERENCE]]
        add(touch.set_high_voltage_reference(value))
    if CONF_VOLTAGE_ATTENUATION in config:
        value = VOLTAGE_ATTENUATION[config[CONF_VOLTAGE_ATTENUATION]]
        add(touch.set_voltage_attenuation(value))

    setup_component(touch, config)
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
def to_code(config):
    for conf in config:
        pin = None
        for pin in gpio_output_pin_expression(conf[CONF_PIN]):
            yield
        rhs = App.make_remote_transmitter_component(pin)
        transmitter = Pvariable(conf[CONF_ID], rhs)
        if CONF_CARRIER_DUTY_PERCENT in conf:
            add(
                transmitter.set_carrier_duty_percent(
                    conf[CONF_CARRIER_DUTY_PERCENT]))
Ejemplo n.º 28
0
def output_set_level_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_set_level_action(template_arg)
    type = SetLevelAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_LEVEL], arg_type, bool_):
        yield None
    add(action.set_level(template_))
    yield action
Ejemplo n.º 29
0
def stepper_set_target_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_set_target_action(template_arg)
    type = SetTargetAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_TARGET], arg_type, int32):
        yield None
    add(action.set_target(template_))
    yield action
Ejemplo n.º 30
0
def stepper_report_position_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_report_position_action(template_arg)
    type = ReportPositionAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_POSITION], arg_type, int32):
        yield None
    add(action.set_target(template_))
    yield action