Exemplo n.º 1
0
def to_code(config):
    pin_a = gpio_input_pin_expression(config[CONF_PIN_A])
    pin_b = gpio_input_pin_expression(config[CONF_PIN_B])
    rhs = App.make_rotary_encoder_sensor(config[CONF_NAME], pin_a, pin_b)
    make = variable(MakeRotaryEncoderSensor, config[CONF_MAKE_ID], rhs)
    encoder = make.Protary_encoder
    if CONF_PIN_RESET in config:
        pin_i = gpio_input_pin_expression(config[CONF_PIN_RESET])
        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, make.Pmqtt, config)
Exemplo n.º 2
0
def to_code(config):
    for conf in config:
        clk = None
        for clk in gpio_output_pin_expression(conf[CONF_CLK_PIN]):
            yield
        rhs = App.init_spi(clk)
        spi = Pvariable(conf[CONF_ID], rhs)
        if CONF_MISO_PIN in conf:
            for miso in gpio_input_pin_expression(conf[CONF_MISO_PIN]):
                yield
            add(spi.set_miso(miso))
        if CONF_MOSI_PIN in conf:
            for mosi in gpio_input_pin_expression(conf[CONF_MOSI_PIN]):
                yield
            add(spi.set_mosi(mosi))
Exemplo n.º 3
0
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_CYCLES in config:
        add(deep_sleep.set_run_cycles(config[CONF_RUN_CYCLES]))
    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)
Exemplo n.º 4
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
    for dc in gpio_output_pin_expression(config[CONF_DC_PIN]):
        yield

    model_type, model = MODELS[config[CONF_MODEL]]
    if model_type == 'a':
        rhs = App.make_waveshare_epaper_type_a(spi, cs, dc, model)
        epaper = Pvariable(config[CONF_ID], rhs, type=WaveshareEPaperTypeA)
    elif model_type == 'b':
        rhs = App.make_waveshare_epaper_type_b(spi, cs, dc, model)
        epaper = Pvariable(config[CONF_ID], rhs, type=WaveshareEPaper)
    else:
        raise NotImplementedError()

    if CONF_LAMBDA in config:
        for lambda_ in process_lambda(config[CONF_LAMBDA],
                                      [(display.DisplayBufferRef, 'it')]):
            yield
        add(epaper.set_writer(lambda_))
    if CONF_RESET_PIN in config:
        for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]):
            yield
        add(epaper.set_reset_pin(reset))
    if CONF_BUSY_PIN in config:
        for reset in gpio_input_pin_expression(config[CONF_BUSY_PIN]):
            yield
        add(epaper.set_busy_pin(reset))
    if CONF_FULL_UPDATE_EVERY in config:
        add(epaper.set_full_update_every(config[CONF_FULL_UPDATE_EVERY]))

    display.setup_display(epaper, config)
Exemplo n.º 5
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))
    make = variable(config[CONF_MAKE_ID], rhs)
    hx711 = make.Phx711

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

    sensor.setup_sensor(hx711, make.Pmqtt, config)
    setup_component(hx711, config)
Exemplo n.º 6
0
def to_code(config):
    pin = None
    for pin in gpio_input_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin)
    gpio = variable(config[CONF_MAKE_ID], rhs)
    binary_sensor.setup_binary_sensor(gpio.Pgpio, gpio.Pmqtt, config)
Exemplo n.º 7
0
def to_code(config):
    pin = None
    for pin in gpio_input_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_duty_cycle_sensor(config[CONF_NAME], pin,
                                     config.get(CONF_UPDATE_INTERVAL))
    make = variable(config[CONF_MAKE_ID], rhs)
    sensor.setup_sensor(make.Pduty, make.Pmqtt, config)
Exemplo n.º 8
0
def to_code(config):
    pin_cs = gpio_output_pin_expression(config[CONF_PIN_CS])
    pin_clock = gpio_output_pin_expression(config[CONF_PIN_CLOCK])
    pin_miso = gpio_input_pin_expression(config[CONF_PIN_MISO])
    rhs = App.make_max6675_sensor(config[CONF_NAME], pin_cs, pin_clock,
                                  pin_miso, config.get(CONF_UPDATE_INTERVAL))
    make = variable(MakeMAX6675Sensor, config[CONF_MAKE_ID], rhs)
    sensor.setup_sensor(make.Pmax6675, make.Pmqtt, config)
Exemplo n.º 9
0
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)
    make = variable(config[CONF_MAKE_ID], rhs)
    encoder = make.Protary_encoder

    if CONF_PIN_RESET in config:
        pin_i = None
        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, make.Pmqtt, config)
    setup_component(encoder, config)
Exemplo n.º 10
0
def to_code(config):
    rhs = App.make_deep_sleep_component()
    deep_sleep = Pvariable(DeepSleepComponent, 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:
        pin = gpio_input_pin_expression(config[CONF_WAKEUP_PIN])
        add(deep_sleep.set_wakeup_pin(pin))
    if CONF_RUN_CYCLES in config:
        add(deep_sleep.set_run_cycles(config[CONF_RUN_CYCLES]))
    if CONF_RUN_DURATION in config:
        add(deep_sleep.set_run_duration(config[CONF_RUN_DURATION]))
Exemplo n.º 11
0
def to_code(config):
    trigger = gpio_output_pin_expression(config[CONF_TRIGGER_PIN])
    echo = gpio_input_pin_expression(config[CONF_ECHO_PIN])
    rhs = App.make_ultrasonic_sensor(config[CONF_NAME], trigger, echo,
                                     config.get(CONF_UPDATE_INTERVAL))
    make = variable(MakeUltrasonicSensor, config[CONF_MAKE_ID], rhs)
    ultrasonic = make.Pultrasonic
    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, make.Pmqtt, config)
Exemplo n.º 12
0
def to_code(config):
    pin = None
    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))
    make = variable(config[CONF_MAKE_ID], rhs)
    pcnt = make.Ppcnt
    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(make.Ppcnt, make.Pmqtt, config)
Exemplo n.º 13
0
def to_code(config):
    for conf in config:
        pin = None
        for pin in gpio_input_pin_expression(conf[CONF_PIN]):
            yield
        rhs = App.make_remote_receiver_component(pin)
        receiver = Pvariable(conf[CONF_ID], rhs)
        for dumper in conf[CONF_DUMP]:
            add(receiver.add_dumper(DUMPERS[dumper].new()))
        if CONF_TOLERANCE in conf:
            add(receiver.set_tolerance(conf[CONF_TOLERANCE]))
        if CONF_BUFFER_SIZE in conf:
            add(receiver.set_buffer_size(conf[CONF_BUFFER_SIZE]))
        if CONF_FILTER in conf:
            add(receiver.set_filter_us(conf[CONF_FILTER]))
        if CONF_IDLE in conf:
            add(receiver.set_idle_us(conf[CONF_IDLE]))
Exemplo n.º 14
0
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:
        pin = None
        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_CYCLES in config:
        add(deep_sleep.set_run_cycles(config[CONF_RUN_CYCLES]))
    if CONF_RUN_DURATION in config:
        add(deep_sleep.set_run_duration(config[CONF_RUN_DURATION]))
Exemplo n.º 15
0
def to_code(config):
    rhs = App.make_gpio_binary_sensor(
        config[CONF_NAME], gpio_input_pin_expression(config[CONF_PIN]))
    gpio = variable(MakeGPIOBinarySensor, config[CONF_MAKE_ID], rhs)
    binary_sensor.setup_binary_sensor(gpio.Pgpio, gpio.Pmqtt, config)