Use unique enum names for native API

Fixes https://github.com/esphome/issues/issues/617
This commit is contained in:
Otto Winter 2019-08-31 21:13:41 +02:00
parent 23ff8178a0
commit 4b0f203049
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
6 changed files with 87 additions and 86 deletions

View File

@ -189,7 +189,7 @@ bool APIConnection::send_cover_state(cover::Cover *cover) {
resp.position = cover->position; resp.position = cover->position;
if (traits.get_supports_tilt()) if (traits.get_supports_tilt())
resp.tilt = cover->tilt; resp.tilt = cover->tilt;
resp.current_operation = static_cast<CoverOperation>(cover->current_operation); resp.current_operation = static_cast<EnumCoverOperation>(cover->current_operation);
return this->send_cover_state_response(resp); return this->send_cover_state_response(resp);
} }
bool APIConnection::send_cover_info(cover::Cover *cover) { bool APIConnection::send_cover_info(cover::Cover *cover) {
@ -246,7 +246,7 @@ bool APIConnection::send_fan_state(fan::FanState *fan) {
if (traits.supports_oscillation()) if (traits.supports_oscillation())
resp.oscillating = fan->oscillating; resp.oscillating = fan->oscillating;
if (traits.supports_speed()) if (traits.supports_speed())
resp.speed = static_cast<FanSpeed>(fan->speed); resp.speed = static_cast<EnumFanSpeed>(fan->speed);
return this->send_fan_state_response(resp); return this->send_fan_state_response(resp);
} }
bool APIConnection::send_fan_info(fan::FanState *fan) { bool APIConnection::send_fan_info(fan::FanState *fan) {
@ -441,7 +441,7 @@ bool APIConnection::send_climate_state(climate::Climate *climate) {
auto traits = climate->get_traits(); auto traits = climate->get_traits();
ClimateStateResponse resp{}; ClimateStateResponse resp{};
resp.key = climate->get_object_id_hash(); resp.key = climate->get_object_id_hash();
resp.mode = static_cast<ClimateMode>(climate->mode); resp.mode = static_cast<EnumClimateMode>(climate->mode);
if (traits.get_supports_current_temperature()) if (traits.get_supports_current_temperature())
resp.current_temperature = climate->current_temperature; resp.current_temperature = climate->current_temperature;
if (traits.get_supports_two_point_target_temperature()) { if (traits.get_supports_two_point_target_temperature()) {
@ -466,7 +466,7 @@ bool APIConnection::send_climate_info(climate::Climate *climate) {
for (auto mode : {climate::CLIMATE_MODE_AUTO, climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_COOL, for (auto mode : {climate::CLIMATE_MODE_AUTO, climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_COOL,
climate::CLIMATE_MODE_HEAT}) { climate::CLIMATE_MODE_HEAT}) {
if (traits.supports_mode(mode)) if (traits.supports_mode(mode))
msg.supported_modes.push_back(static_cast<ClimateMode>(mode)); msg.supported_modes.push_back(static_cast<EnumClimateMode>(mode));
} }
msg.visual_min_temperature = traits.get_visual_min_temperature(); msg.visual_min_temperature = traits.get_visual_min_temperature();
msg.visual_max_temperature = traits.get_visual_max_temperature(); msg.visual_max_temperature = traits.get_visual_max_temperature();

View File

@ -4,7 +4,7 @@
namespace esphome { namespace esphome {
namespace api { namespace api {
template<> const char *proto_enum_to_string<LegacyCoverState>(LegacyCoverState value) { template<> const char *proto_enum_to_string<EnumLegacyCoverState>(EnumLegacyCoverState value) {
switch (value) { switch (value) {
case LEGACY_COVER_STATE_OPEN: case LEGACY_COVER_STATE_OPEN:
return "LEGACY_COVER_STATE_OPEN"; return "LEGACY_COVER_STATE_OPEN";
@ -14,7 +14,7 @@ template<> const char *proto_enum_to_string<LegacyCoverState>(LegacyCoverState v
return "UNKNOWN"; return "UNKNOWN";
} }
} }
template<> const char *proto_enum_to_string<CoverOperation>(CoverOperation value) { template<> const char *proto_enum_to_string<EnumCoverOperation>(EnumCoverOperation value) {
switch (value) { switch (value) {
case COVER_OPERATION_IDLE: case COVER_OPERATION_IDLE:
return "COVER_OPERATION_IDLE"; return "COVER_OPERATION_IDLE";
@ -26,7 +26,7 @@ template<> const char *proto_enum_to_string<CoverOperation>(CoverOperation value
return "UNKNOWN"; return "UNKNOWN";
} }
} }
template<> const char *proto_enum_to_string<LegacyCoverCommand>(LegacyCoverCommand value) { template<> const char *proto_enum_to_string<EnumLegacyCoverCommand>(EnumLegacyCoverCommand value) {
switch (value) { switch (value) {
case LEGACY_COVER_COMMAND_OPEN: case LEGACY_COVER_COMMAND_OPEN:
return "LEGACY_COVER_COMMAND_OPEN"; return "LEGACY_COVER_COMMAND_OPEN";
@ -38,7 +38,7 @@ template<> const char *proto_enum_to_string<LegacyCoverCommand>(LegacyCoverComma
return "UNKNOWN"; return "UNKNOWN";
} }
} }
template<> const char *proto_enum_to_string<FanSpeed>(FanSpeed value) { template<> const char *proto_enum_to_string<EnumFanSpeed>(EnumFanSpeed value) {
switch (value) { switch (value) {
case FAN_SPEED_LOW: case FAN_SPEED_LOW:
return "FAN_SPEED_LOW"; return "FAN_SPEED_LOW";
@ -50,7 +50,7 @@ template<> const char *proto_enum_to_string<FanSpeed>(FanSpeed value) {
return "UNKNOWN"; return "UNKNOWN";
} }
} }
template<> const char *proto_enum_to_string<LogLevel>(LogLevel value) { template<> const char *proto_enum_to_string<EnumLogLevel>(EnumLogLevel value) {
switch (value) { switch (value) {
case LOG_LEVEL_NONE: case LOG_LEVEL_NONE:
return "LOG_LEVEL_NONE"; return "LOG_LEVEL_NONE";
@ -70,7 +70,7 @@ template<> const char *proto_enum_to_string<LogLevel>(LogLevel value) {
return "UNKNOWN"; return "UNKNOWN";
} }
} }
template<> const char *proto_enum_to_string<ServiceArgType>(ServiceArgType value) { template<> const char *proto_enum_to_string<EnumServiceArgType>(EnumServiceArgType value) {
switch (value) { switch (value) {
case SERVICE_ARG_TYPE_BOOL: case SERVICE_ARG_TYPE_BOOL:
return "SERVICE_ARG_TYPE_BOOL"; return "SERVICE_ARG_TYPE_BOOL";
@ -92,7 +92,7 @@ template<> const char *proto_enum_to_string<ServiceArgType>(ServiceArgType value
return "UNKNOWN"; return "UNKNOWN";
} }
} }
template<> const char *proto_enum_to_string<ClimateMode>(ClimateMode value) { template<> const char *proto_enum_to_string<EnumClimateMode>(EnumClimateMode value) {
switch (value) { switch (value) {
case CLIMATE_MODE_OFF: case CLIMATE_MODE_OFF:
return "CLIMATE_MODE_OFF"; return "CLIMATE_MODE_OFF";
@ -523,11 +523,11 @@ void ListEntitiesCoverResponse::dump_to(std::string &out) const {
bool CoverStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { bool CoverStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
switch (field_id) { switch (field_id) {
case 2: { case 2: {
this->legacy_state = value.as_enum<LegacyCoverState>(); this->legacy_state = value.as_enum<EnumLegacyCoverState>();
return true; return true;
} }
case 5: { case 5: {
this->current_operation = value.as_enum<CoverOperation>(); this->current_operation = value.as_enum<EnumCoverOperation>();
return true; return true;
} }
default: default:
@ -554,10 +554,10 @@ bool CoverStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) {
} }
void CoverStateResponse::encode(ProtoWriteBuffer buffer) const { void CoverStateResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_fixed32(1, this->key); buffer.encode_fixed32(1, this->key);
buffer.encode_enum<LegacyCoverState>(2, this->legacy_state); buffer.encode_enum<EnumLegacyCoverState>(2, this->legacy_state);
buffer.encode_float(3, this->position); buffer.encode_float(3, this->position);
buffer.encode_float(4, this->tilt); buffer.encode_float(4, this->tilt);
buffer.encode_enum<CoverOperation>(5, this->current_operation); buffer.encode_enum<EnumCoverOperation>(5, this->current_operation);
} }
void CoverStateResponse::dump_to(std::string &out) const { void CoverStateResponse::dump_to(std::string &out) const {
char buffer[64]; char buffer[64];
@ -568,7 +568,7 @@ void CoverStateResponse::dump_to(std::string &out) const {
out.append("\n"); out.append("\n");
out.append(" legacy_state: "); out.append(" legacy_state: ");
out.append(proto_enum_to_string<LegacyCoverState>(this->legacy_state)); out.append(proto_enum_to_string<EnumLegacyCoverState>(this->legacy_state));
out.append("\n"); out.append("\n");
out.append(" position: "); out.append(" position: ");
@ -582,7 +582,7 @@ void CoverStateResponse::dump_to(std::string &out) const {
out.append("\n"); out.append("\n");
out.append(" current_operation: "); out.append(" current_operation: ");
out.append(proto_enum_to_string<CoverOperation>(this->current_operation)); out.append(proto_enum_to_string<EnumCoverOperation>(this->current_operation));
out.append("\n"); out.append("\n");
out.append("}"); out.append("}");
} }
@ -593,7 +593,7 @@ bool CoverCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
return true; return true;
} }
case 3: { case 3: {
this->legacy_command = value.as_enum<LegacyCoverCommand>(); this->legacy_command = value.as_enum<EnumLegacyCoverCommand>();
return true; return true;
} }
case 4: { case 4: {
@ -633,7 +633,7 @@ bool CoverCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) {
void CoverCommandRequest::encode(ProtoWriteBuffer buffer) const { void CoverCommandRequest::encode(ProtoWriteBuffer buffer) const {
buffer.encode_fixed32(1, this->key); buffer.encode_fixed32(1, this->key);
buffer.encode_bool(2, this->has_legacy_command); buffer.encode_bool(2, this->has_legacy_command);
buffer.encode_enum<LegacyCoverCommand>(3, this->legacy_command); buffer.encode_enum<EnumLegacyCoverCommand>(3, this->legacy_command);
buffer.encode_bool(4, this->has_position); buffer.encode_bool(4, this->has_position);
buffer.encode_float(5, this->position); buffer.encode_float(5, this->position);
buffer.encode_bool(6, this->has_tilt); buffer.encode_bool(6, this->has_tilt);
@ -653,7 +653,7 @@ void CoverCommandRequest::dump_to(std::string &out) const {
out.append("\n"); out.append("\n");
out.append(" legacy_command: "); out.append(" legacy_command: ");
out.append(proto_enum_to_string<LegacyCoverCommand>(this->legacy_command)); out.append(proto_enum_to_string<EnumLegacyCoverCommand>(this->legacy_command));
out.append("\n"); out.append("\n");
out.append(" has_position: "); out.append(" has_position: ");
@ -769,7 +769,7 @@ bool FanStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
return true; return true;
} }
case 4: { case 4: {
this->speed = value.as_enum<FanSpeed>(); this->speed = value.as_enum<EnumFanSpeed>();
return true; return true;
} }
default: default:
@ -790,7 +790,7 @@ void FanStateResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_fixed32(1, this->key); buffer.encode_fixed32(1, this->key);
buffer.encode_bool(2, this->state); buffer.encode_bool(2, this->state);
buffer.encode_bool(3, this->oscillating); buffer.encode_bool(3, this->oscillating);
buffer.encode_enum<FanSpeed>(4, this->speed); buffer.encode_enum<EnumFanSpeed>(4, this->speed);
} }
void FanStateResponse::dump_to(std::string &out) const { void FanStateResponse::dump_to(std::string &out) const {
char buffer[64]; char buffer[64];
@ -809,7 +809,7 @@ void FanStateResponse::dump_to(std::string &out) const {
out.append("\n"); out.append("\n");
out.append(" speed: "); out.append(" speed: ");
out.append(proto_enum_to_string<FanSpeed>(this->speed)); out.append(proto_enum_to_string<EnumFanSpeed>(this->speed));
out.append("\n"); out.append("\n");
out.append("}"); out.append("}");
} }
@ -828,7 +828,7 @@ bool FanCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
return true; return true;
} }
case 5: { case 5: {
this->speed = value.as_enum<FanSpeed>(); this->speed = value.as_enum<EnumFanSpeed>();
return true; return true;
} }
case 6: { case 6: {
@ -858,7 +858,7 @@ void FanCommandRequest::encode(ProtoWriteBuffer buffer) const {
buffer.encode_bool(2, this->has_state); buffer.encode_bool(2, this->has_state);
buffer.encode_bool(3, this->state); buffer.encode_bool(3, this->state);
buffer.encode_bool(4, this->has_speed); buffer.encode_bool(4, this->has_speed);
buffer.encode_enum<FanSpeed>(5, this->speed); buffer.encode_enum<EnumFanSpeed>(5, this->speed);
buffer.encode_bool(6, this->has_oscillating); buffer.encode_bool(6, this->has_oscillating);
buffer.encode_bool(7, this->oscillating); buffer.encode_bool(7, this->oscillating);
} }
@ -883,7 +883,7 @@ void FanCommandRequest::dump_to(std::string &out) const {
out.append("\n"); out.append("\n");
out.append(" speed: "); out.append(" speed: ");
out.append(proto_enum_to_string<FanSpeed>(this->speed)); out.append(proto_enum_to_string<EnumFanSpeed>(this->speed));
out.append("\n"); out.append("\n");
out.append(" has_oscillating: "); out.append(" has_oscillating: ");
@ -1719,7 +1719,7 @@ void TextSensorStateResponse::dump_to(std::string &out) const {
bool SubscribeLogsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { bool SubscribeLogsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
switch (field_id) { switch (field_id) {
case 1: { case 1: {
this->level = value.as_enum<LogLevel>(); this->level = value.as_enum<EnumLogLevel>();
return true; return true;
} }
case 2: { case 2: {
@ -1731,14 +1731,14 @@ bool SubscribeLogsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
} }
} }
void SubscribeLogsRequest::encode(ProtoWriteBuffer buffer) const { void SubscribeLogsRequest::encode(ProtoWriteBuffer buffer) const {
buffer.encode_enum<LogLevel>(1, this->level); buffer.encode_enum<EnumLogLevel>(1, this->level);
buffer.encode_bool(2, this->dump_config); buffer.encode_bool(2, this->dump_config);
} }
void SubscribeLogsRequest::dump_to(std::string &out) const { void SubscribeLogsRequest::dump_to(std::string &out) const {
char buffer[64]; char buffer[64];
out.append("SubscribeLogsRequest {\n"); out.append("SubscribeLogsRequest {\n");
out.append(" level: "); out.append(" level: ");
out.append(proto_enum_to_string<LogLevel>(this->level)); out.append(proto_enum_to_string<EnumLogLevel>(this->level));
out.append("\n"); out.append("\n");
out.append(" dump_config: "); out.append(" dump_config: ");
@ -1749,7 +1749,7 @@ void SubscribeLogsRequest::dump_to(std::string &out) const {
bool SubscribeLogsResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { bool SubscribeLogsResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
switch (field_id) { switch (field_id) {
case 1: { case 1: {
this->level = value.as_enum<LogLevel>(); this->level = value.as_enum<EnumLogLevel>();
return true; return true;
} }
case 4: { case 4: {
@ -1775,7 +1775,7 @@ bool SubscribeLogsResponse::decode_length(uint32_t field_id, ProtoLengthDelimite
} }
} }
void SubscribeLogsResponse::encode(ProtoWriteBuffer buffer) const { void SubscribeLogsResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_enum<LogLevel>(1, this->level); buffer.encode_enum<EnumLogLevel>(1, this->level);
buffer.encode_string(2, this->tag); buffer.encode_string(2, this->tag);
buffer.encode_string(3, this->message); buffer.encode_string(3, this->message);
buffer.encode_bool(4, this->send_failed); buffer.encode_bool(4, this->send_failed);
@ -1784,7 +1784,7 @@ void SubscribeLogsResponse::dump_to(std::string &out) const {
char buffer[64]; char buffer[64];
out.append("SubscribeLogsResponse {\n"); out.append("SubscribeLogsResponse {\n");
out.append(" level: "); out.append(" level: ");
out.append(proto_enum_to_string<LogLevel>(this->level)); out.append(proto_enum_to_string<EnumLogLevel>(this->level));
out.append("\n"); out.append("\n");
out.append(" tag: "); out.append(" tag: ");
@ -1989,7 +1989,7 @@ void GetTimeResponse::dump_to(std::string &out) const {
bool ListEntitiesServicesArgument::decode_varint(uint32_t field_id, ProtoVarInt value) { bool ListEntitiesServicesArgument::decode_varint(uint32_t field_id, ProtoVarInt value) {
switch (field_id) { switch (field_id) {
case 2: { case 2: {
this->type = value.as_enum<ServiceArgType>(); this->type = value.as_enum<EnumServiceArgType>();
return true; return true;
} }
default: default:
@ -2008,7 +2008,7 @@ bool ListEntitiesServicesArgument::decode_length(uint32_t field_id, ProtoLengthD
} }
void ListEntitiesServicesArgument::encode(ProtoWriteBuffer buffer) const { void ListEntitiesServicesArgument::encode(ProtoWriteBuffer buffer) const {
buffer.encode_string(1, this->name); buffer.encode_string(1, this->name);
buffer.encode_enum<ServiceArgType>(2, this->type); buffer.encode_enum<EnumServiceArgType>(2, this->type);
} }
void ListEntitiesServicesArgument::dump_to(std::string &out) const { void ListEntitiesServicesArgument::dump_to(std::string &out) const {
char buffer[64]; char buffer[64];
@ -2018,7 +2018,7 @@ void ListEntitiesServicesArgument::dump_to(std::string &out) const {
out.append("\n"); out.append("\n");
out.append(" type: "); out.append(" type: ");
out.append(proto_enum_to_string<ServiceArgType>(this->type)); out.append(proto_enum_to_string<EnumServiceArgType>(this->type));
out.append("\n"); out.append("\n");
out.append("}"); out.append("}");
} }
@ -2387,7 +2387,7 @@ bool ListEntitiesClimateResponse::decode_varint(uint32_t field_id, ProtoVarInt v
return true; return true;
} }
case 7: { case 7: {
this->supported_modes.push_back(value.as_enum<ClimateMode>()); this->supported_modes.push_back(value.as_enum<EnumClimateMode>());
return true; return true;
} }
case 11: { case 11: {
@ -2446,7 +2446,7 @@ void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_bool(5, this->supports_current_temperature); buffer.encode_bool(5, this->supports_current_temperature);
buffer.encode_bool(6, this->supports_two_point_target_temperature); buffer.encode_bool(6, this->supports_two_point_target_temperature);
for (auto &it : this->supported_modes) { for (auto &it : this->supported_modes) {
buffer.encode_enum<ClimateMode>(7, it, true); buffer.encode_enum<EnumClimateMode>(7, it, true);
} }
buffer.encode_float(8, this->visual_min_temperature); buffer.encode_float(8, this->visual_min_temperature);
buffer.encode_float(9, this->visual_max_temperature); buffer.encode_float(9, this->visual_max_temperature);
@ -2483,7 +2483,7 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const {
for (const auto &it : this->supported_modes) { for (const auto &it : this->supported_modes) {
out.append(" supported_modes: "); out.append(" supported_modes: ");
out.append(proto_enum_to_string<ClimateMode>(it)); out.append(proto_enum_to_string<EnumClimateMode>(it));
out.append("\n"); out.append("\n");
} }
@ -2510,7 +2510,7 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const {
bool ClimateStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { bool ClimateStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
switch (field_id) { switch (field_id) {
case 2: { case 2: {
this->mode = value.as_enum<ClimateMode>(); this->mode = value.as_enum<EnumClimateMode>();
return true; return true;
} }
case 7: { case 7: {
@ -2549,7 +2549,7 @@ bool ClimateStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) {
} }
void ClimateStateResponse::encode(ProtoWriteBuffer buffer) const { void ClimateStateResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_fixed32(1, this->key); buffer.encode_fixed32(1, this->key);
buffer.encode_enum<ClimateMode>(2, this->mode); buffer.encode_enum<EnumClimateMode>(2, this->mode);
buffer.encode_float(3, this->current_temperature); buffer.encode_float(3, this->current_temperature);
buffer.encode_float(4, this->target_temperature); buffer.encode_float(4, this->target_temperature);
buffer.encode_float(5, this->target_temperature_low); buffer.encode_float(5, this->target_temperature_low);
@ -2565,7 +2565,7 @@ void ClimateStateResponse::dump_to(std::string &out) const {
out.append("\n"); out.append("\n");
out.append(" mode: "); out.append(" mode: ");
out.append(proto_enum_to_string<ClimateMode>(this->mode)); out.append(proto_enum_to_string<EnumClimateMode>(this->mode));
out.append("\n"); out.append("\n");
out.append(" current_temperature: "); out.append(" current_temperature: ");
@ -2600,7 +2600,7 @@ bool ClimateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value)
return true; return true;
} }
case 3: { case 3: {
this->mode = value.as_enum<ClimateMode>(); this->mode = value.as_enum<EnumClimateMode>();
return true; return true;
} }
case 4: { case 4: {
@ -2652,7 +2652,7 @@ bool ClimateCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) {
void ClimateCommandRequest::encode(ProtoWriteBuffer buffer) const { void ClimateCommandRequest::encode(ProtoWriteBuffer buffer) const {
buffer.encode_fixed32(1, this->key); buffer.encode_fixed32(1, this->key);
buffer.encode_bool(2, this->has_mode); buffer.encode_bool(2, this->has_mode);
buffer.encode_enum<ClimateMode>(3, this->mode); buffer.encode_enum<EnumClimateMode>(3, this->mode);
buffer.encode_bool(4, this->has_target_temperature); buffer.encode_bool(4, this->has_target_temperature);
buffer.encode_float(5, this->target_temperature); buffer.encode_float(5, this->target_temperature);
buffer.encode_bool(6, this->has_target_temperature_low); buffer.encode_bool(6, this->has_target_temperature_low);
@ -2675,7 +2675,7 @@ void ClimateCommandRequest::dump_to(std::string &out) const {
out.append("\n"); out.append("\n");
out.append(" mode: "); out.append(" mode: ");
out.append(proto_enum_to_string<ClimateMode>(this->mode)); out.append(proto_enum_to_string<EnumClimateMode>(this->mode));
out.append("\n"); out.append("\n");
out.append(" has_target_temperature: "); out.append(" has_target_temperature: ");

View File

@ -5,26 +5,26 @@
namespace esphome { namespace esphome {
namespace api { namespace api {
enum LegacyCoverState : uint32_t { enum EnumLegacyCoverState : uint32_t {
LEGACY_COVER_STATE_OPEN = 0, LEGACY_COVER_STATE_OPEN = 0,
LEGACY_COVER_STATE_CLOSED = 1, LEGACY_COVER_STATE_CLOSED = 1,
}; };
enum CoverOperation : uint32_t { enum EnumCoverOperation : uint32_t {
COVER_OPERATION_IDLE = 0, COVER_OPERATION_IDLE = 0,
COVER_OPERATION_IS_OPENING = 1, COVER_OPERATION_IS_OPENING = 1,
COVER_OPERATION_IS_CLOSING = 2, COVER_OPERATION_IS_CLOSING = 2,
}; };
enum LegacyCoverCommand : uint32_t { enum EnumLegacyCoverCommand : uint32_t {
LEGACY_COVER_COMMAND_OPEN = 0, LEGACY_COVER_COMMAND_OPEN = 0,
LEGACY_COVER_COMMAND_CLOSE = 1, LEGACY_COVER_COMMAND_CLOSE = 1,
LEGACY_COVER_COMMAND_STOP = 2, LEGACY_COVER_COMMAND_STOP = 2,
}; };
enum FanSpeed : uint32_t { enum EnumFanSpeed : uint32_t {
FAN_SPEED_LOW = 0, FAN_SPEED_LOW = 0,
FAN_SPEED_MEDIUM = 1, FAN_SPEED_MEDIUM = 1,
FAN_SPEED_HIGH = 2, FAN_SPEED_HIGH = 2,
}; };
enum LogLevel : uint32_t { enum EnumLogLevel : uint32_t {
LOG_LEVEL_NONE = 0, LOG_LEVEL_NONE = 0,
LOG_LEVEL_ERROR = 1, LOG_LEVEL_ERROR = 1,
LOG_LEVEL_WARN = 2, LOG_LEVEL_WARN = 2,
@ -33,7 +33,7 @@ enum LogLevel : uint32_t {
LOG_LEVEL_VERBOSE = 5, LOG_LEVEL_VERBOSE = 5,
LOG_LEVEL_VERY_VERBOSE = 6, LOG_LEVEL_VERY_VERBOSE = 6,
}; };
enum ServiceArgType : uint32_t { enum EnumServiceArgType : uint32_t {
SERVICE_ARG_TYPE_BOOL = 0, SERVICE_ARG_TYPE_BOOL = 0,
SERVICE_ARG_TYPE_INT = 1, SERVICE_ARG_TYPE_INT = 1,
SERVICE_ARG_TYPE_FLOAT = 2, SERVICE_ARG_TYPE_FLOAT = 2,
@ -43,7 +43,7 @@ enum ServiceArgType : uint32_t {
SERVICE_ARG_TYPE_FLOAT_ARRAY = 6, SERVICE_ARG_TYPE_FLOAT_ARRAY = 6,
SERVICE_ARG_TYPE_STRING_ARRAY = 7, SERVICE_ARG_TYPE_STRING_ARRAY = 7,
}; };
enum ClimateMode : uint32_t { enum EnumClimateMode : uint32_t {
CLIMATE_MODE_OFF = 0, CLIMATE_MODE_OFF = 0,
CLIMATE_MODE_AUTO = 1, CLIMATE_MODE_AUTO = 1,
CLIMATE_MODE_COOL = 2, CLIMATE_MODE_COOL = 2,
@ -207,11 +207,11 @@ class ListEntitiesCoverResponse : public ProtoMessage {
}; };
class CoverStateResponse : public ProtoMessage { class CoverStateResponse : public ProtoMessage {
public: public:
uint32_t key{0}; // NOLINT uint32_t key{0}; // NOLINT
LegacyCoverState legacy_state{}; // NOLINT EnumLegacyCoverState legacy_state{}; // NOLINT
float position{0.0f}; // NOLINT float position{0.0f}; // NOLINT
float tilt{0.0f}; // NOLINT float tilt{0.0f}; // NOLINT
CoverOperation current_operation{}; // NOLINT EnumCoverOperation current_operation{}; // NOLINT
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -221,14 +221,14 @@ class CoverStateResponse : public ProtoMessage {
}; };
class CoverCommandRequest : public ProtoMessage { class CoverCommandRequest : public ProtoMessage {
public: public:
uint32_t key{0}; // NOLINT uint32_t key{0}; // NOLINT
bool has_legacy_command{false}; // NOLINT bool has_legacy_command{false}; // NOLINT
LegacyCoverCommand legacy_command{}; // NOLINT EnumLegacyCoverCommand legacy_command{}; // NOLINT
bool has_position{false}; // NOLINT bool has_position{false}; // NOLINT
float position{0.0f}; // NOLINT float position{0.0f}; // NOLINT
bool has_tilt{false}; // NOLINT bool has_tilt{false}; // NOLINT
float tilt{0.0f}; // NOLINT float tilt{0.0f}; // NOLINT
bool stop{false}; // NOLINT bool stop{false}; // NOLINT
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -257,7 +257,7 @@ class FanStateResponse : public ProtoMessage {
uint32_t key{0}; // NOLINT uint32_t key{0}; // NOLINT
bool state{false}; // NOLINT bool state{false}; // NOLINT
bool oscillating{false}; // NOLINT bool oscillating{false}; // NOLINT
FanSpeed speed{}; // NOLINT EnumFanSpeed speed{}; // NOLINT
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -271,7 +271,7 @@ class FanCommandRequest : public ProtoMessage {
bool has_state{false}; // NOLINT bool has_state{false}; // NOLINT
bool state{false}; // NOLINT bool state{false}; // NOLINT
bool has_speed{false}; // NOLINT bool has_speed{false}; // NOLINT
FanSpeed speed{}; // NOLINT EnumFanSpeed speed{}; // NOLINT
bool has_oscillating{false}; // NOLINT bool has_oscillating{false}; // NOLINT
bool oscillating{false}; // NOLINT bool oscillating{false}; // NOLINT
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
@ -442,7 +442,7 @@ class TextSensorStateResponse : public ProtoMessage {
}; };
class SubscribeLogsRequest : public ProtoMessage { class SubscribeLogsRequest : public ProtoMessage {
public: public:
LogLevel level{}; // NOLINT EnumLogLevel level{}; // NOLINT
bool dump_config{false}; // NOLINT bool dump_config{false}; // NOLINT
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -452,7 +452,7 @@ class SubscribeLogsRequest : public ProtoMessage {
}; };
class SubscribeLogsResponse : public ProtoMessage { class SubscribeLogsResponse : public ProtoMessage {
public: public:
LogLevel level{}; // NOLINT EnumLogLevel level{}; // NOLINT
std::string tag{}; // NOLINT std::string tag{}; // NOLINT
std::string message{}; // NOLINT std::string message{}; // NOLINT
bool send_failed{false}; // NOLINT bool send_failed{false}; // NOLINT
@ -538,8 +538,8 @@ class GetTimeResponse : public ProtoMessage {
}; };
class ListEntitiesServicesArgument : public ProtoMessage { class ListEntitiesServicesArgument : public ProtoMessage {
public: public:
std::string name{}; // NOLINT std::string name{}; // NOLINT
ServiceArgType type{}; // NOLINT EnumServiceArgType type{}; // NOLINT
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -633,7 +633,7 @@ class ListEntitiesClimateResponse : public ProtoMessage {
std::string unique_id{}; // NOLINT std::string unique_id{}; // NOLINT
bool supports_current_temperature{false}; // NOLINT bool supports_current_temperature{false}; // NOLINT
bool supports_two_point_target_temperature{false}; // NOLINT bool supports_two_point_target_temperature{false}; // NOLINT
std::vector<ClimateMode> supported_modes{}; // NOLINT std::vector<EnumClimateMode> supported_modes{}; // NOLINT
float visual_min_temperature{0.0f}; // NOLINT float visual_min_temperature{0.0f}; // NOLINT
float visual_max_temperature{0.0f}; // NOLINT float visual_max_temperature{0.0f}; // NOLINT
float visual_temperature_step{0.0f}; // NOLINT float visual_temperature_step{0.0f}; // NOLINT
@ -649,7 +649,7 @@ class ListEntitiesClimateResponse : public ProtoMessage {
class ClimateStateResponse : public ProtoMessage { class ClimateStateResponse : public ProtoMessage {
public: public:
uint32_t key{0}; // NOLINT uint32_t key{0}; // NOLINT
ClimateMode mode{}; // NOLINT EnumClimateMode mode{}; // NOLINT
float current_temperature{0.0f}; // NOLINT float current_temperature{0.0f}; // NOLINT
float target_temperature{0.0f}; // NOLINT float target_temperature{0.0f}; // NOLINT
float target_temperature_low{0.0f}; // NOLINT float target_temperature_low{0.0f}; // NOLINT
@ -666,7 +666,7 @@ class ClimateCommandRequest : public ProtoMessage {
public: public:
uint32_t key{0}; // NOLINT uint32_t key{0}; // NOLINT
bool has_mode{false}; // NOLINT bool has_mode{false}; // NOLINT
ClimateMode mode{}; // NOLINT EnumClimateMode mode{}; // NOLINT
bool has_target_temperature{false}; // NOLINT bool has_target_temperature{false}; // NOLINT
float target_temperature{0.0f}; // NOLINT float target_temperature{0.0f}; // NOLINT
bool has_target_temperature_low{false}; // NOLINT bool has_target_temperature_low{false}; // NOLINT

View File

@ -25,14 +25,14 @@ template<> std::vector<std::string> get_execute_arg_value<std::vector<std::strin
return arg.string_array; return arg.string_array;
} }
template<> ServiceArgType to_service_arg_type<bool>() { return SERVICE_ARG_TYPE_BOOL; } template<> EnumServiceArgType to_service_arg_type<bool>() { return SERVICE_ARG_TYPE_BOOL; }
template<> ServiceArgType to_service_arg_type<int>() { return SERVICE_ARG_TYPE_INT; } template<> EnumServiceArgType to_service_arg_type<int>() { return SERVICE_ARG_TYPE_INT; }
template<> ServiceArgType to_service_arg_type<float>() { return SERVICE_ARG_TYPE_FLOAT; } template<> EnumServiceArgType to_service_arg_type<float>() { return SERVICE_ARG_TYPE_FLOAT; }
template<> ServiceArgType to_service_arg_type<std::string>() { return SERVICE_ARG_TYPE_STRING; } template<> EnumServiceArgType to_service_arg_type<std::string>() { return SERVICE_ARG_TYPE_STRING; }
template<> ServiceArgType to_service_arg_type<std::vector<bool>>() { return SERVICE_ARG_TYPE_BOOL_ARRAY; } template<> EnumServiceArgType to_service_arg_type<std::vector<bool>>() { return SERVICE_ARG_TYPE_BOOL_ARRAY; }
template<> ServiceArgType to_service_arg_type<std::vector<int>>() { return SERVICE_ARG_TYPE_INT_ARRAY; } template<> EnumServiceArgType to_service_arg_type<std::vector<int>>() { return SERVICE_ARG_TYPE_INT_ARRAY; }
template<> ServiceArgType to_service_arg_type<std::vector<float>>() { return SERVICE_ARG_TYPE_FLOAT_ARRAY; } template<> EnumServiceArgType to_service_arg_type<std::vector<float>>() { return SERVICE_ARG_TYPE_FLOAT_ARRAY; }
template<> ServiceArgType to_service_arg_type<std::vector<std::string>>() { return SERVICE_ARG_TYPE_STRING_ARRAY; } template<> EnumServiceArgType to_service_arg_type<std::vector<std::string>>() { return SERVICE_ARG_TYPE_STRING_ARRAY; }
} // namespace api } // namespace api
} // namespace esphome } // namespace esphome

View File

@ -16,7 +16,7 @@ class UserServiceDescriptor {
template<typename T> T get_execute_arg_value(const ExecuteServiceArgument &arg); template<typename T> T get_execute_arg_value(const ExecuteServiceArgument &arg);
template<typename T> ServiceArgType to_service_arg_type(); template<typename T> EnumServiceArgType to_service_arg_type();
template<typename... Ts> class UserServiceBase : public UserServiceDescriptor { template<typename... Ts> class UserServiceBase : public UserServiceDescriptor {
public: public:
@ -29,7 +29,7 @@ template<typename... Ts> class UserServiceBase : public UserServiceDescriptor {
ListEntitiesServicesResponse msg; ListEntitiesServicesResponse msg;
msg.name = this->name_; msg.name = this->name_;
msg.key = this->key_; msg.key = this->key_;
std::array<ServiceArgType, sizeof...(Ts)> arg_types = {to_service_arg_type<Ts>()...}; std::array<EnumServiceArgType, sizeof...(Ts)> arg_types = {to_service_arg_type<Ts>()...};
for (int i = 0; i < sizeof...(Ts); i++) { for (int i = 0; i < sizeof...(Ts); i++) {
ListEntitiesServicesArgument arg; ListEntitiesServicesArgument arg;
arg.type = arg_types[i]; arg.type = arg_types[i];

View File

@ -344,7 +344,7 @@ class UInt32Type(TypeInfo):
class EnumType(TypeInfo): class EnumType(TypeInfo):
@property @property
def cpp_type(self): def cpp_type(self):
return self._field.type_name[1:] return "Enum" + self._field.type_name[1:]
@property @property
def decode_varint(self): def decode_varint(self):
@ -497,13 +497,14 @@ class RepeatedTypeInfo(TypeInfo):
def build_enum_type(desc): def build_enum_type(desc):
out = f"enum {desc.name} : uint32_t {{\n" name = "Enum" + desc.name
out = f"enum {name} : uint32_t {{\n"
for v in desc.value: for v in desc.value:
out += f' {v.name} = {v.number},\n' out += f' {v.name} = {v.number},\n'
out += '};\n' out += '};\n'
cpp = f"template<>\n" cpp = f"template<>\n"
cpp += f"const char *proto_enum_to_string<{desc.name}>({desc.name} value) {{\n" cpp += f"const char *proto_enum_to_string<{name}>({name} value) {{\n"
cpp += f" switch (value) {{\n" cpp += f" switch (value) {{\n"
for v in desc.value: for v in desc.value:
cpp += f' case {v.name}: return "{v.name}";\n' cpp += f' case {v.name}: return "{v.name}";\n'