Skip to content

Commit

Permalink
Add climate dry fan (esphome#845)
Browse files Browse the repository at this point in the history
* add climate dry fan

* clang-format

* updates, add swing mode, add back compat with old ha

* revert client-config add swing

* sort const.py

* fix missing retur
  • Loading branch information
glmnet authored and OttoWinter committed Nov 16, 2019
1 parent 4f8f59f commit 1814e4a
Show file tree
Hide file tree
Showing 21 changed files with 825 additions and 86 deletions.
27 changes: 27 additions & 0 deletions esphome/components/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,25 @@ enum ClimateMode {
CLIMATE_MODE_AUTO = 1;
CLIMATE_MODE_COOL = 2;
CLIMATE_MODE_HEAT = 3;
CLIMATE_MODE_FAN_ONLY = 4;
CLIMATE_MODE_DRY = 5;
}
enum ClimateFanMode {
CLIMATE_FAN_ON = 0;
CLIMATE_FAN_OFF = 1;
CLIMATE_FAN_AUTO = 2;
CLIMATE_FAN_LOW = 3;
CLIMATE_FAN_MEDIUM = 4;
CLIMATE_FAN_HIGH = 5;
CLIMATE_FAN_MIDDLE = 6;
CLIMATE_FAN_FOCUS = 7;
CLIMATE_FAN_DIFFUSE = 8;
}
enum ClimateSwingMode {
CLIMATE_SWING_OFF = 0;
CLIMATE_SWING_BOTH = 1;
CLIMATE_SWING_VERTICAL = 2;
CLIMATE_SWINT_HORIZONTAL = 3;
}
enum ClimateAction {
CLIMATE_ACTION_OFF = 0;
Expand All @@ -678,6 +697,8 @@ message ListEntitiesClimateResponse {
float visual_temperature_step = 10;
bool supports_away = 11;
bool supports_action = 12;
repeated ClimateFanMode supported_fan_modes = 13;
repeated ClimateSwingMode supported_swing_modes = 14;
}
message ClimateStateResponse {
option (id) = 47;
Expand All @@ -693,6 +714,8 @@ message ClimateStateResponse {
float target_temperature_high = 6;
bool away = 7;
ClimateAction action = 8;
ClimateFanMode fan_mode = 9;
ClimateSwingMode swing_mode = 10;
}
message ClimateCommandRequest {
option (id) = 48;
Expand All @@ -711,4 +734,8 @@ message ClimateCommandRequest {
float target_temperature_high = 9;
bool has_away = 10;
bool away = 11;
bool has_fan_mode = 12;
ClimateFanMode fan_mode = 13;
bool has_swing_mode = 14;
ClimateSwingMode swing_mode = 15;
}
21 changes: 20 additions & 1 deletion esphome/components/api/api_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ bool APIConnection::send_climate_state(climate::Climate *climate) {
}
if (traits.get_supports_away())
resp.away = climate->away;
if (traits.get_supports_fan_modes())
resp.fan_mode = static_cast<enums::ClimateFanMode>(climate->fan_mode);
if (traits.get_supports_swing_modes())
resp.swing_mode = static_cast<enums::ClimateSwingMode>(climate->swing_mode);
return this->send_climate_state_response(resp);
}
bool APIConnection::send_climate_info(climate::Climate *climate) {
Expand All @@ -470,7 +474,7 @@ bool APIConnection::send_climate_info(climate::Climate *climate) {
msg.supports_current_temperature = traits.get_supports_current_temperature();
msg.supports_two_point_target_temperature = traits.get_supports_two_point_target_temperature();
for (auto mode : {climate::CLIMATE_MODE_AUTO, climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_COOL,
climate::CLIMATE_MODE_HEAT}) {
climate::CLIMATE_MODE_HEAT, climate::CLIMATE_MODE_DRY, climate::CLIMATE_MODE_FAN_ONLY}) {
if (traits.supports_mode(mode))
msg.supported_modes.push_back(static_cast<enums::ClimateMode>(mode));
}
Expand All @@ -479,6 +483,17 @@ bool APIConnection::send_climate_info(climate::Climate *climate) {
msg.visual_temperature_step = traits.get_visual_temperature_step();
msg.supports_away = traits.get_supports_away();
msg.supports_action = traits.get_supports_action();
for (auto fan_mode : {climate::CLIMATE_FAN_ON, climate::CLIMATE_FAN_OFF, climate::CLIMATE_FAN_AUTO,
climate::CLIMATE_FAN_LOW, climate::CLIMATE_FAN_MEDIUM, climate::CLIMATE_FAN_HIGH,
climate::CLIMATE_FAN_MIDDLE, climate::CLIMATE_FAN_FOCUS, climate::CLIMATE_FAN_DIFFUSE}) {
if (traits.supports_fan_mode(fan_mode))
msg.supported_fan_modes.push_back(static_cast<enums::ClimateFanMode>(fan_mode));
}
for (auto swing_mode : {climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_BOTH, climate::CLIMATE_SWING_VERTICAL,
climate::CLIMATE_SWING_HORIZONTAL}) {
if (traits.supports_swing_mode(swing_mode))
msg.supported_swing_modes.push_back(static_cast<enums::ClimateSwingMode>(swing_mode));
}
return this->send_list_entities_climate_response(msg);
}
void APIConnection::climate_command(const ClimateCommandRequest &msg) {
Expand All @@ -497,6 +512,10 @@ void APIConnection::climate_command(const ClimateCommandRequest &msg) {
call.set_target_temperature_high(msg.target_temperature_high);
if (msg.has_away)
call.set_away(msg.away);
if (msg.has_fan_mode)
call.set_fan_mode(static_cast<climate::ClimateFanMode>(msg.fan_mode));
if (msg.has_swing_mode)
call.set_swing_mode(static_cast<climate::ClimateSwingMode>(msg.swing_mode));
call.perform();
}
#endif
Expand Down
124 changes: 124 additions & 0 deletions esphome/components/api/api_pb2.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// This file was automatically generated with a tool.
// See scripts/api_protobuf/api_protobuf.py
#include "api_pb2.h"
#include "esphome/core/log.h"

Expand Down Expand Up @@ -102,6 +104,48 @@ template<> const char *proto_enum_to_string<enums::ClimateMode>(enums::ClimateMo
return "CLIMATE_MODE_COOL";
case enums::CLIMATE_MODE_HEAT:
return "CLIMATE_MODE_HEAT";
case enums::CLIMATE_MODE_FAN_ONLY:
return "CLIMATE_MODE_FAN_ONLY";
case enums::CLIMATE_MODE_DRY:
return "CLIMATE_MODE_DRY";
default:
return "UNKNOWN";
}
}
template<> const char *proto_enum_to_string<enums::ClimateFanMode>(enums::ClimateFanMode value) {
switch (value) {
case enums::CLIMATE_FAN_ON:
return "CLIMATE_FAN_ON";
case enums::CLIMATE_FAN_OFF:
return "CLIMATE_FAN_OFF";
case enums::CLIMATE_FAN_AUTO:
return "CLIMATE_FAN_AUTO";
case enums::CLIMATE_FAN_LOW:
return "CLIMATE_FAN_LOW";
case enums::CLIMATE_FAN_MEDIUM:
return "CLIMATE_FAN_MEDIUM";
case enums::CLIMATE_FAN_HIGH:
return "CLIMATE_FAN_HIGH";
case enums::CLIMATE_FAN_MIDDLE:
return "CLIMATE_FAN_MIDDLE";
case enums::CLIMATE_FAN_FOCUS:
return "CLIMATE_FAN_FOCUS";
case enums::CLIMATE_FAN_DIFFUSE:
return "CLIMATE_FAN_DIFFUSE";
default:
return "UNKNOWN";
}
}
template<> const char *proto_enum_to_string<enums::ClimateSwingMode>(enums::ClimateSwingMode value) {
switch (value) {
case enums::CLIMATE_SWING_OFF:
return "CLIMATE_SWING_OFF";
case enums::CLIMATE_SWING_BOTH:
return "CLIMATE_SWING_BOTH";
case enums::CLIMATE_SWING_VERTICAL:
return "CLIMATE_SWING_VERTICAL";
case enums::CLIMATE_SWINT_HORIZONTAL:
return "CLIMATE_SWINT_HORIZONTAL";
default:
return "UNKNOWN";
}
Expand Down Expand Up @@ -2458,6 +2502,14 @@ bool ListEntitiesClimateResponse::decode_varint(uint32_t field_id, ProtoVarInt v
this->supports_action = value.as_bool();
return true;
}
case 13: {
this->supported_fan_modes.push_back(value.as_enum<enums::ClimateFanMode>());
return true;
}
case 14: {
this->supported_swing_modes.push_back(value.as_enum<enums::ClimateSwingMode>());
return true;
}
default:
return false;
}
Expand Down Expand Up @@ -2517,6 +2569,12 @@ void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_float(10, this->visual_temperature_step);
buffer.encode_bool(11, this->supports_away);
buffer.encode_bool(12, this->supports_action);
for (auto &it : this->supported_fan_modes) {
buffer.encode_enum<enums::ClimateFanMode>(13, it, true);
}
for (auto &it : this->supported_swing_modes) {
buffer.encode_enum<enums::ClimateSwingMode>(14, it, true);
}
}
void ListEntitiesClimateResponse::dump_to(std::string &out) const {
char buffer[64];
Expand Down Expand Up @@ -2574,6 +2632,18 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const {
out.append(" supports_action: ");
out.append(YESNO(this->supports_action));
out.append("\n");

for (const auto &it : this->supported_fan_modes) {
out.append(" supported_fan_modes: ");
out.append(proto_enum_to_string<enums::ClimateFanMode>(it));
out.append("\n");
}

for (const auto &it : this->supported_swing_modes) {
out.append(" supported_swing_modes: ");
out.append(proto_enum_to_string<enums::ClimateSwingMode>(it));
out.append("\n");
}
out.append("}");
}
bool ClimateStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
Expand All @@ -2590,6 +2660,14 @@ bool ClimateStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
this->action = value.as_enum<enums::ClimateAction>();
return true;
}
case 9: {
this->fan_mode = value.as_enum<enums::ClimateFanMode>();
return true;
}
case 10: {
this->swing_mode = value.as_enum<enums::ClimateSwingMode>();
return true;
}
default:
return false;
}
Expand Down Expand Up @@ -2629,6 +2707,8 @@ void ClimateStateResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_float(6, this->target_temperature_high);
buffer.encode_bool(7, this->away);
buffer.encode_enum<enums::ClimateAction>(8, this->action);
buffer.encode_enum<enums::ClimateFanMode>(9, this->fan_mode);
buffer.encode_enum<enums::ClimateSwingMode>(10, this->swing_mode);
}
void ClimateStateResponse::dump_to(std::string &out) const {
char buffer[64];
Expand Down Expand Up @@ -2669,6 +2749,14 @@ void ClimateStateResponse::dump_to(std::string &out) const {
out.append(" action: ");
out.append(proto_enum_to_string<enums::ClimateAction>(this->action));
out.append("\n");

out.append(" fan_mode: ");
out.append(proto_enum_to_string<enums::ClimateFanMode>(this->fan_mode));
out.append("\n");

out.append(" swing_mode: ");
out.append(proto_enum_to_string<enums::ClimateSwingMode>(this->swing_mode));
out.append("\n");
out.append("}");
}
bool ClimateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
Expand Down Expand Up @@ -2701,6 +2789,22 @@ bool ClimateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value)
this->away = value.as_bool();
return true;
}
case 12: {
this->has_fan_mode = value.as_bool();
return true;
}
case 13: {
this->fan_mode = value.as_enum<enums::ClimateFanMode>();
return true;
}
case 14: {
this->has_swing_mode = value.as_bool();
return true;
}
case 15: {
this->swing_mode = value.as_enum<enums::ClimateSwingMode>();
return true;
}
default:
return false;
}
Expand Down Expand Up @@ -2739,6 +2843,10 @@ void ClimateCommandRequest::encode(ProtoWriteBuffer buffer) const {
buffer.encode_float(9, this->target_temperature_high);
buffer.encode_bool(10, this->has_away);
buffer.encode_bool(11, this->away);
buffer.encode_bool(12, this->has_fan_mode);
buffer.encode_enum<enums::ClimateFanMode>(13, this->fan_mode);
buffer.encode_bool(14, this->has_swing_mode);
buffer.encode_enum<enums::ClimateSwingMode>(15, this->swing_mode);
}
void ClimateCommandRequest::dump_to(std::string &out) const {
char buffer[64];
Expand Down Expand Up @@ -2790,6 +2898,22 @@ void ClimateCommandRequest::dump_to(std::string &out) const {
out.append(" away: ");
out.append(YESNO(this->away));
out.append("\n");

out.append(" has_fan_mode: ");
out.append(YESNO(this->has_fan_mode));
out.append("\n");

out.append(" fan_mode: ");
out.append(proto_enum_to_string<enums::ClimateFanMode>(this->fan_mode));
out.append("\n");

out.append(" has_swing_mode: ");
out.append(YESNO(this->has_swing_mode));
out.append("\n");

out.append(" swing_mode: ");
out.append(proto_enum_to_string<enums::ClimateSwingMode>(this->swing_mode));
out.append("\n");
out.append("}");
}

Expand Down
Loading

0 comments on commit 1814e4a

Please sign in to comment.