1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-09 04:10:35 +01:00

add tests

This commit is contained in:
Tomasz Duda 2024-05-06 20:37:50 +02:00
parent 0ff7710c6a
commit 5796b0e4bf
17 changed files with 90 additions and 21 deletions

View File

@ -5,10 +5,7 @@ from esphome.const import (
CONF_ID,
)
from esphome.core import CORE
from esphome.components.zephyr import zephyr_add_prj_conf
import esphome.final_validate as fv
from esphome.components.nrf52.const import BOOTLOADER_ADAFRUIT
dfu_ns = cg.esphome_ns.namespace("dfu")
DeviceFirmwareUpdate = dfu_ns.class_("DeviceFirmwareUpdate", cg.Component)
@ -26,21 +23,6 @@ CONFIG_SCHEMA = cv.All(
)
# TODO move this to common place with OTA
def _validate_mcumgr(config):
if CORE.using_zephyr:
fconf = fv.full_config.get()
try:
bootloader = fconf.get_config_for_path(["nrf52", "bootloader"])
if bootloader != BOOTLOADER_ADAFRUIT:
raise cv.Invalid(f"'{bootloader}' bootloader does not support DFU")
except KeyError:
pass
FINAL_VALIDATE_SCHEMA = _validate_mcumgr
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
reset_output = await cg.get_variable(config[CONF_RESET_OUTPUT])

View File

@ -1,3 +1,4 @@
#ifdef USE_NRF52
#include "dfu.h"
#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
@ -15,7 +16,7 @@ static uint32_t *dbl_reset_mem = ((uint32_t *) 0x20007F7C);
const struct device *cdc_dev[] = {DT_FOREACH_STATUS_OKAY(zephyr_cdc_acm_uart, DEVICE_AND_COMMA)};
static void cdc_dte_rate_callback(const struct device *, uint32_t rate) {
static void cdc_dte_rate_callback(const struct device * /*unused*/, uint32_t rate) {
if (rate == 1200) {
goto_dfu = true;
}
@ -30,6 +31,7 @@ void DeviceFirmwareUpdate::setup() {
void DeviceFirmwareUpdate::loop() {
if (goto_dfu) {
goto_dfu = false;
// TODO this is not required for mcuboot
(*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
reset_output_->set_state(true);
}
@ -37,3 +39,4 @@ void DeviceFirmwareUpdate::loop() {
} // namespace dfu
} // namespace esphome
#endif

View File

@ -1,4 +1,5 @@
#pragma once
#ifdef USE_NRF52
#include "esphome/core/defines.h"
#include "esphome/core/component.h"
#ifdef USE_OUTPUT
@ -21,3 +22,4 @@ class DeviceFirmwareUpdate : public Component {
};
} // namespace dfu
} // namespace esphome
#endif

View File

@ -1,3 +1,4 @@
#ifdef USE_ZEPHYR
#include "ble_nus.h"
#include <zephyr/kernel.h>
#include <bluetooth/services/nus.h>
@ -139,3 +140,4 @@ void BLENUS::loop() {
} // namespace zephyr_ble_nus
} // namespace esphome
#endif

View File

@ -1,5 +1,5 @@
#pragma once
#ifdef USE_ZEPHYR
#include "esphome/core/defines.h"
#include "esphome/core/component.h"
#include <zephyr/sys/ring_buffer.h>
@ -38,3 +38,4 @@ class BLENUS : public Component {
} // namespace zephyr_ble_nus
} // namespace esphome
#endif

View File

@ -1,3 +1,4 @@
#ifdef USE_ZEPHYR
#include "ble_server.h"
#include "esphome/core/defines.h"
#include "esphome/core/log.h"
@ -77,3 +78,5 @@ void BLEServer::setup() {
} // namespace zephyr_ble_server
} // namespace esphome
#endif

View File

@ -1,5 +1,5 @@
#pragma once
#ifdef USE_ZEPHYR
#include "esphome/core/component.h"
namespace esphome {
@ -12,3 +12,4 @@ class BLEServer : public Component {
} // namespace zephyr_ble_server
} // namespace esphome
#endif

View File

@ -0,0 +1,11 @@
output:
- platform: gpio
pin:
number: 14
inverted: true
mode:
output: true
id: rest_gpio
dfu:
reset_output: rest_gpio

View File

@ -0,0 +1,11 @@
output:
- platform: gpio
pin:
number: 14
inverted: true
mode:
output: true
id: rest_gpio
dfu:
reset_output: rest_gpio

View File

@ -0,0 +1,7 @@
esphome:
on_boot:
then:
- logger.log: Hello world
logger:
level: DEBUG

View File

@ -0,0 +1,7 @@
esphome:
on_boot:
then:
- logger.log: Hello world
logger:
level: DEBUG

View File

@ -0,0 +1,26 @@
zephyr_ble_server:
ota:
safe_mode: true
reboot_timeout: 2min
num_attempts: 5
on_begin:
then:
- logger.log: "OTA start"
on_progress:
then:
- logger.log:
format: "OTA progress %0.1f%%"
args: ["x"]
on_end:
then:
- logger.log: "OTA end"
on_error:
then:
- logger.log:
format: "OTA update error %d"
args: ["x"]
on_state_change:
then:
lambda: >-
ESP_LOGD("ota", "State %d", state);

View File

@ -0,0 +1,4 @@
zephyr_ble_server:
zephyr_ble_nus:
log: true

View File

@ -0,0 +1,4 @@
zephyr_ble_server:
zephyr_ble_nus:
log: true

View File

@ -0,0 +1 @@
zephyr_ble_server:

View File

@ -0,0 +1 @@
zephyr_ble_server:

View File

@ -40,6 +40,9 @@ output:
output: true
id: rest_gpio
dfu:
reset_output: rest_gpio
ota:
safe_mode: true
on_begin: