Example #1
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

    rhs = App.make_spi_ssd1306(spi_, cs, dc)
    ssd = Pvariable(config[CONF_ID], rhs)
    add(ssd.set_model(MODELS[config[CONF_MODEL]]))

    if CONF_RESET_PIN in config:
        for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]):
            yield
        add(ssd.set_reset_pin(reset))
    if CONF_EXTERNAL_VCC in config:
        add(ssd.set_external_vcc(config[CONF_EXTERNAL_VCC]))
    if CONF_LAMBDA in config:
        for lambda_ in process_lambda(config[CONF_LAMBDA],
                                      [(display.DisplayBufferRef, 'it')],
                                      return_type=void):
            yield
        add(ssd.set_writer(lambda_))

    display.setup_display(ssd, config)
    setup_component(ssd, config)
Example #2
0
def to_code(config):
    rhs = App.make_gpio_lcd_display(config[CONF_DIMENSIONS][0],
                                    config[CONF_DIMENSIONS][1])
    lcd = Pvariable(config[CONF_ID], rhs)
    pins_ = []
    for conf in config[CONF_DATA_PINS]:
        for pin in gpio_output_pin_expression(conf):
            yield
        pins_.append(pin)
    add(lcd.set_data_pins(*pins_))
    for enable in gpio_output_pin_expression(config[CONF_ENABLE_PIN]):
        yield
    add(lcd.set_enable_pin(enable))

    for rs in gpio_output_pin_expression(config[CONF_RS_PIN]):
        yield
    add(lcd.set_rs_pin(rs))

    if CONF_RW_PIN in config:
        for rw in gpio_output_pin_expression(config[CONF_RW_PIN]):
            yield
        add(lcd.set_rw_pin(rw))

    if CONF_LAMBDA in config:
        for lambda_ in process_lambda(config[CONF_LAMBDA],
                                      [(LCDDisplayRef, 'it')],
                                      return_type=void):
            yield
        add(lcd.set_writer(lambda_))

    display.setup_display(lcd, config)
    setup_component(lcd, config)
Example #3
0
def to_code(config):
    for step_pin in gpio_output_pin_expression(config[CONF_STEP_PIN]):
        yield
    for dir_pin in gpio_output_pin_expression(config[CONF_DIR_PIN]):
        yield
    rhs = App.make_a4988(step_pin, dir_pin)
    a4988 = Pvariable(config[CONF_ID], rhs)

    if CONF_SLEEP_PIN in config:
        for sleep_pin in gpio_output_pin_expression(config[CONF_SLEEP_PIN]):
            yield
        add(a4988.set_sleep_pin(sleep_pin))

    stepper.setup_stepper(a4988, config)
    setup_component(a4988, config)
Example #4
0
def to_code(config):
    for pin in gpio_output_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_status_led(pin)
    var = Pvariable(config[CONF_ID], rhs)

    setup_component(var, config)
Example #5
0
def to_code(config):
    for di in gpio_output_pin_expression(config[CONF_DATA_PIN]):
        yield
    for dcki in gpio_output_pin_expression(config[CONF_CLOCK_PIN]):
        yield
    rhs = App.make_my9231_component(di, dcki)
    my9231 = Pvariable(config[CONF_ID], rhs)
    if CONF_NUM_CHANNELS in config:
        add(my9231.set_num_channels(config[CONF_NUM_CHANNELS]))
    if CONF_NUM_CHIPS in config:
        add(my9231.set_num_chips(config[CONF_NUM_CHIPS]))
    if CONF_BIT_DEPTH in config:
        add(my9231.set_bit_depth(config[CONF_BIT_DEPTH]))
    if CONF_UPDATE_ON_BOOT in config:
        add(my9231.set_update(config[CONF_UPDATE_ON_BOOT]))
    setup_component(my9231, config)
Example #6
0
File: gpio.py Project: khzd/pi4home
def to_code(config):
    for pin in gpio_output_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_gpio_output(pin)
    gpio = Pvariable(config[CONF_ID], rhs)
    output.setup_output_platform(gpio, config)
    setup_component(gpio, config)
Example #7
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_max31855_sensor(config[CONF_NAME], spi_, cs,
                                   config.get(CONF_UPDATE_INTERVAL))
    max31855 = Pvariable(config[CONF_ID], rhs)
    sensor.setup_sensor(max31855, config)
    setup_component(max31855, config)
Example #8
0
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)
Example #9
0
def to_code(config):
    for pin_a in gpio_output_pin_expression(config[CONF_PIN_A]):
        yield
    for pin_b in gpio_output_pin_expression(config[CONF_PIN_B]):
        yield
    for pin_c in gpio_output_pin_expression(config[CONF_PIN_C]):
        yield
    for pin_d in gpio_output_pin_expression(config[CONF_PIN_D]):
        yield
    rhs = App.make_uln2003(pin_a, pin_b, pin_c, pin_d)
    uln = Pvariable(config[CONF_ID], rhs)

    if CONF_SLEEP_WHEN_DONE in config:
        add(uln.set_sleep_when_done(config[CONF_SLEEP_WHEN_DONE]))

    if CONF_STEP_MODE in config:
        add(uln.set_step_mode(STEP_MODES[config[CONF_STEP_MODE]]))

    stepper.setup_stepper(uln, config)
    setup_component(uln, config)
Example #10
0
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)
Example #11
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_pn532_component(spi_, cs, config.get(CONF_UPDATE_INTERVAL))
    pn532 = Pvariable(config[CONF_ID], rhs)

    for conf_ in config.get(CONF_ON_TAG, []):
        trigger = Pvariable(conf_[CONF_TRIGGER_ID], pn532.make_trigger())
        automation.build_automations(trigger, [(std_string, 'x')], conf_)

    setup_component(pn532, config)
Example #12
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')],
                                      return_type=void):
            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)
    setup_component(epaper, config)
Example #13
0
File: spi.py Project: khzd/pi4home
def to_code(config):
    for clk in gpio_output_pin_expression(config[CONF_CLK_PIN]):
        yield
    rhs = App.init_spi(clk)
    spi = Pvariable(config[CONF_ID], rhs)
    if CONF_MISO_PIN in config:
        for miso in gpio_input_pin_expression(config[CONF_MISO_PIN]):
            yield
        add(spi.set_miso(miso))
    if CONF_MOSI_PIN in config:
        for mosi in gpio_input_pin_expression(config[CONF_MOSI_PIN]):
            yield
        add(spi.set_mosi(mosi))

    setup_component(spi, config)
Example #14
0
File: dht.py Project: khzd/pi4home
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)
Example #15
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 in config:
        add(ultrasonic.set_timeout_us(config[CONF_TIMEOUT] / (0.000343 / 2)))

    if CONF_PULSE_TIME in config:
        add(ultrasonic.set_pulse_time_us(config[CONF_PULSE_TIME]))

    sensor.setup_sensor(ultrasonic, config)
    setup_component(ultrasonic, config)
Example #16
0
def to_code(config):
    rhs = App.init_ethernet()
    eth = Pvariable(config[CONF_ID], rhs)

    add(eth.set_phy_addr(config[CONF_PHY_ADDR]))
    add(eth.set_mdc_pin(config[CONF_MDC_PIN]))
    add(eth.set_mdio_pin(config[CONF_MDIO_PIN]))
    add(eth.set_type(ETHERNET_TYPES[config[CONF_TYPE]]))
    add(eth.set_clk_mode(CLK_MODES[config[CONF_CLK_MODE]]))
    add(eth.set_use_address(config[CONF_USE_ADDRESS]))

    if CONF_POWER_PIN in config:
        for pin in gpio_output_pin_expression(config[CONF_POWER_PIN]):
            yield
        add(eth.set_power_pin(pin))

    if CONF_MANUAL_IP in config:
        add(eth.set_manual_ip(wifi.manual_ip(config[CONF_MANUAL_IP])))
Example #17
0
File: gpio.py Project: khzd/pi4home
def to_code(config):
    for pin in gpio_output_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_gpio_switch(config[CONF_NAME], pin)
    gpio = Pvariable(config[CONF_ID], rhs)

    if CONF_RESTORE_MODE in config:
        add(gpio.set_restore_mode(RESTORE_MODES[config[CONF_RESTORE_MODE]]))

    if CONF_INTERLOCK in config:
        interlock = []
        for it in config[CONF_INTERLOCK]:
            for lock in get_variable(it):
                yield
            interlock.append(lock)
        add(gpio.set_interlock(interlock))

    switch.setup_switch(gpio, config)
    setup_component(gpio, config)
Example #18
0
def to_code(config):
    ssd = Pvariable(config[CONF_ID], App.make_i2c_ssd1306())
    add(ssd.set_model(ssd1306_spi.MODELS[config[CONF_MODEL]]))

    if CONF_RESET_PIN in config:
        for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]):
            yield
        add(ssd.set_reset_pin(reset))
    if CONF_EXTERNAL_VCC in config:
        add(ssd.set_external_vcc(config[CONF_EXTERNAL_VCC]))
    if CONF_ADDRESS in config:
        add(ssd.set_address(config[CONF_ADDRESS]))
    if CONF_LAMBDA in config:
        for lambda_ in process_lambda(config[CONF_LAMBDA],
                                      [(display.DisplayBufferRef, 'it')],
                                      return_type=void):
            yield
        add(ssd.set_writer(lambda_))

    display.setup_display(ssd, config)
    setup_component(ssd, config)
Example #19
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_max7219(spi_, cs)
    max7219 = Pvariable(config[CONF_ID], rhs)

    if CONF_NUM_CHIPS in config:
        add(max7219.set_num_chips(config[CONF_NUM_CHIPS]))
    if CONF_INTENSITY in config:
        add(max7219.set_intensity(config[CONF_INTENSITY]))

    if CONF_LAMBDA in config:
        for lambda_ in process_lambda(config[CONF_LAMBDA],
                                      [(MAX7219ComponentRef, 'it')],
                                      return_type=void):
            yield
        add(max7219.set_writer(lambda_))

    display.setup_display(max7219, config)
    setup_component(max7219, config)
Example #20
0
def to_code(config):
    for sel in gpio_output_pin_expression(config[CONF_SEL_PIN]):
        yield

    rhs = App.make_hlw8012(sel, config[CONF_CF_PIN], config[CONF_CF1_PIN],
                           config.get(CONF_UPDATE_INTERVAL))
    hlw = Pvariable(config[CONF_ID], rhs)

    if CONF_VOLTAGE in config:
        conf = config[CONF_VOLTAGE]
        sensor.register_sensor(hlw.make_voltage_sensor(conf[CONF_NAME]), conf)
    if CONF_CURRENT in config:
        conf = config[CONF_CURRENT]
        sensor.register_sensor(hlw.make_current_sensor(conf[CONF_NAME]), conf)
    if CONF_POWER in config:
        conf = config[CONF_POWER]
        sensor.register_sensor(hlw.make_power_sensor(conf[CONF_NAME]), conf)
    if CONF_CURRENT_RESISTOR in config:
        add(hlw.set_current_resistor(config[CONF_CURRENT_RESISTOR]))
    if CONF_VOLTAGE_DIVIDER in config:
        add(hlw.set_voltage_divider(config[CONF_VOLTAGE_DIVIDER]))
    if CONF_CHANGE_MODE_EVERY in config:
        add(hlw.set_change_mode_every(config[CONF_CHANGE_MODE_EVERY]))
    setup_component(hlw, config)