From a15b647d139003e21efd5c6022c58f1eba6ab020 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Mon, 11 Feb 2019 15:50:12 +0100 Subject: [PATCH] Rework UART component for fixes (#419) --- esphomeyaml/components/uart.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/esphomeyaml/components/uart.py b/esphomeyaml/components/uart.py index 2e4d5b7704..4623b75516 100644 --- a/esphomeyaml/components/uart.py +++ b/esphomeyaml/components/uart.py @@ -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)