Rework UART component for fixes (#419)

This commit is contained in:
Otto Winter 2019-02-11 15:50:12 +01:00 committed by GitHub
parent feab956ea9
commit a15b647d13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ import voluptuous as vol
from esphomeyaml import pins
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_BAUD_RATE, CONF_ID, CONF_RX_PIN, CONF_TX_PIN
from esphomeyaml.cpp_generator import Pvariable
from esphomeyaml.cpp_generator import Pvariable, add
from esphomeyaml.cpp_helpers import setup_component
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
@ -20,11 +20,14 @@ CONFIG_SCHEMA = vol.All(vol.Schema({
def to_code(config):
tx = config.get(CONF_TX_PIN, -1)
rx = config.get(CONF_RX_PIN, -1)
rhs = App.init_uart(tx, rx, config[CONF_BAUD_RATE])
rhs = App.init_uart(config[CONF_BAUD_RATE])
var = Pvariable(config[CONF_ID], rhs)
if CONF_TX_PIN in config:
add(var.set_tx_pin(config[CONF_TX_PIN]))
if CONF_RX_PIN in config:
add(var.set_rx_pin(config[CONF_RX_PIN]))
setup_component(var, config)