Beispiel #1
0
def to_code(config):
    rhs = App.make_htu21d_sensor(config[CONF_TEMPERATURE][CONF_NAME],
                                 config[CONF_HUMIDITY][CONF_NAME],
                                 config.get(CONF_UPDATE_INTERVAL))
    htu21d = Pvariable(config[CONF_ID], rhs)

    sensor.setup_sensor(htu21d.Pget_temperature_sensor(),
                        config[CONF_TEMPERATURE])
    sensor.setup_sensor(htu21d.Pget_humidity_sensor(), config[CONF_HUMIDITY])
    setup_component(htu21d, config)
Beispiel #2
0
def to_code(config):
    for spi_ in get_variable(config[CONF_SPI_ID]):
        yield
    for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
        yield
    rhs = App.make_max6675_sensor(config[CONF_NAME], spi_, cs,
                                  config.get(CONF_UPDATE_INTERVAL))
    max6675 = Pvariable(config[CONF_ID], rhs)
    sensor.setup_sensor(max6675, config)
    setup_component(max6675, config)
def to_code(config):
    for time_ in get_variable(config[CONF_TIME_ID]):
        yield
    for sens in get_variable(config[CONF_POWER_ID]):
        yield
    rhs = App.make_total_daily_energy_sensor(config[CONF_NAME], time_, sens)
    total_energy = Pvariable(config[CONF_ID], rhs)

    sensor.setup_sensor(total_energy, config)
    setup_component(total_energy, config)
Beispiel #4
0
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)
Beispiel #5
0
def to_code(config):
    rhs = App.make_template_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL))
    template = Pvariable(config[CONF_ID], rhs)

    sensor.setup_sensor(template, config)
    setup_component(template, config)

    if CONF_LAMBDA in config:
        for template_ in process_lambda(config[CONF_LAMBDA], [],
                                        return_type=optional.template(float_)):
            yield
        add(template.set_template(template_))
Beispiel #6
0
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)
Beispiel #7
0
def to_code(config):
    rhs = App.make_ms5611_sensor(config[CONF_TEMPERATURE][CONF_NAME],
                                 config[CONF_PRESSURE][CONF_NAME],
                                 config.get(CONF_UPDATE_INTERVAL))
    ms5611 = Pvariable(config[CONF_ID], rhs)

    if CONF_ADDRESS in config:
        add(ms5611.set_address(config[CONF_ADDRESS]))

    sensor.setup_sensor(ms5611.Pget_temperature_sensor(),
                        config[CONF_TEMPERATURE])
    sensor.setup_sensor(ms5611.Pget_pressure_sensor(), config[CONF_PRESSURE])
    setup_component(ms5611, config)
Beispiel #8
0
def to_code(config):
    rhs = App.make_tsl2561_sensor(config[CONF_NAME], config[CONF_ADDRESS],
                                  config.get(CONF_UPDATE_INTERVAL))
    tsl2561 = Pvariable(config[CONF_ID], rhs)

    if CONF_INTEGRATION_TIME in config:
        add(tsl2561.set_integration_time(INTEGRATION_TIMES[config[CONF_INTEGRATION_TIME]]))
    if CONF_GAIN in config:
        add(tsl2561.set_gain(GAINS[config[CONF_GAIN]]))
    if CONF_IS_CS_PACKAGE in config:
        add(tsl2561.set_is_cs_package(config[CONF_IS_CS_PACKAGE]))

    sensor.setup_sensor(tsl2561, config)
    setup_component(tsl2561, config)
Beispiel #9
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)
Beispiel #10
0
def to_code(config):
    rhs = App.make_bme680_sensor(config[CONF_TEMPERATURE][CONF_NAME],
                                 config[CONF_PRESSURE][CONF_NAME],
                                 config[CONF_HUMIDITY][CONF_NAME],
                                 config[CONF_GAS_RESISTANCE][CONF_NAME],
                                 config[CONF_ADDRESS],
                                 config.get(CONF_UPDATE_INTERVAL))
    bme680 = Pvariable(config[CONF_ID], rhs)
    if CONF_OVERSAMPLING in config[CONF_TEMPERATURE]:
        constant = OVERSAMPLING_OPTIONS[config[CONF_TEMPERATURE][CONF_OVERSAMPLING]]
        add(bme680.set_temperature_oversampling(constant))
    if CONF_OVERSAMPLING in config[CONF_PRESSURE]:
        constant = OVERSAMPLING_OPTIONS[config[CONF_PRESSURE][CONF_OVERSAMPLING]]
        add(bme680.set_pressure_oversampling(constant))
    if CONF_OVERSAMPLING in config[CONF_HUMIDITY]:
        constant = OVERSAMPLING_OPTIONS[config[CONF_HUMIDITY][CONF_OVERSAMPLING]]
        add(bme680.set_humidity_oversampling(constant))
    if CONF_IIR_FILTER in config:
        constant = IIR_FILTER_OPTIONS[config[CONF_IIR_FILTER]]
        add(bme680.set_iir_filter(constant))
    if CONF_HEATER in config:
        conf = config[CONF_HEATER]
        if not conf:
            add(bme680.set_heater(0, 0))
        else:
            add(bme680.set_heater(conf[CONF_TEMPERATURE], conf[CONF_DURATION]))

    sensor.setup_sensor(bme680.Pget_temperature_sensor(), config[CONF_TEMPERATURE])
    sensor.setup_sensor(bme680.Pget_pressure_sensor(), config[CONF_PRESSURE])
    sensor.setup_sensor(bme680.Pget_humidity_sensor(), config[CONF_HUMIDITY])
    sensor.setup_sensor(bme680.Pget_gas_resistance_sensor(), config[CONF_GAS_RESISTANCE])
    setup_component(bme680, config)
Beispiel #11
0
def to_code(config):
    for dout_pin in gpio_input_pin_expression(config[CONF_DOUT_PIN]):
        yield
    for sck_pin in gpio_input_pin_expression(config[CONF_CLK_PIN]):
        yield

    rhs = App.make_hx711_sensor(config[CONF_NAME], dout_pin, sck_pin,
                                config.get(CONF_UPDATE_INTERVAL))
    hx711 = Pvariable(config[CONF_ID], rhs)

    if CONF_GAIN in config:
        add(hx711.set_gain(GAINS[config[CONF_GAIN]]))

    sensor.setup_sensor(hx711, config)
    setup_component(hx711, config)
Beispiel #12
0
def to_code(config):
    for pin in gpio_input_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_pulse_counter_sensor(config[CONF_NAME], pin,
                                        config.get(CONF_UPDATE_INTERVAL))
    pcnt = Pvariable(config[CONF_ID], rhs)

    if CONF_COUNT_MODE in config:
        rising_edge = COUNT_MODES[config[CONF_COUNT_MODE][CONF_RISING_EDGE]]
        falling_edge = COUNT_MODES[config[CONF_COUNT_MODE][CONF_FALLING_EDGE]]
        add(pcnt.set_edge_mode(rising_edge, falling_edge))
    if CONF_INTERNAL_FILTER in config:
        add(pcnt.set_filter_us(config[CONF_INTERNAL_FILTER]))

    sensor.setup_sensor(pcnt, config)
    setup_component(pcnt, config)
Beispiel #13
0
def to_code(config):
    for trigger in gpio_output_pin_expression(config[CONF_TRIGGER_PIN]):
        yield
    for echo in gpio_input_pin_expression(config[CONF_ECHO_PIN]):
        yield
    rhs = App.make_ultrasonic_sensor(config[CONF_NAME], trigger, echo,
                                     config.get(CONF_UPDATE_INTERVAL))
    ultrasonic = Pvariable(config[CONF_ID], rhs)

    if CONF_TIMEOUT_TIME in config:
        add(ultrasonic.set_timeout_us(config[CONF_TIMEOUT_TIME]))
    elif CONF_TIMEOUT_METER in config:
        add(ultrasonic.set_timeout_m(config[CONF_TIMEOUT_METER]))

    sensor.setup_sensor(ultrasonic, config)
    setup_component(ultrasonic, config)
Beispiel #14
0
def to_code(config):
    for pin in gpio_output_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_dht_sensor(config[CONF_TEMPERATURE][CONF_NAME],
                              config[CONF_HUMIDITY][CONF_NAME], pin,
                              config.get(CONF_UPDATE_INTERVAL))
    dht = Pvariable(config[CONF_ID], rhs)

    if CONF_MODEL in config:
        constant = DHT_MODELS[config[CONF_MODEL]]
        add(dht.set_dht_model(constant))

    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):
    for pin_a in gpio_input_pin_expression(config[CONF_PIN_A]):
        yield
    for pin_b in gpio_input_pin_expression(config[CONF_PIN_B]):
        yield
    rhs = App.make_rotary_encoder_sensor(config[CONF_NAME], pin_a, pin_b)
    encoder = Pvariable(config[CONF_ID], rhs)

    if CONF_PIN_RESET in config:
        for pin_i in gpio_input_pin_expression(config[CONF_PIN_RESET]):
            yield
        add(encoder.set_reset_pin(pin_i))
    if CONF_RESOLUTION in config:
        resolution = RESOLUTIONS[config[CONF_RESOLUTION]]
        add(encoder.set_resolution(resolution))

    sensor.setup_sensor(encoder, config)
    setup_component(encoder, config)
Beispiel #16
0
def to_code(config):
    rhs = App.make_bmp280_sensor(config[CONF_TEMPERATURE][CONF_NAME],
                                 config[CONF_PRESSURE][CONF_NAME],
                                 config[CONF_ADDRESS],
                                 config.get(CONF_UPDATE_INTERVAL))
    bmp280 = Pvariable(config[CONF_ID], rhs)
    if CONF_OVERSAMPLING in config[CONF_TEMPERATURE]:
        constant = OVERSAMPLING_OPTIONS[config[CONF_TEMPERATURE]
                                        [CONF_OVERSAMPLING]]
        add(bmp280.set_temperature_oversampling(constant))
    if CONF_OVERSAMPLING in config[CONF_PRESSURE]:
        constant = OVERSAMPLING_OPTIONS[config[CONF_PRESSURE]
                                        [CONF_OVERSAMPLING]]
        add(bmp280.set_pressure_oversampling(constant))
    if CONF_IIR_FILTER in config:
        constant = IIR_FILTER_OPTIONS[config[CONF_IIR_FILTER]]
        add(bmp280.set_iir_filter(constant))

    sensor.setup_sensor(bmp280.Pget_temperature_sensor(),
                        config[CONF_TEMPERATURE])
    sensor.setup_sensor(bmp280.Pget_pressure_sensor(), config[CONF_PRESSURE])
    setup_component(bmp280, config)
def to_code(config):
    rhs = App.make_esp32_hall_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL))
    hall = Pvariable(config[CONF_ID], rhs)
    sensor.setup_sensor(hall, config)
    setup_component(hall, config)
Beispiel #18
0
def to_code(config):
    rhs = App.make_homeassistant_sensor(config[CONF_NAME], config[CONF_ENTITY_ID])
    subs = Pvariable(config[CONF_ID], rhs)
    sensor.setup_sensor(subs, config)
Beispiel #19
0
def to_code(config):
    rhs = App.make_uptime_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL))
    uptime = Pvariable(config[CONF_ID], rhs)

    sensor.setup_sensor(uptime, config)
    setup_component(uptime, config)