1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-28 05:33:53 +00:00

add support for climate action (#720)

* add support for climate action:

Following hass implementation of climate, action represents the current action the climate device is perfoming, e.g. cooling or heating

fix bang_bang climate:

make sure that the thresholds are always respected.
fixes the issue where the component would just keep on heating, regardless of the temperature range

* Updates

- Use dedicated enum for action (otherwise it gets confusing because "auto" is not a valid action)
- Add field to tell HA that action is supported
- Revert semantic changes in bang_bang

* Conditional print


Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Marcel van der Veldt
2019-10-18 10:39:14 +02:00
committed by Otto Winter
parent 22aecdfc6f
commit 72d6471ab8
12 changed files with 101 additions and 25 deletions

View File

@@ -644,6 +644,12 @@ enum ClimateMode {
CLIMATE_MODE_COOL = 2;
CLIMATE_MODE_HEAT = 3;
}
enum ClimateAction {
CLIMATE_ACTION_OFF = 0;
// values same as mode for readability
CLIMATE_ACTION_COOLING = 2;
CLIMATE_ACTION_HEATING = 3;
}
message ListEntitiesClimateResponse {
option (id) = 46;
option (source) = SOURCE_SERVER;
@@ -661,6 +667,7 @@ message ListEntitiesClimateResponse {
float visual_max_temperature = 9;
float visual_temperature_step = 10;
bool supports_away = 11;
bool supports_action = 12;
}
message ClimateStateResponse {
option (id) = 47;
@@ -675,6 +682,7 @@ message ClimateStateResponse {
float target_temperature_low = 5;
float target_temperature_high = 6;
bool away = 7;
ClimateAction action = 8;
}
message ClimateCommandRequest {
option (id) = 48;

View File

@@ -442,6 +442,7 @@ bool APIConnection::send_climate_state(climate::Climate *climate) {
ClimateStateResponse resp{};
resp.key = climate->get_object_id_hash();
resp.mode = static_cast<EnumClimateMode>(climate->mode);
resp.action = static_cast<EnumClimateAction>(climate->action);
if (traits.get_supports_current_temperature())
resp.current_temperature = climate->current_temperature;
if (traits.get_supports_two_point_target_temperature()) {
@@ -472,6 +473,7 @@ bool APIConnection::send_climate_info(climate::Climate *climate) {
msg.visual_max_temperature = traits.get_visual_max_temperature();
msg.visual_temperature_step = traits.get_visual_temperature_step();
msg.supports_away = traits.get_supports_away();
msg.supports_action = traits.get_supports_action();
return this->send_list_entities_climate_response(msg);
}
void APIConnection::climate_command(const ClimateCommandRequest &msg) {

View File

@@ -106,6 +106,18 @@ template<> const char *proto_enum_to_string<EnumClimateMode>(EnumClimateMode val
return "UNKNOWN";
}
}
template<> const char *proto_enum_to_string<EnumClimateAction>(EnumClimateAction value) {
switch (value) {
case CLIMATE_ACTION_OFF:
return "CLIMATE_ACTION_OFF";
case CLIMATE_ACTION_COOLING:
return "CLIMATE_ACTION_COOLING";
case CLIMATE_ACTION_HEATING:
return "CLIMATE_ACTION_HEATING";
default:
return "UNKNOWN";
}
}
bool HelloRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) {
switch (field_id) {
case 1: {
@@ -2394,6 +2406,10 @@ bool ListEntitiesClimateResponse::decode_varint(uint32_t field_id, ProtoVarInt v
this->supports_away = value.as_bool();
return true;
}
case 12: {
this->supports_action = value.as_bool();
return true;
}
default:
return false;
}
@@ -2452,6 +2468,7 @@ void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_float(9, this->visual_max_temperature);
buffer.encode_float(10, this->visual_temperature_step);
buffer.encode_bool(11, this->supports_away);
buffer.encode_bool(12, this->supports_action);
}
void ListEntitiesClimateResponse::dump_to(std::string &out) const {
char buffer[64];
@@ -2505,6 +2522,10 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const {
out.append(" supports_away: ");
out.append(YESNO(this->supports_away));
out.append("\n");
out.append(" supports_action: ");
out.append(YESNO(this->supports_action));
out.append("\n");
out.append("}");
}
bool ClimateStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
@@ -2517,6 +2538,10 @@ bool ClimateStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
this->away = value.as_bool();
return true;
}
case 8: {
this->action = value.as_enum<EnumClimateAction>();
return true;
}
default:
return false;
}
@@ -2555,6 +2580,7 @@ void ClimateStateResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_float(5, this->target_temperature_low);
buffer.encode_float(6, this->target_temperature_high);
buffer.encode_bool(7, this->away);
buffer.encode_enum<EnumClimateAction>(8, this->action);
}
void ClimateStateResponse::dump_to(std::string &out) const {
char buffer[64];
@@ -2591,6 +2617,10 @@ void ClimateStateResponse::dump_to(std::string &out) const {
out.append(" away: ");
out.append(YESNO(this->away));
out.append("\n");
out.append(" action: ");
out.append(proto_enum_to_string<EnumClimateAction>(this->action));
out.append("\n");
out.append("}");
}
bool ClimateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {

View File

@@ -49,6 +49,11 @@ enum EnumClimateMode : uint32_t {
CLIMATE_MODE_COOL = 2,
CLIMATE_MODE_HEAT = 3,
};
enum EnumClimateAction : uint32_t {
CLIMATE_ACTION_OFF = 0,
CLIMATE_ACTION_COOLING = 2,
CLIMATE_ACTION_HEATING = 3,
};
class HelloRequest : public ProtoMessage {
public:
std::string client_info{}; // NOLINT
@@ -638,6 +643,7 @@ class ListEntitiesClimateResponse : public ProtoMessage {
float visual_max_temperature{0.0f}; // NOLINT
float visual_temperature_step{0.0f}; // NOLINT
bool supports_away{false}; // NOLINT
bool supports_action{false}; // NOLINT
void encode(ProtoWriteBuffer buffer) const override;
void dump_to(std::string &out) const override;
@@ -655,6 +661,7 @@ class ClimateStateResponse : public ProtoMessage {
float target_temperature_low{0.0f}; // NOLINT
float target_temperature_high{0.0f}; // NOLINT
bool away{false}; // NOLINT
EnumClimateAction action{}; // NOLINT
void encode(ProtoWriteBuffer buffer) const override;
void dump_to(std::string &out) const override;