Ejemplo n.º 1
0
def to_code(config):
    for hub in get_variable(config[CONF_ESP32_BLE_ID]):
        yield
    rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS]))
    dev = Pvariable(config[CONF_ID], rhs)
    if CONF_TEMPERATURE in config:
        conf = config[CONF_TEMPERATURE]
        sensor.register_sensor(dev.Pmake_temperature_sensor(conf[CONF_NAME]),
                               conf)
    if CONF_MOISTURE in config:
        conf = config[CONF_MOISTURE]
        sensor.register_sensor(dev.Pmake_moisture_sensor(conf[CONF_NAME]),
                               conf)
    if CONF_ILLUMINANCE in config:
        conf = config[CONF_ILLUMINANCE]
        sensor.register_sensor(dev.Pmake_illuminance_sensor(conf[CONF_NAME]),
                               conf)
    if CONF_CONDUCTIVITY in config:
        conf = config[CONF_CONDUCTIVITY]
        sensor.register_sensor(dev.Pmake_conductivity_sensor(conf[CONF_NAME]),
                               conf)
    if CONF_BATTERY_LEVEL in config:
        conf = config[CONF_BATTERY_LEVEL]
        sensor.register_sensor(dev.Pmake_battery_level_sensor(conf[CONF_NAME]),
                               conf)
Ejemplo n.º 2
0
def to_code(config):
    for hub in get_variable(config[CONF_ADS1115_ID]):
        yield

    mux = MUX[config[CONF_MULTIPLEXER]]
    gain = GAIN[config[CONF_GAIN]]
    rhs = hub.get_sensor(config[CONF_NAME], mux, gain, config.get(CONF_UPDATE_INTERVAL))
    sensor.register_sensor(rhs, config)
Ejemplo n.º 3
0
def to_code(config):
    for template_ in process_lambda(config[CONF_LAMBDA], [],
                                    return_type=std_vector.template(sensor.SensorPtr)):
        yield

    rhs = CustomSensorConstructor(template_)
    custom = variable(config[CONF_ID], rhs)
    for i, conf in enumerate(config[CONF_SENSORS]):
        rhs = custom.Pget_sensor(i)
        add(rhs.set_name(conf[CONF_NAME]))
        sensor.register_sensor(rhs, conf)
Ejemplo n.º 4
0
def to_code(config):
    for hub in get_variable(config[CONF_DALLAS_ID]):
        yield
    if CONF_ADDRESS in config:
        address = HexIntLiteral(config[CONF_ADDRESS])
        rhs = hub.Pget_sensor_by_address(config[CONF_NAME], address,
                                         config.get(CONF_RESOLUTION))
    else:
        rhs = hub.Pget_sensor_by_index(config[CONF_NAME], config[CONF_INDEX],
                                       config.get(CONF_RESOLUTION))
    sensor.register_sensor(rhs, config)
Ejemplo n.º 5
0
def to_code(config):
    rhs = App.make_ina3221(config[CONF_ADDRESS],
                           config.get(CONF_UPDATE_INTERVAL))
    ina = Pvariable(config[CONF_ID], rhs)
    for i, channel in enumerate(
        [CONF_CHANNEL_1, CONF_CHANNEL_2, CONF_CHANNEL_3]):
        if channel not in config:
            continue
        conf = config[channel]
        if CONF_SHUNT_RESISTANCE in conf:
            add(ina.set_shunt_resistance(i, conf[CONF_SHUNT_RESISTANCE]))
        if CONF_BUS_VOLTAGE in conf:
            c = conf[CONF_BUS_VOLTAGE]
            sensor.register_sensor(
                ina.Pmake_bus_voltage_sensor(i, c[CONF_NAME]), c)
        if CONF_SHUNT_VOLTAGE in conf:
            c = conf[CONF_SHUNT_VOLTAGE]
            sensor.register_sensor(
                ina.Pmake_shunt_voltage_sensor(i, c[CONF_NAME]), c)
        if CONF_CURRENT in conf:
            c = conf[CONF_CURRENT]
            sensor.register_sensor(ina.Pmake_current_sensor(i, c[CONF_NAME]),
                                   c)
        if CONF_POWER in conf:
            c = conf[CONF_POWER]
            sensor.register_sensor(ina.Pmake_power_sensor(i, c[CONF_NAME]), c)

    setup_component(ina, config)
Ejemplo n.º 6
0
def to_code(config):
    for uart_ in get_variable(config[CONF_UART_ID]):
        yield
    rhs = App.make_mhz19_sensor(uart_, config[CONF_CO2][CONF_NAME],
                                config.get(CONF_UPDATE_INTERVAL))
    mhz19 = Pvariable(config[CONF_ID], rhs)
    sensor.setup_sensor(mhz19.Pget_co2_sensor(), config[CONF_CO2])

    if CONF_TEMPERATURE in config:
        sensor.register_sensor(
            mhz19.Pmake_temperature_sensor(
                config[CONF_TEMPERATURE][CONF_NAME]), config[CONF_TEMPERATURE])

    setup_component(mhz19, config)
Ejemplo n.º 7
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)

    yield setup_input(config, CONF_TIME_ID, var.set_time)

    # inputs
    yield setup_input(config, CONF_TOTAL, var.set_total)

    if CONF_TIME_OFFSET in config:
        cg.add(var.set_time_offset(config[CONF_TIME_OFFSET]))
    if CONF_TIME_OFFSET_SERVICE in config:
        cg.add(var.set_time_offset_service(config[CONF_TIME_OFFSET_SERVICE]))

    # exposed sensors
    for conf in config.get(CONF_TARIFFS, []):
        sens = cg.new_Pvariable(conf[CONF_ID])
        yield sensor.register_sensor(sens, conf)
        for tm in conf.get(CONF_TIME, []):
            parts = tm.split("-")
            t = [time_period(parts[0]), time_period(parts[1])]
            cg.add(sens.add_time(t[0].total_minutes, t[1].total_minutes))
        cg.add(var.add_tariff(sens))
        if CONF_SERVICE in conf:
            cg.add(sens.set_service(conf[CONF_SERVICE]))

    for conf in config.get(CONF_ON_TARIFF, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        yield automation.build_automation(trigger, [(sensor.SensorPtr, "x")], conf)

    for conf in config.get(CONF_ON_BEFORE_TARIFF, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        yield automation.build_automation(trigger, [], conf)
Ejemplo n.º 8
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)
    yield i2c.register_i2c_device(var, config)

    cg.add(var.set_resolution(config[CONF_RESOLUTION]))
Ejemplo n.º 9
0
def to_code(config):
    paren = yield cg.get_variable(config[CONF_HUB_ID])
    var = cg.new_Pvariable(config[CONF_ID])

    yield sensor.register_sensor(var, config)

    cg.add(paren.register_sensor(var))
Ejemplo n.º 10
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield esp32_ble_tracker.register_ble_device(var, config)
    yield sensor.register_sensor(var, config)

    cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
Ejemplo n.º 11
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    cg.add(var.set_signal_rate_limit(config[CONF_SIGNAL_RATE_LIMIT]))
    cg.add(var.set_long_range(config[CONF_LONG_RANGE]))
    yield sensor.register_sensor(var, config)
    yield i2c.register_i2c_device(var, config)
Ejemplo n.º 12
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    pin = yield cg.gpio_pin_expression(config[CONF_PIN])
    cg.add(var.set_pin(pin))
Ejemplo n.º 13
0
def to_code(config):
    parent = yield cg.get_variable(config[CONF_CLIMATE_ID])
    var = cg.new_Pvariable(config[CONF_ID])
    yield sensor.register_sensor(var, config)
    yield cg.register_component(var, config)

    cg.add(var.set_parent(parent))
    cg.add(var.set_type(config[CONF_TYPE]))
Ejemplo n.º 14
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)
    yield i2c.register_i2c_device(var, config)

    cg.add(var.set_resolution(config[CONF_RESOLUTION]))
    cg.add(var.set_measurement_duration(config[CONF_MEASUREMENT_DURATION]))
Ejemplo n.º 15
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield spi.register_spi_device(var, config)
    yield sensor.register_sensor(var, config)
    if CONF_REFERENCE_TEMPERATURE in config:
        tc_ref = yield sensor.new_sensor(config[CONF_REFERENCE_TEMPERATURE])
        cg.add(var.set_reference_sensor(tc_ref))
Ejemplo n.º 16
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    sens = yield cg.get_variable(config[CONF_SENSOR])
    cg.add(var.set_source(sens))
    cg.add(var.set_sample_duration(config[CONF_SAMPLE_DURATION]))
Ejemplo n.º 17
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    cg.add(var.set_type(config[CONF_TYPE]))
    paren = yield cg.get_variable(config[CONF_SUN_ID])
    cg.add(var.set_parent(paren))
Ejemplo n.º 18
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield i2c.register_i2c_device(var, config)
    yield sensor.register_sensor(var, config)

    update_period = config[CONF_UPDATE_INTERVAL].total_seconds
    cg.add(var.set_config(determine_config_register(update_period)))
Ejemplo n.º 19
0
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(
            var.set_service_uuid32(
                esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID])))
    elif len(config[CONF_SERVICE_UUID]) == len(
            esp32_ble_tracker.bt_uuid128_format):
        uuid128 = esp32_ble_tracker.as_hex_array(config[CONF_SERVICE_UUID])
        cg.add(var.set_service_uuid128(uuid128))

    if len(config[CONF_CHARACTERISTIC_UUID]) == len(
            esp32_ble_tracker.bt_uuid16_format):
        cg.add(
            var.set_char_uuid16(
                esp32_ble_tracker.as_hex(config[CONF_CHARACTERISTIC_UUID])))
    elif len(config[CONF_CHARACTERISTIC_UUID]) == len(
            esp32_ble_tracker.bt_uuid32_format):
        cg.add(
            var.set_char_uuid32(
                esp32_ble_tracker.as_hex(config[CONF_CHARACTERISTIC_UUID])))
    elif len(config[CONF_CHARACTERISTIC_UUID]) == len(
            esp32_ble_tracker.bt_uuid128_format):
        uuid128 = esp32_ble_tracker.as_hex_array(
            config[CONF_CHARACTERISTIC_UUID])
        cg.add(var.set_char_uuid128(uuid128))

    if CONF_DESCRIPTOR_UUID in config:
        if len(config[CONF_DESCRIPTOR_UUID]) == len(
                esp32_ble_tracker.bt_uuid16_format):
            cg.add(
                var.set_descr_uuid16(
                    esp32_ble_tracker.as_hex(config[CONF_DESCRIPTOR_UUID])))
        elif len(config[CONF_DESCRIPTOR_UUID]) == len(
                esp32_ble_tracker.bt_uuid32_format):
            cg.add(
                var.set_descr_uuid32(
                    esp32_ble_tracker.as_hex(config[CONF_DESCRIPTOR_UUID])))
        elif len(config[CONF_DESCRIPTOR_UUID]) == len(
                esp32_ble_tracker.bt_uuid128_format):
            uuid128 = esp32_ble_tracker.as_hex_array(
                config[CONF_DESCRIPTOR_UUID])
            cg.add(var.set_descr_uuid128(uuid128))

    yield cg.register_component(var, config)
    yield ble_client.register_ble_node(var, config)
    cg.add(var.set_enable_notify(config[CONF_NOTIFY]))
    yield sensor.register_sensor(var, config)
    for conf in config.get(CONF_ON_NOTIFY, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        yield ble_client.register_ble_node(trigger, config)
        yield automation.build_automation(trigger, [(float, "x")], conf)
Ejemplo n.º 20
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield i2c.register_i2c_device(var, config)
    yield sensor.register_sensor(var, config)

    cg.add(var.set_integration_time(config[CONF_INTEGRATION_TIME]))
    cg.add(var.set_gain(config[CONF_GAIN]))
    cg.add(var.set_is_cs_package(config[CONF_IS_CS_PACKAGE]))
Ejemplo n.º 21
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield spi.register_spi_device(var, config)
    yield sensor.register_sensor(var, config)
    cg.add(var.set_reference_resistance(config[CONF_REFERENCE_RESISTANCE]))
    cg.add(var.set_nominal_resistance(config[CONF_RTD_NOMINAL_RESISTANCE]))
    cg.add(var.set_filter(config[CONF_MAINS_FILTER]))
    cg.add(var.set_num_rtd_wires(config[CONF_RTD_WIRES]))
Ejemplo n.º 22
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    if CONF_LAMBDA in config:
        template_ = yield cg.process_lambda(
            config[CONF_LAMBDA], [], return_type=cg.optional.template(float))
        cg.add(var.set_template(template_))
Ejemplo n.º 23
0
def to_code(config):
    hub = yield cg.get_variable(config[CONF_DALLAS_ID])
    if CONF_ADDRESS in config:
        address = config[CONF_ADDRESS]
        rhs = hub.Pget_sensor_by_address(address, config.get(CONF_RESOLUTION))
    else:
        rhs = hub.Pget_sensor_by_index(config[CONF_INDEX], config.get(CONF_RESOLUTION))
    var = cg.Pvariable(config[CONF_ID], rhs)
    yield sensor.register_sensor(var, config)
Ejemplo n.º 24
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    paren = yield cg.get_variable(config[CONF_TUYA_ID])
    cg.add(var.set_tuya_parent(paren))

    cg.add(var.set_sensor_id(config[CONF_SENSOR_DATAPOINT]))
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    parent = yield cg.get_variable(config[CONF_MQTT_PARENT_ID])
    cg.add(var.set_parent(parent))
    cg.add(var.set_topic(config[CONF_TOPIC]))
    cg.add(var.set_qos(config[CONF_QOS]))
Ejemplo n.º 26
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])

    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    sens = yield cg.get_variable(config[CONF_POWER_ID])
    cg.add(var.set_parent(sens))
    time_ = yield cg.get_variable(config[CONF_TIME_ID])
    cg.add(var.set_time(time_))
Ejemplo n.º 27
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    dout_pin = yield cg.gpio_pin_expression(config[CONF_DOUT_PIN])
    cg.add(var.set_dout_pin(dout_pin))
    sck_pin = yield cg.gpio_pin_expression(config[CONF_CLK_PIN])
    cg.add(var.set_sck_pin(sck_pin))
    cg.add(var.set_gain(config[CONF_GAIN]))
Ejemplo n.º 28
0
def to_code(config):
    paren = yield cg.get_variable(config[CONF_ADS1115_ID])
    var = cg.new_Pvariable(config[CONF_ID], paren)
    yield sensor.register_sensor(var, config)
    yield cg.register_component(var, config)

    cg.add(var.set_multiplexer(config[CONF_MULTIPLEXER]))
    cg.add(var.set_gain(config[CONF_GAIN]))

    cg.add(paren.register_sensor(var))
Ejemplo n.º 29
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    sens = yield cg.get_variable(config[CONF_SENSOR])
    cg.add(var.set_sensor(sens))
    cg.add(var.set_configuration(config[CONF_CONFIGURATION]))
    cg.add(var.set_resistor(config[CONF_RESISTOR]))
    cg.add(var.set_reference_voltage(config[CONF_REFERENCE_VOLTAGE]))
Ejemplo n.º 30
0
def to_code(config):
    template_ = yield cg.process_lambda(config[CONF_LAMBDA], [],
                                        return_type=cg.std_vector.template(
                                            sensor.SensorPtr))

    rhs = CustomSensorConstructor(template_)
    var = cg.variable(config[CONF_ID], rhs)
    for i, conf in enumerate(config[CONF_SENSORS]):
        sens = cg.Pvariable(conf[CONF_ID], var.get_sensor(i))
        yield sensor.register_sensor(sens, conf)