mirror of
https://github.com/esphome/esphome.git
synced 2025-09-04 04:12:23 +01:00
add tests
This commit is contained in:
@@ -5,10 +5,7 @@ from esphome.const import (
|
|||||||
CONF_ID,
|
CONF_ID,
|
||||||
)
|
)
|
||||||
|
|
||||||
from esphome.core import CORE
|
|
||||||
from esphome.components.zephyr import zephyr_add_prj_conf
|
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")
|
dfu_ns = cg.esphome_ns.namespace("dfu")
|
||||||
DeviceFirmwareUpdate = dfu_ns.class_("DeviceFirmwareUpdate", cg.Component)
|
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):
|
async def to_code(config):
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
reset_output = await cg.get_variable(config[CONF_RESET_OUTPUT])
|
reset_output = await cg.get_variable(config[CONF_RESET_OUTPUT])
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
#ifdef USE_NRF52
|
||||||
#include "dfu.h"
|
#include "dfu.h"
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/drivers/uart.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)};
|
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) {
|
if (rate == 1200) {
|
||||||
goto_dfu = true;
|
goto_dfu = true;
|
||||||
}
|
}
|
||||||
@@ -30,6 +31,7 @@ void DeviceFirmwareUpdate::setup() {
|
|||||||
void DeviceFirmwareUpdate::loop() {
|
void DeviceFirmwareUpdate::loop() {
|
||||||
if (goto_dfu) {
|
if (goto_dfu) {
|
||||||
goto_dfu = false;
|
goto_dfu = false;
|
||||||
|
// TODO this is not required for mcuboot
|
||||||
(*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
|
(*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
|
||||||
reset_output_->set_state(true);
|
reset_output_->set_state(true);
|
||||||
}
|
}
|
||||||
@@ -37,3 +39,4 @@ void DeviceFirmwareUpdate::loop() {
|
|||||||
|
|
||||||
} // namespace dfu
|
} // namespace dfu
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#ifdef USE_NRF52
|
||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#ifdef USE_OUTPUT
|
#ifdef USE_OUTPUT
|
||||||
@@ -21,3 +22,4 @@ class DeviceFirmwareUpdate : public Component {
|
|||||||
};
|
};
|
||||||
} // namespace dfu
|
} // namespace dfu
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
#ifdef USE_ZEPHYR
|
||||||
#include "ble_nus.h"
|
#include "ble_nus.h"
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <bluetooth/services/nus.h>
|
#include <bluetooth/services/nus.h>
|
||||||
@@ -139,3 +140,4 @@ void BLENUS::loop() {
|
|||||||
|
|
||||||
} // namespace zephyr_ble_nus
|
} // namespace zephyr_ble_nus
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#ifdef USE_ZEPHYR
|
||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include <zephyr/sys/ring_buffer.h>
|
#include <zephyr/sys/ring_buffer.h>
|
||||||
@@ -38,3 +38,4 @@ class BLENUS : public Component {
|
|||||||
|
|
||||||
} // namespace zephyr_ble_nus
|
} // namespace zephyr_ble_nus
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
#ifdef USE_ZEPHYR
|
||||||
#include "ble_server.h"
|
#include "ble_server.h"
|
||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
@@ -77,3 +78,5 @@ void BLEServer::setup() {
|
|||||||
|
|
||||||
} // namespace zephyr_ble_server
|
} // namespace zephyr_ble_server
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#ifdef USE_ZEPHYR
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
@@ -12,3 +12,4 @@ class BLEServer : public Component {
|
|||||||
|
|
||||||
} // namespace zephyr_ble_server
|
} // namespace zephyr_ble_server
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
11
tests/components/dfu/test.nrf52-adafruit.yaml
Normal file
11
tests/components/dfu/test.nrf52-adafruit.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
output:
|
||||||
|
- platform: gpio
|
||||||
|
pin:
|
||||||
|
number: 14
|
||||||
|
inverted: true
|
||||||
|
mode:
|
||||||
|
output: true
|
||||||
|
id: rest_gpio
|
||||||
|
|
||||||
|
dfu:
|
||||||
|
reset_output: rest_gpio
|
11
tests/components/dfu/test.nrf52.yaml
Normal file
11
tests/components/dfu/test.nrf52.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
output:
|
||||||
|
- platform: gpio
|
||||||
|
pin:
|
||||||
|
number: 14
|
||||||
|
inverted: true
|
||||||
|
mode:
|
||||||
|
output: true
|
||||||
|
id: rest_gpio
|
||||||
|
|
||||||
|
dfu:
|
||||||
|
reset_output: rest_gpio
|
7
tests/components/logger/test.nrf52-adafruit.yaml
Normal file
7
tests/components/logger/test.nrf52-adafruit.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
esphome:
|
||||||
|
on_boot:
|
||||||
|
then:
|
||||||
|
- logger.log: Hello world
|
||||||
|
|
||||||
|
logger:
|
||||||
|
level: DEBUG
|
7
tests/components/logger/test.nrf52.yaml
Normal file
7
tests/components/logger/test.nrf52.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
esphome:
|
||||||
|
on_boot:
|
||||||
|
then:
|
||||||
|
- logger.log: Hello world
|
||||||
|
|
||||||
|
logger:
|
||||||
|
level: DEBUG
|
26
tests/components/ota/test.nrf52.yaml
Normal file
26
tests/components/ota/test.nrf52.yaml
Normal 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);
|
4
tests/components/zephyr_ble_nus/test.nrf52-adafruit.yaml
Normal file
4
tests/components/zephyr_ble_nus/test.nrf52-adafruit.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
zephyr_ble_server:
|
||||||
|
|
||||||
|
zephyr_ble_nus:
|
||||||
|
log: true
|
4
tests/components/zephyr_ble_nus/test.nrf52.yaml
Normal file
4
tests/components/zephyr_ble_nus/test.nrf52.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
zephyr_ble_server:
|
||||||
|
|
||||||
|
zephyr_ble_nus:
|
||||||
|
log: true
|
@@ -0,0 +1 @@
|
|||||||
|
zephyr_ble_server:
|
1
tests/components/zephyr_ble_server/test.nrf52.yaml
Normal file
1
tests/components/zephyr_ble_server/test.nrf52.yaml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
zephyr_ble_server:
|
@@ -40,6 +40,9 @@ output:
|
|||||||
output: true
|
output: true
|
||||||
id: rest_gpio
|
id: rest_gpio
|
||||||
|
|
||||||
|
dfu:
|
||||||
|
reset_output: rest_gpio
|
||||||
|
|
||||||
ota:
|
ota:
|
||||||
safe_mode: true
|
safe_mode: true
|
||||||
on_begin:
|
on_begin:
|
||||||
|
Reference in New Issue
Block a user