mirror of
https://github.com/esphome/esphome.git
synced 2024-12-23 16:47:57 +01:00
Support custom fan modes in mqtt_climate (#1989)
Co-authored-by: Michael Gorven <michael@gorven.za.net>
This commit is contained in:
parent
be61b38a2c
commit
294ba1fca7
@ -91,7 +91,7 @@ class ClimateTraits {
|
|||||||
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead")
|
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead")
|
||||||
void set_supports_fan_mode_diffuse(bool supported) { set_fan_mode_support_(CLIMATE_FAN_DIFFUSE, supported); }
|
void set_supports_fan_mode_diffuse(bool supported) { set_fan_mode_support_(CLIMATE_FAN_DIFFUSE, supported); }
|
||||||
bool supports_fan_mode(ClimateFanMode fan_mode) const { return supported_fan_modes_.count(fan_mode); }
|
bool supports_fan_mode(ClimateFanMode fan_mode) const { return supported_fan_modes_.count(fan_mode); }
|
||||||
bool get_supports_fan_modes() const { return !supported_fan_modes_.empty(); }
|
bool get_supports_fan_modes() const { return !supported_fan_modes_.empty() || !supported_custom_fan_modes_.empty(); }
|
||||||
const std::set<ClimateFanMode> get_supported_fan_modes() const { return supported_fan_modes_; }
|
const std::set<ClimateFanMode> get_supported_fan_modes() const { return supported_fan_modes_; }
|
||||||
|
|
||||||
void set_supported_custom_fan_modes(std::set<std::string> supported_custom_fan_modes) {
|
void set_supported_custom_fan_modes(std::set<std::string> supported_custom_fan_modes) {
|
||||||
|
@ -97,6 +97,8 @@ void MQTTClimateComponent::send_discovery(JsonObject &root, mqtt::SendDiscoveryC
|
|||||||
fan_modes.add("focus");
|
fan_modes.add("focus");
|
||||||
if (traits.supports_fan_mode(CLIMATE_FAN_DIFFUSE))
|
if (traits.supports_fan_mode(CLIMATE_FAN_DIFFUSE))
|
||||||
fan_modes.add("diffuse");
|
fan_modes.add("diffuse");
|
||||||
|
for (const auto &fan_mode : traits.get_supported_custom_fan_modes())
|
||||||
|
fan_modes.add(fan_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (traits.get_supports_swing_modes()) {
|
if (traits.get_supports_swing_modes()) {
|
||||||
@ -291,7 +293,8 @@ bool MQTTClimateComponent::publish_state_() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (traits.get_supports_fan_modes()) {
|
if (traits.get_supports_fan_modes()) {
|
||||||
const char *payload = "";
|
std::string payload;
|
||||||
|
if (this->device_->fan_mode.has_value())
|
||||||
switch (this->device_->fan_mode.value()) {
|
switch (this->device_->fan_mode.value()) {
|
||||||
case CLIMATE_FAN_ON:
|
case CLIMATE_FAN_ON:
|
||||||
payload = "on";
|
payload = "on";
|
||||||
@ -321,6 +324,8 @@ bool MQTTClimateComponent::publish_state_() {
|
|||||||
payload = "diffuse";
|
payload = "diffuse";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (this->device_->custom_fan_mode.has_value())
|
||||||
|
payload = this->device_->custom_fan_mode.value();
|
||||||
if (!this->publish(this->get_fan_mode_state_topic(), payload))
|
if (!this->publish(this->get_fan_mode_state_topic(), payload))
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user