mirror of
https://github.com/esphome/esphome.git
synced 2025-10-28 05:33:53 +00:00
Keep Device Class in Flash. (#4639)
* Keep Device Class in Flash. * Remove blank line --------- Co-authored-by: Your Name <you@example.com>
This commit is contained in:
@@ -63,13 +63,6 @@ void Switch::add_on_state_callback(std::function<void(bool)> &&callback) {
|
||||
void Switch::set_inverted(bool inverted) { this->inverted_ = inverted; }
|
||||
bool Switch::is_inverted() const { return this->inverted_; }
|
||||
|
||||
std::string Switch::get_device_class() {
|
||||
if (this->device_class_.has_value())
|
||||
return *this->device_class_;
|
||||
return "";
|
||||
}
|
||||
void Switch::set_device_class(const std::string &device_class) { this->device_class_ = device_class; }
|
||||
|
||||
void log_switch(const char *tag, const char *prefix, const char *type, Switch *obj) {
|
||||
if (obj != nullptr) {
|
||||
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
|
||||
|
||||
@@ -29,7 +29,7 @@ enum SwitchRestoreMode {
|
||||
* A switch is basically just a combination of a binary sensor (for reporting switch values)
|
||||
* and a write_state method that writes a state to the hardware.
|
||||
*/
|
||||
class Switch : public EntityBase {
|
||||
class Switch : public EntityBase, public EntityBase_DeviceClass {
|
||||
public:
|
||||
explicit Switch();
|
||||
|
||||
@@ -103,10 +103,6 @@ class Switch : public EntityBase {
|
||||
|
||||
bool is_inverted() const;
|
||||
|
||||
/// Get the device class for this switch.
|
||||
std::string get_device_class();
|
||||
/// Set the Home Assistant device class for this switch.
|
||||
void set_device_class(const std::string &device_class);
|
||||
void set_restore_mode(SwitchRestoreMode restore_mode) { this->restore_mode = restore_mode; }
|
||||
|
||||
protected:
|
||||
@@ -124,7 +120,6 @@ class Switch : public EntityBase {
|
||||
bool inverted_{false};
|
||||
Deduplicator<bool> publish_dedup_;
|
||||
ESPPreferenceObject rtc_;
|
||||
optional<std::string> device_class_;
|
||||
};
|
||||
|
||||
#define LOG_SWITCH(prefix, type, obj) log_switch((TAG), (prefix), LOG_STR_LITERAL(type), (obj))
|
||||
|
||||
Reference in New Issue
Block a user