Merge pull request #3478 from esphome/bump-2022.5.0b3

2022.5.0b3
This commit is contained in:
Jesse Hills 2022-05-16 13:42:05 +12:00 committed by GitHub
commit 7e88938932
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 18 deletions

View file

@ -1,6 +1,8 @@
from esphome.const import CONF_BAUD_RATE, CONF_ID, CONF_LOGGER from esphome.components.logger import USB_CDC, USB_SERIAL_JTAG
from esphome.const import CONF_BAUD_RATE, CONF_HARDWARE_UART, CONF_ID, CONF_LOGGER
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.core import CORE
import esphome.final_validate as fv import esphome.final_validate as fv
CODEOWNERS = ["@esphome/core"] CODEOWNERS = ["@esphome/core"]
@ -17,14 +19,19 @@ CONFIG_SCHEMA = cv.Schema(
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)
def validate_logger_baud_rate(config): def validate_logger(config):
logger_conf = fv.full_config.get()[CONF_LOGGER] logger_conf = fv.full_config.get()[CONF_LOGGER]
if logger_conf[CONF_BAUD_RATE] == 0: if logger_conf[CONF_BAUD_RATE] == 0:
raise cv.Invalid("improv_serial requires the logger baud_rate to be not 0") raise cv.Invalid("improv_serial requires the logger baud_rate to be not 0")
if CORE.using_esp_idf:
if logger_conf[CONF_HARDWARE_UART] in [USB_SERIAL_JTAG, USB_CDC]:
raise cv.Invalid(
"improv_serial does not support the selected logger hardware_uart"
)
return config return config
FINAL_VALIDATE_SCHEMA = validate_logger_baud_rate FINAL_VALIDATE_SCHEMA = validate_logger
async def to_code(config): async def to_code(config):

View file

@ -26,22 +26,34 @@ std::string build_json(const json_build_t &f) {
const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT); const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
#endif #endif
const size_t request_size = std::min(free_heap, (size_t) 512); size_t request_size = std::min(free_heap, (size_t) 512);
while (true) {
ESP_LOGV(TAG, "Attempting to allocate %u bytes for JSON serialization", request_size);
DynamicJsonDocument json_document(request_size); DynamicJsonDocument json_document(request_size);
if (json_document.capacity() == 0) { if (json_document.capacity() == 0) {
ESP_LOGE(TAG, "Could not allocate memory for JSON document! Requested %u bytes, largest free heap block: %u bytes", ESP_LOGE(TAG,
"Could not allocate memory for JSON document! Requested %u bytes, largest free heap block: %u bytes",
request_size, free_heap); request_size, free_heap);
return "{}"; return "{}";
} }
JsonObject root = json_document.to<JsonObject>(); JsonObject root = json_document.to<JsonObject>();
f(root); f(root);
if (json_document.overflowed()) {
if (request_size == free_heap) {
ESP_LOGE(TAG, "Could not allocate memory for JSON document! Overflowed largest free heap block: %u bytes",
free_heap);
return "{}";
}
request_size = std::min(request_size * 2, free_heap);
continue;
}
json_document.shrinkToFit(); json_document.shrinkToFit();
ESP_LOGV(TAG, "Size after shrink %u bytes", json_document.capacity()); ESP_LOGV(TAG, "Size after shrink %u bytes", json_document.capacity());
std::string output; std::string output;
serializeJson(json_document, output); serializeJson(json_document, output);
return output; return output;
} }
}
void parse_json(const std::string &data, const json_parse_t &f) { void parse_json(const std::string &data, const json_parse_t &f) {
// Here we are allocating 1.5 times the data size, // Here we are allocating 1.5 times the data size,

View file

@ -1,6 +1,6 @@
"""Constants used by esphome.""" """Constants used by esphome."""
__version__ = "2022.5.0b2" __version__ = "2022.5.0b3"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_" ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"