Merge branch 'json-bump-library' of https://github.com/kahrendt/esphome into json-bump-library

This commit is contained in:
J. Nick Koston 2025-07-14 09:30:45 -10:00
commit fe9316c95d
No known key found for this signature in database
4 changed files with 23 additions and 23 deletions

View File

@ -91,7 +91,7 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
}
}
if (root["brightness"].is<unsigned char>()) {
if (root["brightness"].is<uint8_t>()) {
call.set_brightness(float(root["brightness"]) / 255.0f);
}
@ -99,32 +99,32 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
JsonObject color = root["color"];
// HA also encodes brightness information in the r, g, b values, so extract that and set it as color brightness.
float max_rgb = 0.0f;
if (color["r"].is<unsigned char>()) {
if (color["r"].is<uint8_t>()) {
float r = float(color["r"]) / 255.0f;
max_rgb = fmaxf(max_rgb, r);
call.set_red(r);
}
if (color["g"].is<unsigned char>()) {
if (color["g"].is<uint8_t>()) {
float g = float(color["g"]) / 255.0f;
max_rgb = fmaxf(max_rgb, g);
call.set_green(g);
}
if (color["b"].is<unsigned char>()) {
if (color["b"].is<uint8_t>()) {
float b = float(color["b"]) / 255.0f;
max_rgb = fmaxf(max_rgb, b);
call.set_blue(b);
}
if (color["r"].is<unsigned char>() || color["g"].is<unsigned char>() || color["b"].is<unsigned char>()) {
if (color["r"].is<uint8_t>() || color["g"].is<uint8_t>() || color["b"].is<uint8_t>()) {
call.set_color_brightness(max_rgb);
}
if (color["c"].is<unsigned char>()) {
if (color["c"].is<uint8_t>()) {
call.set_cold_white(float(color["c"]) / 255.0f);
}
if (color["w"].is<unsigned short>()) {
if (color["w"].is<uint16_t>()) {
// the HA scheme is ambiguous here, the same key is used for white channel in RGBW and warm
// white channel in RGBWW.
if (color["c"].is<unsigned short>()) {
if (color["c"].is<uint16_t>()) {
call.set_warm_white(float(color["w"]) / 255.0f);
} else {
call.set_white(float(color["w"]) / 255.0f);
@ -132,11 +132,11 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
}
}
if (root["white_value"].is<unsigned short>()) { // legacy API
if (root["white_value"].is<uint16_t>()) { // legacy API
call.set_white(float(root["white_value"]) / 255.0f);
}
if (root["color_temp"].is<unsigned short>()) {
if (root["color_temp"].is<uint16_t>()) {
call.set_color_temperature(float(root["color_temp"]));
}
}
@ -149,7 +149,7 @@ void LightJSONSchema::parse_json(LightState &state, LightCall &call, JsonObject
call.set_flash_length(length);
}
if (root["transition"].is<unsigned short>()) {
if (root["transition"].is<uint16_t>()) {
auto length = uint32_t(float(root["transition"]) * 1000);
call.set_transition_length(length);
}

View File

@ -20,13 +20,13 @@ MQTTDateComponent::MQTTDateComponent(DateEntity *date) : date_(date) {}
void MQTTDateComponent::setup() {
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
auto call = this->date_->make_call();
if (root["year"].is<unsigned short>()) {
if (root["year"].is<uint16_t>()) {
call.set_year(root["year"]);
}
if (root["month"].is<unsigned char>()) {
if (root["month"].is<uint8_t>()) {
call.set_month(root["month"]);
}
if (root["day"].is<unsigned short>()) {
if (root["day"].is<uint16_t>()) {
call.set_day(root["day"]);
}
call.perform();

View File

@ -20,22 +20,22 @@ MQTTDateTimeComponent::MQTTDateTimeComponent(DateTimeEntity *datetime) : datetim
void MQTTDateTimeComponent::setup() {
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
auto call = this->datetime_->make_call();
if (root["year"].is<unsigned short>()) {
if (root["year"].is<uint16_t>()) {
call.set_year(root["year"]);
}
if (root["month"].is<unsigned char>()) {
if (root["month"].is<uint8_t>()) {
call.set_month(root["month"]);
}
if (root["day"].is<unsigned char>()) {
if (root["day"].is<uint8_t>()) {
call.set_day(root["day"]);
}
if (root["hour"].is<unsigned short>()) {
if (root["hour"].is<uint16_t>()) {
call.set_hour(root["hour"]);
}
if (root["minute"].is<unsigned short>()) {
if (root["minute"].is<uint16_t>()) {
call.set_minute(root["minute"]);
}
if (root["second"].is<unsigned short>()) {
if (root["second"].is<uint16_t>()) {
call.set_second(root["second"]);
}
call.perform();

View File

@ -20,13 +20,13 @@ MQTTTimeComponent::MQTTTimeComponent(TimeEntity *time) : time_(time) {}
void MQTTTimeComponent::setup() {
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
auto call = this->time_->make_call();
if (root["hour"].is<unsigned short>()) {
if (root["hour"].is<uint16_t>()) {
call.set_hour(root["hour"]);
}
if (root["minute"].is<unsigned short>()) {
if (root["minute"].is<uint16_t>()) {
call.set_minute(root["minute"]);
}
if (root["second"].is<unsigned short>()) {
if (root["second"].is<uint16_t>()) {
call.set_second(root["second"]);
}
call.perform();