mirror of
https://github.com/esphome/esphome.git
synced 2025-08-03 17:07:54 +00:00
Merge branch 'json-bump-library' of https://github.com/kahrendt/esphome into json-bump-library
This commit is contained in:
commit
4c8bb878bf
@ -29,6 +29,7 @@ std::string build_json(const json_build_t &f) {
|
|||||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
auto doc_allocator = SpiRamAllocator();
|
auto doc_allocator = SpiRamAllocator();
|
||||||
JsonDocument json_document(&doc_allocator);
|
JsonDocument json_document(&doc_allocator);
|
||||||
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
if (json_document.overflowed()) {
|
if (json_document.overflowed()) {
|
||||||
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
||||||
return "{}";
|
return "{}";
|
||||||
@ -36,6 +37,7 @@ std::string build_json(const json_build_t &f) {
|
|||||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
JsonObject root = json_document.to<JsonObject>();
|
JsonObject root = json_document.to<JsonObject>();
|
||||||
f(root);
|
f(root);
|
||||||
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
if (json_document.overflowed()) {
|
if (json_document.overflowed()) {
|
||||||
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
||||||
return "{}";
|
return "{}";
|
||||||
@ -49,6 +51,7 @@ bool parse_json(const std::string &data, const json_parse_t &f) {
|
|||||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
auto doc_allocator = SpiRamAllocator();
|
auto doc_allocator = SpiRamAllocator();
|
||||||
JsonDocument json_document(&doc_allocator);
|
JsonDocument json_document(&doc_allocator);
|
||||||
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
if (json_document.overflowed()) {
|
if (json_document.overflowed()) {
|
||||||
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
||||||
return false;
|
return false;
|
||||||
|
@ -121,10 +121,10 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
|
|||||||
if (color["c"].is<uint8_t>()) {
|
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<uint16_t>()) {
|
if (color["w"].is<uint8_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<uint16_t>()) {
|
if (color["c"].is<uint8_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,7 +132,7 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root["white_value"].is<uint16_t>()) { // legacy API
|
if (root["white_value"].is<uint8_t>()) { // legacy API
|
||||||
call.set_white(float(root["white_value"]) / 255.0f);
|
call.set_white(float(root["white_value"]) / 255.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
|
|||||||
void LightJSONSchema::parse_json(LightState &state, LightCall &call, JsonObject root) {
|
void LightJSONSchema::parse_json(LightState &state, LightCall &call, JsonObject root) {
|
||||||
LightJSONSchema::parse_color_json(state, call, root);
|
LightJSONSchema::parse_color_json(state, call, root);
|
||||||
|
|
||||||
if (root["flash"].is<unsigned int>()) {
|
if (root["flash"].is<uint32_t>()) {
|
||||||
auto length = uint32_t(float(root["flash"]) * 1000);
|
auto length = uint32_t(float(root["flash"]) * 1000);
|
||||||
call.set_flash_length(length);
|
call.set_flash_length(length);
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,10 @@ void MQTTLockComponent::dump_config() {
|
|||||||
std::string MQTTLockComponent::component_type() const { return "lock"; }
|
std::string MQTTLockComponent::component_type() const { return "lock"; }
|
||||||
const EntityBase *MQTTLockComponent::get_entity() const { return this->lock_; }
|
const EntityBase *MQTTLockComponent::get_entity() const { return this->lock_; }
|
||||||
void MQTTLockComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
void MQTTLockComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||||
if (this->lock_->traits.get_assumed_state())
|
if (this->lock_->traits.get_assumed_state()) {
|
||||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
root[MQTT_OPTIMISTIC] = true;
|
root[MQTT_OPTIMISTIC] = true;
|
||||||
|
}
|
||||||
if (this->lock_->traits.get_supports_open())
|
if (this->lock_->traits.get_supports_open())
|
||||||
root[MQTT_PAYLOAD_OPEN] = "OPEN";
|
root[MQTT_PAYLOAD_OPEN] = "OPEN";
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,10 @@ void MQTTSensorComponent::set_expire_after(uint32_t expire_after) { this->expire
|
|||||||
void MQTTSensorComponent::disable_expire_after() { this->expire_after_ = 0; }
|
void MQTTSensorComponent::disable_expire_after() { this->expire_after_ = 0; }
|
||||||
|
|
||||||
void MQTTSensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
void MQTTSensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||||
if (!this->sensor_->get_device_class().empty())
|
if (!this->sensor_->get_device_class().empty()) {
|
||||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
root[MQTT_DEVICE_CLASS] = this->sensor_->get_device_class();
|
root[MQTT_DEVICE_CLASS] = this->sensor_->get_device_class();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this->sensor_->get_unit_of_measurement().empty())
|
if (!this->sensor_->get_unit_of_measurement().empty())
|
||||||
root[MQTT_UNIT_OF_MEASUREMENT] = this->sensor_->get_unit_of_measurement();
|
root[MQTT_UNIT_OF_MEASUREMENT] = this->sensor_->get_unit_of_measurement();
|
||||||
|
@ -45,9 +45,10 @@ void MQTTSwitchComponent::dump_config() {
|
|||||||
std::string MQTTSwitchComponent::component_type() const { return "switch"; }
|
std::string MQTTSwitchComponent::component_type() const { return "switch"; }
|
||||||
const EntityBase *MQTTSwitchComponent::get_entity() const { return this->switch_; }
|
const EntityBase *MQTTSwitchComponent::get_entity() const { return this->switch_; }
|
||||||
void MQTTSwitchComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
void MQTTSwitchComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||||
if (this->switch_->assumed_state())
|
if (this->switch_->assumed_state()) {
|
||||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
root[MQTT_OPTIMISTIC] = true;
|
root[MQTT_OPTIMISTIC] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bool MQTTSwitchComponent::send_initial_state() { return this->publish_state(this->switch_->state); }
|
bool MQTTSwitchComponent::send_initial_state() { return this->publish_state(this->switch_->state); }
|
||||||
|
|
||||||
|
@ -15,9 +15,10 @@ using namespace esphome::text_sensor;
|
|||||||
|
|
||||||
MQTTTextSensor::MQTTTextSensor(TextSensor *sensor) : sensor_(sensor) {}
|
MQTTTextSensor::MQTTTextSensor(TextSensor *sensor) : sensor_(sensor) {}
|
||||||
void MQTTTextSensor::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
void MQTTTextSensor::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||||
if (!this->sensor_->get_device_class().empty())
|
if (!this->sensor_->get_device_class().empty()) {
|
||||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
root[MQTT_DEVICE_CLASS] = this->sensor_->get_device_class();
|
root[MQTT_DEVICE_CLASS] = this->sensor_->get_device_class();
|
||||||
|
}
|
||||||
config.command_topic = false;
|
config.command_topic = false;
|
||||||
}
|
}
|
||||||
void MQTTTextSensor::setup() {
|
void MQTTTextSensor::setup() {
|
||||||
|
@ -49,9 +49,10 @@ void MQTTValveComponent::dump_config() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MQTTValveComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
void MQTTValveComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||||
if (!this->valve_->get_device_class().empty())
|
if (!this->valve_->get_device_class().empty()) {
|
||||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
root[MQTT_DEVICE_CLASS] = this->valve_->get_device_class();
|
root[MQTT_DEVICE_CLASS] = this->valve_->get_device_class();
|
||||||
|
}
|
||||||
|
|
||||||
auto traits = this->valve_->get_traits();
|
auto traits = this->valve_->get_traits();
|
||||||
if (traits.get_is_assumed_state()) {
|
if (traits.get_is_assumed_state()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user