Merge branch 'dev' into refactor_esp32camera

This commit is contained in:
DT-art1 2024-11-22 07:53:29 +01:00 committed by GitHub
commit 6f02833e3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 115 additions and 20 deletions

View file

@ -219,7 +219,7 @@ jobs:
. venv/bin/activate . venv/bin/activate
pytest -vv --cov-report=xml --tb=native tests pytest -vv --cov-report=xml --tb=native tests
- name: Upload coverage to Codecov - name: Upload coverage to Codecov
uses: codecov/codecov-action@v4 uses: codecov/codecov-action@v5
with: with:
token: ${{ secrets.CODECOV_TOKEN }} token: ${{ secrets.CODECOV_TOKEN }}

View file

@ -1,10 +1,9 @@
import logging import logging
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv from esphome.components.ota import BASE_OTA_SCHEMA, OTAComponent, ota_to_code
import esphome.final_validate as fv
from esphome.components.ota import BASE_OTA_SCHEMA, ota_to_code, OTAComponent
from esphome.config_helpers import merge_config from esphome.config_helpers import merge_config
import esphome.config_validation as cv
from esphome.const import ( from esphome.const import (
CONF_ESPHOME, CONF_ESPHOME,
CONF_ID, CONF_ID,
@ -18,6 +17,7 @@ from esphome.const import (
CONF_VERSION, CONF_VERSION,
) )
from esphome.core import coroutine_with_priority from esphome.core import coroutine_with_priority
import esphome.final_validate as fv
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -124,7 +124,6 @@ FINAL_VALIDATE_SCHEMA = ota_esphome_final_validate
@coroutine_with_priority(52.0) @coroutine_with_priority(52.0)
async def to_code(config): async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await ota_to_code(var, config)
cg.add(var.set_port(config[CONF_PORT])) cg.add(var.set_port(config[CONF_PORT]))
if CONF_PASSWORD in config: if CONF_PASSWORD in config:
cg.add(var.set_auth_password(config[CONF_PASSWORD])) cg.add(var.set_auth_password(config[CONF_PASSWORD]))
@ -132,3 +131,4 @@ async def to_code(config):
cg.add_define("USE_OTA_VERSION", config[CONF_VERSION]) cg.add_define("USE_OTA_VERSION", config[CONF_VERSION])
await cg.register_component(var, config) await cg.register_component(var, config)
await ota_to_code(var, config)

View file

@ -189,7 +189,7 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
if (container == nullptr) { if (container == nullptr) {
for (auto *trigger : this->error_triggers_) for (auto *trigger : this->error_triggers_)
trigger->trigger(x...); trigger->trigger();
return; return;
} }

View file

@ -104,7 +104,9 @@ std::shared_ptr<HttpContainer> HttpRequestArduino::start(std::string url, std::s
static const size_t HEADER_COUNT = sizeof(header_keys) / sizeof(header_keys[0]); static const size_t HEADER_COUNT = sizeof(header_keys) / sizeof(header_keys[0]);
container->client_.collectHeaders(header_keys, HEADER_COUNT); container->client_.collectHeaders(header_keys, HEADER_COUNT);
App.feed_wdt();
container->status_code = container->client_.sendRequest(method.c_str(), body.c_str()); container->status_code = container->client_.sendRequest(method.c_str(), body.c_str());
App.feed_wdt();
if (container->status_code < 0) { if (container->status_code < 0) {
ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %s", url.c_str(), ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %s", url.c_str(),
HTTPClient::errorToString(container->status_code).c_str()); HTTPClient::errorToString(container->status_code).c_str());

View file

@ -117,8 +117,11 @@ std::shared_ptr<HttpContainer> HttpRequestIDF::start(std::string url, std::strin
return nullptr; return nullptr;
} }
App.feed_wdt();
container->content_length = esp_http_client_fetch_headers(client); container->content_length = esp_http_client_fetch_headers(client);
App.feed_wdt();
container->status_code = esp_http_client_get_status_code(client); container->status_code = esp_http_client_get_status_code(client);
App.feed_wdt();
if (is_success(container->status_code)) { if (is_success(container->status_code)) {
container->duration_ms = millis() - start; container->duration_ms = millis() - start;
return container; return container;
@ -148,8 +151,11 @@ std::shared_ptr<HttpContainer> HttpRequestIDF::start(std::string url, std::strin
return nullptr; return nullptr;
} }
App.feed_wdt();
container->content_length = esp_http_client_fetch_headers(client); container->content_length = esp_http_client_fetch_headers(client);
App.feed_wdt();
container->status_code = esp_http_client_get_status_code(client); container->status_code = esp_http_client_get_status_code(client);
App.feed_wdt();
if (is_success(container->status_code)) { if (is_success(container->status_code)) {
container->duration_ms = millis() - start; container->duration_ms = millis() - start;
return container; return container;

View file

@ -42,5 +42,12 @@ class TouchTrigger : public Trigger<uint8_t, uint8_t, bool> {
} }
}; };
class BufferOverflowTrigger : public Trigger<> {
public:
explicit BufferOverflowTrigger(Nextion *nextion) {
nextion->add_buffer_overflow_event_callback([this]() { this->trigger(); });
}
};
} // namespace nextion } // namespace nextion
} // namespace esphome } // namespace esphome

View file

@ -18,6 +18,7 @@ CONF_ON_SLEEP = "on_sleep"
CONF_ON_WAKE = "on_wake" CONF_ON_WAKE = "on_wake"
CONF_ON_SETUP = "on_setup" CONF_ON_SETUP = "on_setup"
CONF_ON_PAGE = "on_page" CONF_ON_PAGE = "on_page"
CONF_ON_BUFFER_OVERFLOW = "on_buffer_overflow"
CONF_TOUCH_SLEEP_TIMEOUT = "touch_sleep_timeout" CONF_TOUCH_SLEEP_TIMEOUT = "touch_sleep_timeout"
CONF_WAKE_UP_PAGE = "wake_up_page" CONF_WAKE_UP_PAGE = "wake_up_page"
CONF_START_UP_PAGE = "start_up_page" CONF_START_UP_PAGE = "start_up_page"

View file

@ -13,6 +13,7 @@ from esphome.const import (
from esphome.core import CORE from esphome.core import CORE
from . import Nextion, nextion_ns, nextion_ref from . import Nextion, nextion_ns, nextion_ref
from .base_component import ( from .base_component import (
CONF_ON_BUFFER_OVERFLOW,
CONF_ON_SLEEP, CONF_ON_SLEEP,
CONF_ON_WAKE, CONF_ON_WAKE,
CONF_ON_SETUP, CONF_ON_SETUP,
@ -36,6 +37,9 @@ SleepTrigger = nextion_ns.class_("SleepTrigger", automation.Trigger.template())
WakeTrigger = nextion_ns.class_("WakeTrigger", automation.Trigger.template()) WakeTrigger = nextion_ns.class_("WakeTrigger", automation.Trigger.template())
PageTrigger = nextion_ns.class_("PageTrigger", automation.Trigger.template()) PageTrigger = nextion_ns.class_("PageTrigger", automation.Trigger.template())
TouchTrigger = nextion_ns.class_("TouchTrigger", automation.Trigger.template()) TouchTrigger = nextion_ns.class_("TouchTrigger", automation.Trigger.template())
BufferOverflowTrigger = nextion_ns.class_(
"BufferOverflowTrigger", automation.Trigger.template()
)
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
display.BASIC_DISPLAY_SCHEMA.extend( display.BASIC_DISPLAY_SCHEMA.extend(
@ -68,6 +72,13 @@ CONFIG_SCHEMA = (
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(TouchTrigger), cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(TouchTrigger),
} }
), ),
cv.Optional(CONF_ON_BUFFER_OVERFLOW): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
BufferOverflowTrigger
),
}
),
cv.Optional(CONF_TOUCH_SLEEP_TIMEOUT): cv.int_range(min=3, max=65535), cv.Optional(CONF_TOUCH_SLEEP_TIMEOUT): cv.int_range(min=3, max=65535),
cv.Optional(CONF_WAKE_UP_PAGE): cv.uint8_t, cv.Optional(CONF_WAKE_UP_PAGE): cv.uint8_t,
cv.Optional(CONF_START_UP_PAGE): cv.uint8_t, cv.Optional(CONF_START_UP_PAGE): cv.uint8_t,
@ -151,3 +162,7 @@ async def to_code(config):
], ],
conf, conf,
) )
for conf in config.get(CONF_ON_BUFFER_OVERFLOW, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)

View file

@ -190,6 +190,10 @@ void Nextion::add_touch_event_callback(std::function<void(uint8_t, uint8_t, bool
this->touch_callback_.add(std::move(callback)); this->touch_callback_.add(std::move(callback));
} }
void Nextion::add_buffer_overflow_event_callback(std::function<void()> &&callback) {
this->buffer_overflow_callback_.add(std::move(callback));
}
void Nextion::update_all_components() { void Nextion::update_all_components() {
if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping()) if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
return; return;
@ -458,7 +462,9 @@ void Nextion::process_nextion_commands_() {
this->remove_from_q_(); this->remove_from_q_();
break; break;
case 0x24: // Serial Buffer overflow occurs case 0x24: // Serial Buffer overflow occurs
ESP_LOGW(TAG, "Nextion reported Serial Buffer overflow!"); // Buffer will continue to receive the current instruction, all previous instructions are lost.
ESP_LOGE(TAG, "Nextion reported Serial Buffer overflow!");
this->buffer_overflow_callback_.call();
break; break;
case 0x65: { // touch event return data case 0x65: { // touch event return data
if (to_process_length != 3) { if (to_process_length != 3) {

View file

@ -1134,6 +1134,12 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
*/ */
void add_touch_event_callback(std::function<void(uint8_t, uint8_t, bool)> &&callback); void add_touch_event_callback(std::function<void(uint8_t, uint8_t, bool)> &&callback);
/** Add a callback to be notified when the nextion reports a buffer overflow.
*
* @param callback The void() callback.
*/
void add_buffer_overflow_event_callback(std::function<void()> &&callback);
void update_all_components(); void update_all_components();
/** /**
@ -1323,6 +1329,7 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
CallbackManager<void()> wake_callback_{}; CallbackManager<void()> wake_callback_{};
CallbackManager<void(uint8_t)> page_callback_{}; CallbackManager<void(uint8_t)> page_callback_{};
CallbackManager<void(uint8_t, uint8_t, bool)> touch_callback_{}; CallbackManager<void(uint8_t, uint8_t, bool)> touch_callback_{};
CallbackManager<void()> buffer_overflow_callback_{};
optional<nextion_writer_t> writer_; optional<nextion_writer_t> writer_;
float brightness_{1.0}; float brightness_{1.0};

View file

@ -98,6 +98,7 @@ CONFIG_SCHEMA = cv.Schema(
# esp8266_arduino=cv.Version(2, 7, 0), # esp8266_arduino=cv.Version(2, 7, 0),
esp32_arduino=cv.Version(0, 0, 0), esp32_arduino=cv.Version(0, 0, 0),
esp_idf=cv.Version(4, 0, 0), esp_idf=cv.Version(4, 0, 0),
rp2040_arduino=cv.Version(0, 0, 0),
), ),
) )
) )

View file

@ -92,6 +92,7 @@ async def to_code(config):
async def ota_to_code(var, config): async def ota_to_code(var, config):
await cg.past_safe_mode()
use_state_callback = False use_state_callback = False
for conf in config.get(CONF_ON_STATE_CHANGE, []): for conf in config.get(CONF_ON_STATE_CHANGE, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var) trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)

View file

@ -55,6 +55,7 @@ chip.cmd(PAGESEL, 0x00)
chip.cmd(0xC2, 0x00) chip.cmd(0xC2, 0x00)
chip.delay(10) chip.delay(10)
chip.cmd(TEON, 0x00) chip.cmd(TEON, 0x00)
chip.cmd(PIXFMT, 0x55)
chip = DriverChip("AXS15231") chip = DriverChip("AXS15231")
chip.cmd(0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A, 0xA5) chip.cmd(0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A, 0xA5)

View file

@ -28,7 +28,7 @@ bool RawDumper::dump(RemoteReceiveData src) {
ESP_LOGI(TAG, "%s", buffer); ESP_LOGI(TAG, "%s", buffer);
buffer_offset = 0; buffer_offset = 0;
written = sprintf(buffer, " "); written = sprintf(buffer, " ");
if (i + 1 < src.size()) { if (i + 1 < src.size() - 1) {
written += sprintf(buffer + written, "%" PRId32 ", ", value); written += sprintf(buffer + written, "%" PRId32 ", ", value);
} else { } else {
written += sprintf(buffer + written, "%" PRId32, value); written += sprintf(buffer + written, "%" PRId32, value);

View file

@ -40,13 +40,7 @@ class Rtttl : public Component {
void set_speaker(speaker::Speaker *speaker) { this->speaker_ = speaker; } void set_speaker(speaker::Speaker *speaker) { this->speaker_ = speaker; }
#endif #endif
float get_gain() { return gain_; } float get_gain() { return gain_; }
void set_gain(float gain) { void set_gain(float gain) { this->gain_ = clamp(gain, 0.0f, 1.0f); }
if (gain < 0.1f)
gain = 0.1f;
if (gain > 1.0f)
gain = 1.0f;
this->gain_ = gain;
}
void play(std::string rtttl); void play(std::string rtttl);
void stop(); void stop();
void dump_config() override; void dump_config() override;

View file

@ -7,6 +7,7 @@ from esphome.const import CONF_DATA, CONF_ID, CONF_VOLUME
from esphome.core import CORE from esphome.core import CORE
from esphome.coroutine import coroutine_with_priority from esphome.coroutine import coroutine_with_priority
AUTO_LOAD = ["audio"]
CODEOWNERS = ["@jesserockz", "@kahrendt"] CODEOWNERS = ["@jesserockz", "@kahrendt"]
IS_PLATFORM_COMPONENT = True IS_PLATFORM_COMPONENT = True

View file

@ -86,7 +86,7 @@ void TuyaFan::control(const fan::FanCall &call) {
if (this->oscillation_id_.has_value() && call.get_oscillating().has_value()) { if (this->oscillation_id_.has_value() && call.get_oscillating().has_value()) {
if (this->oscillation_type_ == TuyaDatapointType::ENUM) { if (this->oscillation_type_ == TuyaDatapointType::ENUM) {
this->parent_->set_enum_datapoint_value(*this->oscillation_id_, *call.get_oscillating()); this->parent_->set_enum_datapoint_value(*this->oscillation_id_, *call.get_oscillating());
} else if (this->speed_type_ == TuyaDatapointType::BOOLEAN) { } else if (this->oscillation_type_ == TuyaDatapointType::BOOLEAN) {
this->parent_->set_boolean_datapoint_value(*this->oscillation_id_, *call.get_oscillating()); this->parent_->set_boolean_datapoint_value(*this->oscillation_id_, *call.get_oscillating());
} }
} }

View file

@ -184,6 +184,9 @@ PRELOAD_CONFIG_SCHEMA = cv.Schema(
cv.Optional(CONF_ESP8266_RESTORE_FROM_FLASH): cv.valid, cv.Optional(CONF_ESP8266_RESTORE_FROM_FLASH): cv.valid,
cv.Optional(CONF_BOARD_FLASH_MODE): cv.valid, cv.Optional(CONF_BOARD_FLASH_MODE): cv.valid,
cv.Optional(CONF_ARDUINO_VERSION): cv.valid, cv.Optional(CONF_ARDUINO_VERSION): cv.valid,
cv.Optional(CONF_MIN_VERSION, default=ESPHOME_VERSION): cv.All(
cv.version_number, cv.validate_esphome_version
),
}, },
extra=cv.ALLOW_EXTRA, extra=cv.ALLOW_EXTRA,
) )

View file

@ -103,7 +103,7 @@ class ESPHomeDashboard:
self.loop = asyncio.get_running_loop() self.loop = asyncio.get_running_loop()
self.ping_request = asyncio.Event() self.ping_request = asyncio.Event()
self.entries = DashboardEntries(self) self.entries = DashboardEntries(self)
self.load_ignored_devices() await self.loop.run_in_executor(None, self.load_ignored_devices)
def load_ignored_devices(self) -> None: def load_ignored_devices(self) -> None:
storage_path = Path(ignored_devices_storage_path()) storage_path = Path(ignored_devices_storage_path())

View file

@ -544,7 +544,7 @@ class ImportRequestHandler(BaseHandler):
class IgnoreDeviceRequestHandler(BaseHandler): class IgnoreDeviceRequestHandler(BaseHandler):
@authenticated @authenticated
def post(self) -> None: async def post(self) -> None:
dashboard = DASHBOARD dashboard = DASHBOARD
try: try:
args = json.loads(self.request.body.decode()) args = json.loads(self.request.body.decode())
@ -576,7 +576,8 @@ class IgnoreDeviceRequestHandler(BaseHandler):
else: else:
dashboard.ignored_devices.discard(ignored_device.device_name) dashboard.ignored_devices.discard(ignored_device.device_name)
dashboard.save_ignored_devices() loop = asyncio.get_running_loop()
await loop.run_in_executor(None, dashboard.save_ignored_devices)
self.set_status(204) self.set_status(204)
self.finish() self.finish()

View file

@ -12,7 +12,7 @@ pyserial==3.5
platformio==6.1.16 # When updating platformio, also update Dockerfile platformio==6.1.16 # When updating platformio, also update Dockerfile
esptool==4.7.0 esptool==4.7.0
click==8.1.7 click==8.1.7
esphome-dashboard==20241025.0 esphome-dashboard==20241120.0
aioesphomeapi==24.6.2 aioesphomeapi==24.6.2
zeroconf==0.132.2 zeroconf==0.132.2
puremagic==1.27 puremagic==1.27

View file

@ -39,6 +39,14 @@ http_request:
timeout: 10s timeout: 10s
verify_ssl: ${verify_ssl} verify_ssl: ${verify_ssl}
script:
- id: does_not_compile
parameters:
api_url: string
then:
- http_request.get:
url: "http://google.com"
ota: ota:
- platform: http_request - platform: http_request
on_begin: on_begin:

View file

@ -58,3 +58,6 @@ display:
on_page: on_page:
then: then:
lambda: 'ESP_LOGD("display","Display shows new page %u", x);' lambda: 'ESP_LOGD("display","Display shows new page %u", x);'
on_buffer_overflow:
then:
logger.log: "Nextion reported a buffer overflow!"

View file

@ -58,3 +58,6 @@ display:
on_page: on_page:
then: then:
lambda: 'ESP_LOGD("display","Display shows new page %u", x);' lambda: 'ESP_LOGD("display","Display shows new page %u", x);'
on_buffer_overflow:
then:
logger.log: "Nextion reported a buffer overflow!"

View file

@ -58,3 +58,6 @@ display:
on_page: on_page:
then: then:
lambda: 'ESP_LOGD("display","Display shows new page %u", x);' lambda: 'ESP_LOGD("display","Display shows new page %u", x);'
on_buffer_overflow:
then:
logger.log: "Nextion reported a buffer overflow!"

View file

@ -58,3 +58,6 @@ display:
on_page: on_page:
then: then:
lambda: 'ESP_LOGD("display","Display shows new page %u", x);' lambda: 'ESP_LOGD("display","Display shows new page %u", x);'
on_buffer_overflow:
then:
logger.log: "Nextion reported a buffer overflow!"

View file

@ -58,3 +58,6 @@ display:
on_page: on_page:
then: then:
lambda: 'ESP_LOGD("display","Display shows new page %u", x);' lambda: 'ESP_LOGD("display","Display shows new page %u", x);'
on_buffer_overflow:
then:
logger.log: "Nextion reported a buffer overflow!"

View file

@ -53,3 +53,6 @@ display:
on_page: on_page:
then: then:
lambda: 'ESP_LOGD("display","Display shows new page %u", x);' lambda: 'ESP_LOGD("display","Display shows new page %u", x);'
on_buffer_overflow:
then:
logger.log: "Nextion reported a buffer overflow!"

View file

@ -0,0 +1,19 @@
<<: !include common.yaml
spi:
- id: spi_main_lcd
clk_pin: 18
mosi_pin: 19
miso_pin: 16
display:
- platform: ili9xxx
id: main_lcd
model: ili9342
cs_pin: 20
dc_pin: 17
reset_pin: 21
invert_colors: true
lambda: |-
it.fill(Color(0, 0, 0));
it.image(0, 0, id(online_rgba_image));

View file

@ -0,0 +1,4 @@
<<: !include common-rp2040.yaml
http_request:
verify_ssl: false