mirror of
https://github.com/esphome/esphome.git
synced 2025-08-03 00:47:47 +00:00
Merge branch 'json-bump-library' of https://github.com/kahrendt/esphome into json-bump-library
This commit is contained in:
commit
fe9316c95d
@ -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);
|
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"];
|
JsonObject color = root["color"];
|
||||||
// HA also encodes brightness information in the r, g, b values, so extract that and set it as color brightness.
|
// 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;
|
float max_rgb = 0.0f;
|
||||||
if (color["r"].is<unsigned char>()) {
|
if (color["r"].is<uint8_t>()) {
|
||||||
float r = float(color["r"]) / 255.0f;
|
float r = float(color["r"]) / 255.0f;
|
||||||
max_rgb = fmaxf(max_rgb, r);
|
max_rgb = fmaxf(max_rgb, r);
|
||||||
call.set_red(r);
|
call.set_red(r);
|
||||||
}
|
}
|
||||||
if (color["g"].is<unsigned char>()) {
|
if (color["g"].is<uint8_t>()) {
|
||||||
float g = float(color["g"]) / 255.0f;
|
float g = float(color["g"]) / 255.0f;
|
||||||
max_rgb = fmaxf(max_rgb, g);
|
max_rgb = fmaxf(max_rgb, g);
|
||||||
call.set_green(g);
|
call.set_green(g);
|
||||||
}
|
}
|
||||||
if (color["b"].is<unsigned char>()) {
|
if (color["b"].is<uint8_t>()) {
|
||||||
float b = float(color["b"]) / 255.0f;
|
float b = float(color["b"]) / 255.0f;
|
||||||
max_rgb = fmaxf(max_rgb, b);
|
max_rgb = fmaxf(max_rgb, b);
|
||||||
call.set_blue(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);
|
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);
|
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
|
// the HA scheme is ambiguous here, the same key is used for white channel in RGBW and warm
|
||||||
// white channel in RGBWW.
|
// 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);
|
call.set_warm_white(float(color["w"]) / 255.0f);
|
||||||
} else {
|
} else {
|
||||||
call.set_white(float(color["w"]) / 255.0f);
|
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);
|
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"]));
|
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);
|
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);
|
auto length = uint32_t(float(root["transition"]) * 1000);
|
||||||
call.set_transition_length(length);
|
call.set_transition_length(length);
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,13 @@ MQTTDateComponent::MQTTDateComponent(DateEntity *date) : date_(date) {}
|
|||||||
void MQTTDateComponent::setup() {
|
void MQTTDateComponent::setup() {
|
||||||
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
|
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
|
||||||
auto call = this->date_->make_call();
|
auto call = this->date_->make_call();
|
||||||
if (root["year"].is<unsigned short>()) {
|
if (root["year"].is<uint16_t>()) {
|
||||||
call.set_year(root["year"]);
|
call.set_year(root["year"]);
|
||||||
}
|
}
|
||||||
if (root["month"].is<unsigned char>()) {
|
if (root["month"].is<uint8_t>()) {
|
||||||
call.set_month(root["month"]);
|
call.set_month(root["month"]);
|
||||||
}
|
}
|
||||||
if (root["day"].is<unsigned short>()) {
|
if (root["day"].is<uint16_t>()) {
|
||||||
call.set_day(root["day"]);
|
call.set_day(root["day"]);
|
||||||
}
|
}
|
||||||
call.perform();
|
call.perform();
|
||||||
|
@ -20,22 +20,22 @@ MQTTDateTimeComponent::MQTTDateTimeComponent(DateTimeEntity *datetime) : datetim
|
|||||||
void MQTTDateTimeComponent::setup() {
|
void MQTTDateTimeComponent::setup() {
|
||||||
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
|
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
|
||||||
auto call = this->datetime_->make_call();
|
auto call = this->datetime_->make_call();
|
||||||
if (root["year"].is<unsigned short>()) {
|
if (root["year"].is<uint16_t>()) {
|
||||||
call.set_year(root["year"]);
|
call.set_year(root["year"]);
|
||||||
}
|
}
|
||||||
if (root["month"].is<unsigned char>()) {
|
if (root["month"].is<uint8_t>()) {
|
||||||
call.set_month(root["month"]);
|
call.set_month(root["month"]);
|
||||||
}
|
}
|
||||||
if (root["day"].is<unsigned char>()) {
|
if (root["day"].is<uint8_t>()) {
|
||||||
call.set_day(root["day"]);
|
call.set_day(root["day"]);
|
||||||
}
|
}
|
||||||
if (root["hour"].is<unsigned short>()) {
|
if (root["hour"].is<uint16_t>()) {
|
||||||
call.set_hour(root["hour"]);
|
call.set_hour(root["hour"]);
|
||||||
}
|
}
|
||||||
if (root["minute"].is<unsigned short>()) {
|
if (root["minute"].is<uint16_t>()) {
|
||||||
call.set_minute(root["minute"]);
|
call.set_minute(root["minute"]);
|
||||||
}
|
}
|
||||||
if (root["second"].is<unsigned short>()) {
|
if (root["second"].is<uint16_t>()) {
|
||||||
call.set_second(root["second"]);
|
call.set_second(root["second"]);
|
||||||
}
|
}
|
||||||
call.perform();
|
call.perform();
|
||||||
|
@ -20,13 +20,13 @@ MQTTTimeComponent::MQTTTimeComponent(TimeEntity *time) : time_(time) {}
|
|||||||
void MQTTTimeComponent::setup() {
|
void MQTTTimeComponent::setup() {
|
||||||
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
|
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
|
||||||
auto call = this->time_->make_call();
|
auto call = this->time_->make_call();
|
||||||
if (root["hour"].is<unsigned short>()) {
|
if (root["hour"].is<uint16_t>()) {
|
||||||
call.set_hour(root["hour"]);
|
call.set_hour(root["hour"]);
|
||||||
}
|
}
|
||||||
if (root["minute"].is<unsigned short>()) {
|
if (root["minute"].is<uint16_t>()) {
|
||||||
call.set_minute(root["minute"]);
|
call.set_minute(root["minute"]);
|
||||||
}
|
}
|
||||||
if (root["second"].is<unsigned short>()) {
|
if (root["second"].is<uint16_t>()) {
|
||||||
call.set_second(root["second"]);
|
call.set_second(root["second"]);
|
||||||
}
|
}
|
||||||
call.perform();
|
call.perform();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user