From 92e909568c59c65ad4cea8a63b78fcfc9150c1fb Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Tue, 29 Jan 2019 16:39:29 +0100 Subject: [PATCH] Fix Custom Components No Name (#395) * Fix Custom Components No Name Fixes https://github.com/esphome/ESPHome-Core/issues/445 * Fix --- esphomeyaml/components/binary_sensor/custom.py | 10 ++++++---- esphomeyaml/components/output/custom.py | 7 ++++--- esphomeyaml/components/sensor/custom.py | 10 ++++++---- esphomeyaml/components/switch/custom.py | 10 ++++++---- esphomeyaml/components/text_sensor/custom.py | 10 ++++++---- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/esphomeyaml/components/binary_sensor/custom.py b/esphomeyaml/components/binary_sensor/custom.py index c170793b99..71ddbcd972 100644 --- a/esphomeyaml/components/binary_sensor/custom.py +++ b/esphomeyaml/components/binary_sensor/custom.py @@ -2,8 +2,8 @@ import voluptuous as vol from esphomeyaml.components import binary_sensor import esphomeyaml.config_validation as cv -from esphomeyaml.const import CONF_BINARY_SENSORS, CONF_ID, CONF_LAMBDA -from esphomeyaml.cpp_generator import process_lambda, variable +from esphomeyaml.const import CONF_BINARY_SENSORS, CONF_ID, CONF_LAMBDA, CONF_NAME +from esphomeyaml.cpp_generator import process_lambda, variable, Pvariable, add from esphomeyaml.cpp_types import std_vector CustomBinarySensorConstructor = binary_sensor.binary_sensor_ns.class_( @@ -26,8 +26,10 @@ def to_code(config): rhs = CustomBinarySensorConstructor(template_) custom = variable(config[CONF_ID], rhs) - for i, sens in enumerate(config[CONF_BINARY_SENSORS]): - binary_sensor.register_binary_sensor(custom.get_binary_sensor(i), sens) + for i, conf in enumerate(config[CONF_BINARY_SENSORS]): + var = Pvariable(conf[CONF_ID], custom.get_binary_sensor(i)) + add(var.set_name(conf[CONF_NAME])) + binary_sensor.register_binary_sensor(var, conf) BUILD_FLAGS = '-DUSE_CUSTOM_BINARY_SENSOR' diff --git a/esphomeyaml/components/output/custom.py b/esphomeyaml/components/output/custom.py index d2953e4b47..89319ddaa6 100644 --- a/esphomeyaml/components/output/custom.py +++ b/esphomeyaml/components/output/custom.py @@ -3,7 +3,7 @@ import voluptuous as vol from esphomeyaml.components import output import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_OUTPUTS, CONF_TYPE -from esphomeyaml.cpp_generator import process_lambda, variable +from esphomeyaml.cpp_generator import process_lambda, variable, Pvariable from esphomeyaml.cpp_types import std_vector CustomBinaryOutputConstructor = output.output_ns.class_('CustomBinaryOutputConstructor') @@ -61,8 +61,9 @@ def to_code(config): rhs = klass(template_) custom = variable(config[CONF_ID], rhs) - for i, sens in enumerate(config[CONF_OUTPUTS]): - output.register_output(custom.get_output(i), sens) + for i, conf in enumerate(config[CONF_OUTPUTS]): + var = Pvariable(conf[CONF_ID], custom.get_output(i)) + output.register_output(var, conf) BUILD_FLAGS = '-DUSE_CUSTOM_OUTPUT' diff --git a/esphomeyaml/components/sensor/custom.py b/esphomeyaml/components/sensor/custom.py index a87fef6604..e56b85e2cb 100644 --- a/esphomeyaml/components/sensor/custom.py +++ b/esphomeyaml/components/sensor/custom.py @@ -2,8 +2,8 @@ import voluptuous as vol from esphomeyaml.components import sensor import esphomeyaml.config_validation as cv -from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_SENSORS -from esphomeyaml.cpp_generator import process_lambda, variable +from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_SENSORS, CONF_NAME +from esphomeyaml.cpp_generator import process_lambda, variable, Pvariable, add from esphomeyaml.cpp_types import std_vector CustomSensorConstructor = sensor.sensor_ns.class_('CustomSensorConstructor') @@ -24,8 +24,10 @@ def to_code(config): rhs = CustomSensorConstructor(template_) custom = variable(config[CONF_ID], rhs) - for i, sens in enumerate(config[CONF_SENSORS]): - sensor.register_sensor(custom.get_sensor(i), sens) + for i, conf in enumerate(config[CONF_SENSORS]): + var = Pvariable(conf[CONF_ID], custom.get_sensor(i)) + add(var.set_name(conf[CONF_NAME])) + sensor.register_sensor(var, conf) BUILD_FLAGS = '-DUSE_CUSTOM_SENSOR' diff --git a/esphomeyaml/components/switch/custom.py b/esphomeyaml/components/switch/custom.py index a763744ea9..3b23d9a022 100644 --- a/esphomeyaml/components/switch/custom.py +++ b/esphomeyaml/components/switch/custom.py @@ -2,8 +2,8 @@ import voluptuous as vol from esphomeyaml.components import switch import esphomeyaml.config_validation as cv -from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_SWITCHES -from esphomeyaml.cpp_generator import process_lambda, variable +from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_SWITCHES, CONF_NAME +from esphomeyaml.cpp_generator import process_lambda, variable, Pvariable, add from esphomeyaml.cpp_types import std_vector CustomSwitchConstructor = switch.switch_ns.class_('CustomSwitchConstructor') @@ -25,8 +25,10 @@ def to_code(config): rhs = CustomSwitchConstructor(template_) custom = variable(config[CONF_ID], rhs) - for i, sens in enumerate(config[CONF_SWITCHES]): - switch.register_switch(custom.get_switch(i), sens) + for i, conf in enumerate(config[CONF_SWITCHES]): + var = Pvariable(conf[CONF_ID], custom.get_switch(i)) + add(var.set_name(conf[CONF_NAME])) + switch.register_switch(var, conf) BUILD_FLAGS = '-DUSE_CUSTOM_SWITCH' diff --git a/esphomeyaml/components/text_sensor/custom.py b/esphomeyaml/components/text_sensor/custom.py index 468e971ef5..5c8684b074 100644 --- a/esphomeyaml/components/text_sensor/custom.py +++ b/esphomeyaml/components/text_sensor/custom.py @@ -2,8 +2,8 @@ import voluptuous as vol from esphomeyaml.components import text_sensor import esphomeyaml.config_validation as cv -from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_TEXT_SENSORS -from esphomeyaml.cpp_generator import process_lambda, variable +from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_TEXT_SENSORS, CONF_NAME +from esphomeyaml.cpp_generator import process_lambda, variable, Pvariable, add from esphomeyaml.cpp_types import std_vector CustomTextSensorConstructor = text_sensor.text_sensor_ns.class_('CustomTextSensorConstructor') @@ -25,8 +25,10 @@ def to_code(config): rhs = CustomTextSensorConstructor(template_) custom = variable(config[CONF_ID], rhs) - for i, sens in enumerate(config[CONF_TEXT_SENSORS]): - text_sensor.register_text_sensor(custom.get_text_sensor(i), sens) + for i, conf in enumerate(config[CONF_TEXT_SENSORS]): + var = Pvariable(conf[CONF_ID], custom.get_text_sensor(i)) + add(var.set_name(conf[CONF_NAME])) + text_sensor.register_text_sensor(var, conf) BUILD_FLAGS = '-DUSE_CUSTOM_TEXT_SENSOR'