From 6772e389ce6aea6fe097ee2306c37c04dc730c57 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Mon, 18 Feb 2019 18:49:42 +0100 Subject: [PATCH] Add empty nameable constructors (#509) --- src/esphome/switch_/switch.cpp | 6 ++---- src/esphome/switch_/switch.h | 1 + src/esphome/text_sensor/text_sensor.cpp | 3 +++ src/esphome/text_sensor/text_sensor.h | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/esphome/switch_/switch.cpp b/src/esphome/switch_/switch.cpp index 7afefdf2..f66ff047 100644 --- a/src/esphome/switch_/switch.cpp +++ b/src/esphome/switch_/switch.cpp @@ -15,10 +15,8 @@ static const char *TAG = "switch"; std::string Switch::icon() { return ""; } -Switch::Switch(const std::string &name) - : Nameable(name), state(false) { - -} +Switch::Switch(const std::string &name) : Nameable(name), state(false) {} +Switch::Switch() : Switch("") {} std::string Switch::get_icon() { if (this->icon_.has_value()) diff --git a/src/esphome/switch_/switch.h b/src/esphome/switch_/switch.h index 4f9bbd60..365fc023 100644 --- a/src/esphome/switch_/switch.h +++ b/src/esphome/switch_/switch.h @@ -51,6 +51,7 @@ class MQTTSwitchComponent; */ class Switch : public Nameable { public: + explicit Switch(); explicit Switch(const std::string &name); /** Publish a state to the front-end from the back-end. diff --git a/src/esphome/text_sensor/text_sensor.cpp b/src/esphome/text_sensor/text_sensor.cpp index 87ee5634..bc24f2a1 100644 --- a/src/esphome/text_sensor/text_sensor.cpp +++ b/src/esphome/text_sensor/text_sensor.cpp @@ -11,6 +11,9 @@ namespace text_sensor { static const char *TAG = "text_sensor.text_sensor"; +TextSensor::TextSensor() : TextSensor("") {} +TextSensor::TextSensor(const std::string &name) : Nameable(name) {} + void TextSensor::publish_state(std::string state) { this->state = state; this->has_state_ = true; diff --git a/src/esphome/text_sensor/text_sensor.h b/src/esphome/text_sensor/text_sensor.h index 29b23045..d73d5462 100644 --- a/src/esphome/text_sensor/text_sensor.h +++ b/src/esphome/text_sensor/text_sensor.h @@ -34,7 +34,8 @@ class MQTTTextSensor; class TextSensor : public Nameable { public: - explicit TextSensor(const std::string &name) : Nameable(name) {} + explicit TextSensor(); + explicit TextSensor(const std::string &name); void publish_state(std::string state);