fix build error

This commit is contained in:
Tomasz Duda 2024-04-25 00:09:01 +02:00
parent 031dd54034
commit 6fa5b558a6
7 changed files with 28 additions and 23 deletions

View File

@ -8,6 +8,7 @@ from esphome.const import (
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)
@ -31,7 +32,7 @@ def _validate_mcumgr(config):
fconf = fv.full_config.get()
try:
bootloader = fconf.get_config_for_path(["nrf52", "bootloader"])
if bootloader != "adafruit":
if bootloader != BOOTLOADER_ADAFRUIT:
raise cv.Invalid(f"'{bootloader}' bootloader does not support DFU")
except KeyError:
pass

View File

@ -26,11 +26,11 @@ from esphome.components.zephyr.const import (
ZEPHYR_VARIANT_GENERIC,
ZEPHYR_VARIANT_NRF_SDK,
KEY_ZEPHYR,
KEY_BOOTLOADER,
BOOTLOADER_MCUBOOT,
)
from .boards_zephyr import BOARDS_ZEPHYR
from .const import (
KEY_BOOTLOADER,
BOOTLOADER_MCUBOOT,
BOOTLOADER_ADAFRUIT,
)
@ -130,8 +130,8 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(KEY_BOOTLOADER): cv.one_of(*BOOTLOADERS, lower=True),
}
),
set_core_data,
_detect_bootloader,
set_core_data,
)

View File

@ -1,7 +1,5 @@
from .const import (
BOOTLOADER_ADAFRUIT,
KEY_BOOTLOADER,
)
from .const import BOOTLOADER_ADAFRUIT
from esphome.components.zephyr.const import KEY_BOOTLOADER
BOARDS_ZEPHYR = {
"adafruit_itsybitsy_nrf52840": {KEY_BOOTLOADER: BOOTLOADER_ADAFRUIT},

View File

@ -1,3 +1 @@
KEY_BOOTLOADER = "bootloader"
BOOTLOADER_MCUBOOT = "mcuboot"
BOOTLOADER_ADAFRUIT = "adafruit"

View File

@ -16,6 +16,7 @@ from esphome.const import (
)
from esphome.core import CORE, coroutine_with_priority
import esphome.final_validate as fv
from esphome.components.zephyr.const import BOOTLOADER_MCUBOOT
CODEOWNERS = ["@esphome/core"]
@ -120,7 +121,7 @@ def _validate_mcumgr(config):
fconf = fv.full_config.get()
try:
bootloader = fconf.get_config_for_path(["nrf52", "bootloader"])
if bootloader != "mcuboot":
if bootloader != BOOTLOADER_MCUBOOT:
raise cv.Invalid(f"'{bootloader}' bootloader does not support OTA")
except KeyError:
pass

View File

@ -15,18 +15,22 @@ from .const import (
KEY_PRJ_CONF,
KEY_OVERLAY,
zephyr_ns,
BOOTLOADER_MCUBOOT,
)
AUTO_LOAD = ["preferences"]
KEY_BOARD = "board"
KEY_BOOTLOADER = "bootloader"
def zephyr_set_core_data(config):
CORE.data[KEY_ZEPHYR] = {}
CORE.data[KEY_ZEPHYR][KEY_BOARD] = config[CONF_BOARD]
CORE.data[KEY_ZEPHYR][KEY_PRJ_CONF] = {}
CORE.data[KEY_ZEPHYR][KEY_OVERLAY] = ""
CORE.data[KEY_ZEPHYR][KEY_BOOTLOADER] = config[KEY_BOOTLOADER]
return config
@ -131,21 +135,22 @@ def zephyr_copy_files():
CORE.data[KEY_ZEPHYR][KEY_OVERLAY],
)
fake_board_manifest = """
if CORE.data[KEY_ZEPHYR][KEY_BOOTLOADER] == BOOTLOADER_MCUBOOT:
fake_board_manifest = """
{
"frameworks": [
"frameworks": [
"zephyr"
],
"name": "esphome nrf52",
"upload": {
],
"name": "esphome nrf52",
"upload": {
"maximum_ram_size": 248832,
"maximum_size": 815104
},
"url": "https://esphome.io/",
"vendor": "esphome"
},
"url": "https://esphome.io/",
"vendor": "esphome"
}
"""
write_file_if_changed(
CORE.relative_build_path(f"boards/{CORE.data[KEY_ZEPHYR][KEY_BOARD]}.json"),
fake_board_manifest,
)
write_file_if_changed(
CORE.relative_build_path(f"boards/{CORE.data[KEY_ZEPHYR][KEY_BOARD]}.json"),
fake_board_manifest,
)

View File

@ -5,5 +5,7 @@ ZEPHYR_VARIANT_NRF_SDK = "nrf-sdk"
KEY_ZEPHYR = "zephyr"
KEY_PRJ_CONF = "prj_conf"
KEY_OVERLAY = "overlay"
KEY_BOOTLOADER = "bootloader"
BOOTLOADER_MCUBOOT = "mcuboot"
zephyr_ns = cg.esphome_ns.namespace("zephyr")