mirror of
https://github.com/esphome/esphome.git
synced 2025-09-04 20:32:21 +01:00
Color mode implementation (#2012)
This commit is contained in:
@@ -62,6 +62,32 @@ template<> const char *proto_enum_to_string<enums::FanDirection>(enums::FanDirec
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
template<> const char *proto_enum_to_string<enums::ColorMode>(enums::ColorMode value) {
|
||||
switch (value) {
|
||||
case enums::COLOR_MODE_UNKNOWN:
|
||||
return "COLOR_MODE_UNKNOWN";
|
||||
case enums::COLOR_MODE_ON_OFF:
|
||||
return "COLOR_MODE_ON_OFF";
|
||||
case enums::COLOR_MODE_BRIGHTNESS:
|
||||
return "COLOR_MODE_BRIGHTNESS";
|
||||
case enums::COLOR_MODE_WHITE:
|
||||
return "COLOR_MODE_WHITE";
|
||||
case enums::COLOR_MODE_COLOR_TEMPERATURE:
|
||||
return "COLOR_MODE_COLOR_TEMPERATURE";
|
||||
case enums::COLOR_MODE_COLD_WARM_WHITE:
|
||||
return "COLOR_MODE_COLD_WARM_WHITE";
|
||||
case enums::COLOR_MODE_RGB:
|
||||
return "COLOR_MODE_RGB";
|
||||
case enums::COLOR_MODE_RGB_WHITE:
|
||||
return "COLOR_MODE_RGB_WHITE";
|
||||
case enums::COLOR_MODE_RGB_COLOR_TEMPERATURE:
|
||||
return "COLOR_MODE_RGB_COLOR_TEMPERATURE";
|
||||
case enums::COLOR_MODE_RGB_COLD_WARM_WHITE:
|
||||
return "COLOR_MODE_RGB_COLD_WARM_WHITE";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
template<> const char *proto_enum_to_string<enums::SensorStateClass>(enums::SensorStateClass value) {
|
||||
switch (value) {
|
||||
case enums::STATE_CLASS_NONE:
|
||||
@@ -1117,20 +1143,24 @@ void FanCommandRequest::dump_to(std::string &out) const {
|
||||
}
|
||||
bool ListEntitiesLightResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||
switch (field_id) {
|
||||
case 12: {
|
||||
this->supported_color_modes.push_back(value.as_enum<enums::ColorMode>());
|
||||
return true;
|
||||
}
|
||||
case 5: {
|
||||
this->supports_brightness = value.as_bool();
|
||||
this->legacy_supports_brightness = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 6: {
|
||||
this->supports_rgb = value.as_bool();
|
||||
this->legacy_supports_rgb = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 7: {
|
||||
this->supports_white_value = value.as_bool();
|
||||
this->legacy_supports_white_value = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 8: {
|
||||
this->supports_color_temperature = value.as_bool();
|
||||
this->legacy_supports_color_temperature = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
@@ -1182,10 +1212,13 @@ void ListEntitiesLightResponse::encode(ProtoWriteBuffer buffer) const {
|
||||
buffer.encode_fixed32(2, this->key);
|
||||
buffer.encode_string(3, this->name);
|
||||
buffer.encode_string(4, this->unique_id);
|
||||
buffer.encode_bool(5, this->supports_brightness);
|
||||
buffer.encode_bool(6, this->supports_rgb);
|
||||
buffer.encode_bool(7, this->supports_white_value);
|
||||
buffer.encode_bool(8, this->supports_color_temperature);
|
||||
for (auto &it : this->supported_color_modes) {
|
||||
buffer.encode_enum<enums::ColorMode>(12, it, true);
|
||||
}
|
||||
buffer.encode_bool(5, this->legacy_supports_brightness);
|
||||
buffer.encode_bool(6, this->legacy_supports_rgb);
|
||||
buffer.encode_bool(7, this->legacy_supports_white_value);
|
||||
buffer.encode_bool(8, this->legacy_supports_color_temperature);
|
||||
buffer.encode_float(9, this->min_mireds);
|
||||
buffer.encode_float(10, this->max_mireds);
|
||||
for (auto &it : this->effects) {
|
||||
@@ -1212,20 +1245,26 @@ void ListEntitiesLightResponse::dump_to(std::string &out) const {
|
||||
out.append("'").append(this->unique_id).append("'");
|
||||
out.append("\n");
|
||||
|
||||
out.append(" supports_brightness: ");
|
||||
out.append(YESNO(this->supports_brightness));
|
||||
for (const auto &it : this->supported_color_modes) {
|
||||
out.append(" supported_color_modes: ");
|
||||
out.append(proto_enum_to_string<enums::ColorMode>(it));
|
||||
out.append("\n");
|
||||
}
|
||||
|
||||
out.append(" legacy_supports_brightness: ");
|
||||
out.append(YESNO(this->legacy_supports_brightness));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" supports_rgb: ");
|
||||
out.append(YESNO(this->supports_rgb));
|
||||
out.append(" legacy_supports_rgb: ");
|
||||
out.append(YESNO(this->legacy_supports_rgb));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" supports_white_value: ");
|
||||
out.append(YESNO(this->supports_white_value));
|
||||
out.append(" legacy_supports_white_value: ");
|
||||
out.append(YESNO(this->legacy_supports_white_value));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" supports_color_temperature: ");
|
||||
out.append(YESNO(this->supports_color_temperature));
|
||||
out.append(" legacy_supports_color_temperature: ");
|
||||
out.append(YESNO(this->legacy_supports_color_temperature));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" min_mireds: ");
|
||||
@@ -1251,6 +1290,10 @@ bool LightStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||
this->state = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 11: {
|
||||
this->color_mode = value.as_enum<enums::ColorMode>();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -1299,6 +1342,14 @@ bool LightStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) {
|
||||
this->color_temperature = value.as_float();
|
||||
return true;
|
||||
}
|
||||
case 12: {
|
||||
this->cold_white = value.as_float();
|
||||
return true;
|
||||
}
|
||||
case 13: {
|
||||
this->warm_white = value.as_float();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -1307,12 +1358,15 @@ void LightStateResponse::encode(ProtoWriteBuffer buffer) const {
|
||||
buffer.encode_fixed32(1, this->key);
|
||||
buffer.encode_bool(2, this->state);
|
||||
buffer.encode_float(3, this->brightness);
|
||||
buffer.encode_enum<enums::ColorMode>(11, this->color_mode);
|
||||
buffer.encode_float(10, this->color_brightness);
|
||||
buffer.encode_float(4, this->red);
|
||||
buffer.encode_float(5, this->green);
|
||||
buffer.encode_float(6, this->blue);
|
||||
buffer.encode_float(7, this->white);
|
||||
buffer.encode_float(8, this->color_temperature);
|
||||
buffer.encode_float(12, this->cold_white);
|
||||
buffer.encode_float(13, this->warm_white);
|
||||
buffer.encode_string(9, this->effect);
|
||||
}
|
||||
void LightStateResponse::dump_to(std::string &out) const {
|
||||
@@ -1332,6 +1386,10 @@ void LightStateResponse::dump_to(std::string &out) const {
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" color_mode: ");
|
||||
out.append(proto_enum_to_string<enums::ColorMode>(this->color_mode));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" color_brightness: ");
|
||||
sprintf(buffer, "%g", this->color_brightness);
|
||||
out.append(buffer);
|
||||
@@ -1362,6 +1420,16 @@ void LightStateResponse::dump_to(std::string &out) const {
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" cold_white: ");
|
||||
sprintf(buffer, "%g", this->cold_white);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" warm_white: ");
|
||||
sprintf(buffer, "%g", this->warm_white);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" effect: ");
|
||||
out.append("'").append(this->effect).append("'");
|
||||
out.append("\n");
|
||||
@@ -1381,6 +1449,14 @@ bool LightCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||
this->has_brightness = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 22: {
|
||||
this->has_color_mode = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 23: {
|
||||
this->color_mode = value.as_enum<enums::ColorMode>();
|
||||
return true;
|
||||
}
|
||||
case 20: {
|
||||
this->has_color_brightness = value.as_bool();
|
||||
return true;
|
||||
@@ -1397,6 +1473,14 @@ bool LightCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||
this->has_color_temperature = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 24: {
|
||||
this->has_cold_white = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 26: {
|
||||
this->has_warm_white = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 14: {
|
||||
this->has_transition_length = value.as_bool();
|
||||
return true;
|
||||
@@ -1465,6 +1549,14 @@ bool LightCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) {
|
||||
this->color_temperature = value.as_float();
|
||||
return true;
|
||||
}
|
||||
case 25: {
|
||||
this->cold_white = value.as_float();
|
||||
return true;
|
||||
}
|
||||
case 27: {
|
||||
this->warm_white = value.as_float();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -1475,6 +1567,8 @@ void LightCommandRequest::encode(ProtoWriteBuffer buffer) const {
|
||||
buffer.encode_bool(3, this->state);
|
||||
buffer.encode_bool(4, this->has_brightness);
|
||||
buffer.encode_float(5, this->brightness);
|
||||
buffer.encode_bool(22, this->has_color_mode);
|
||||
buffer.encode_enum<enums::ColorMode>(23, this->color_mode);
|
||||
buffer.encode_bool(20, this->has_color_brightness);
|
||||
buffer.encode_float(21, this->color_brightness);
|
||||
buffer.encode_bool(6, this->has_rgb);
|
||||
@@ -1485,6 +1579,10 @@ void LightCommandRequest::encode(ProtoWriteBuffer buffer) const {
|
||||
buffer.encode_float(11, this->white);
|
||||
buffer.encode_bool(12, this->has_color_temperature);
|
||||
buffer.encode_float(13, this->color_temperature);
|
||||
buffer.encode_bool(24, this->has_cold_white);
|
||||
buffer.encode_float(25, this->cold_white);
|
||||
buffer.encode_bool(26, this->has_warm_white);
|
||||
buffer.encode_float(27, this->warm_white);
|
||||
buffer.encode_bool(14, this->has_transition_length);
|
||||
buffer.encode_uint32(15, this->transition_length);
|
||||
buffer.encode_bool(16, this->has_flash_length);
|
||||
@@ -1517,6 +1615,14 @@ void LightCommandRequest::dump_to(std::string &out) const {
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" has_color_mode: ");
|
||||
out.append(YESNO(this->has_color_mode));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" color_mode: ");
|
||||
out.append(proto_enum_to_string<enums::ColorMode>(this->color_mode));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" has_color_brightness: ");
|
||||
out.append(YESNO(this->has_color_brightness));
|
||||
out.append("\n");
|
||||
@@ -1563,6 +1669,24 @@ void LightCommandRequest::dump_to(std::string &out) const {
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" has_cold_white: ");
|
||||
out.append(YESNO(this->has_cold_white));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" cold_white: ");
|
||||
sprintf(buffer, "%g", this->cold_white);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" has_warm_white: ");
|
||||
out.append(YESNO(this->has_warm_white));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" warm_white: ");
|
||||
sprintf(buffer, "%g", this->warm_white);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" has_transition_length: ");
|
||||
out.append(YESNO(this->has_transition_length));
|
||||
out.append("\n");
|
||||
|
Reference in New Issue
Block a user