1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-07 13:52:20 +01:00

Add device class support to Switch (#3012)

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
This commit is contained in:
Franck Nijhof
2022-02-03 21:04:48 +01:00
committed by GitHub
parent 21803607e7
commit e7864a28a1
9 changed files with 49 additions and 1 deletions

View File

@@ -20,6 +20,9 @@ namespace switch_ {
if ((obj)->is_inverted()) { \
ESP_LOGCONFIG(TAG, "%s Inverted: YES", prefix); \
} \
if (!(obj)->get_device_class().empty()) { \
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \
} \
}
/** Base class for all switches.
@@ -88,6 +91,11 @@ 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);
protected:
/** Write the given state to hardware. You should implement this
* abstract method if you want to create your own switch.
@@ -105,6 +113,7 @@ class Switch : public EntityBase {
bool inverted_{false};
Deduplicator<bool> publish_dedup_;
ESPPreferenceObject rtc_;
optional<std::string> device_class_;
};
} // namespace switch_