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

Add API for dashboard to get boards list (#4154)

This commit is contained in:
Jesse Hills
2022-12-07 16:07:51 +13:00
committed by GitHub
parent f843925301
commit 6ad9baa870
9 changed files with 960 additions and 234 deletions

View File

@@ -22,10 +22,11 @@ from .const import (
CONF_EARLY_PIN_INIT,
KEY_BOARD,
KEY_ESP8266,
KEY_FLASH_SIZE,
KEY_PIN_INITIAL_STATES,
esp8266_ns,
)
from .boards import ESP8266_FLASH_SIZES, ESP8266_LD_SCRIPTS
from .boards import BOARDS, ESP8266_LD_SCRIPTS
from .gpio import PinInitialState, add_pin_initial_states_array
@@ -218,8 +219,8 @@ async def to_code(config):
cg.RawExpression(f"VERSION_CODE({ver.major}, {ver.minor}, {ver.patch})"),
)
if config[CONF_BOARD] in ESP8266_FLASH_SIZES:
flash_size = ESP8266_FLASH_SIZES[config[CONF_BOARD]]
if config[CONF_BOARD] in BOARDS:
flash_size = BOARDS[config[CONF_BOARD]][KEY_FLASH_SIZE]
ld_scripts = ESP8266_LD_SCRIPTS[flash_size]
if ver <= cv.Version(2, 3, 0):

View File

@@ -4,50 +4,6 @@ FLASH_SIZE_2_MB = 2 * FLASH_SIZE_1_MB
FLASH_SIZE_4_MB = 4 * FLASH_SIZE_1_MB
FLASH_SIZE_16_MB = 16 * FLASH_SIZE_1_MB
ESP8266_FLASH_SIZES = {
"d1": FLASH_SIZE_4_MB,
"d1_mini": FLASH_SIZE_4_MB,
"d1_mini_lite": FLASH_SIZE_1_MB,
"d1_mini_pro": FLASH_SIZE_16_MB,
"esp01": FLASH_SIZE_512_KB,
"esp01_1m": FLASH_SIZE_1_MB,
"esp07": FLASH_SIZE_4_MB,
"esp12e": FLASH_SIZE_4_MB,
"esp210": FLASH_SIZE_4_MB,
"esp8285": FLASH_SIZE_1_MB,
"esp_wroom_02": FLASH_SIZE_2_MB,
"espduino": FLASH_SIZE_4_MB,
"espectro": FLASH_SIZE_4_MB,
"espino": FLASH_SIZE_4_MB,
"espinotee": FLASH_SIZE_4_MB,
"espmxdevkit": FLASH_SIZE_1_MB,
"espresso_lite_v1": FLASH_SIZE_4_MB,
"espresso_lite_v2": FLASH_SIZE_4_MB,
"gen4iod": FLASH_SIZE_512_KB,
"heltec_wifi_kit_8": FLASH_SIZE_4_MB,
"huzzah": FLASH_SIZE_4_MB,
"inventone": FLASH_SIZE_4_MB,
"modwifi": FLASH_SIZE_2_MB,
"nodemcu": FLASH_SIZE_4_MB,
"nodemcuv2": FLASH_SIZE_4_MB,
"oak": FLASH_SIZE_4_MB,
"phoenix_v1": FLASH_SIZE_4_MB,
"phoenix_v2": FLASH_SIZE_4_MB,
"sonoff_basic": FLASH_SIZE_1_MB,
"sonoff_s20": FLASH_SIZE_1_MB,
"sonoff_sv": FLASH_SIZE_1_MB,
"sonoff_th": FLASH_SIZE_1_MB,
"sparkfunBlynk": FLASH_SIZE_4_MB,
"thing": FLASH_SIZE_512_KB,
"thingdev": FLASH_SIZE_512_KB,
"wifi_slot": FLASH_SIZE_1_MB,
"wifiduino": FLASH_SIZE_4_MB,
"wifinfo": FLASH_SIZE_1_MB,
"wio_link": FLASH_SIZE_4_MB,
"wio_node": FLASH_SIZE_4_MB,
"xinabox_cw01": FLASH_SIZE_4_MB,
}
ESP8266_LD_SCRIPTS = {
FLASH_SIZE_512_KB: ("eagle.flash.512k0.ld", "eagle.flash.512k.ld"),
FLASH_SIZE_1_MB: ("eagle.flash.1m0.ld", "eagle.flash.1m.ld"),
@@ -206,3 +162,201 @@ ESP8266_BOARD_PINS = {
"wio_node": {"LED": 2, "GROVE": 15, "D0": 3, "D1": 5, "BUTTON": 0},
"xinabox_cw01": {"SDA": 2, "SCL": 14, "LED": 5, "LED_RED": 12, "LED_GREEN": 13},
}
"""
BOARDS generate with:
git clone https://github.com/platformio/platform-espressif8266
for x in platform-espressif8266/boards/*.json; do
max_size=$(jq -r .upload.maximum_size <"$x")
name=$(jq -r .name <"$x")
fname=$(basename "$x")
board="${fname%.*}"
size_mb=$((max_size / (1024 * 1024)))
if [[ $size_mb -gt 0 ]]; then
size="${size_mb}_MB"
else
size="${$((max_size / 1024))}_KB"
fi
echo " \"$board\": {\"name\": \"$name\", \"flash_size\": FLASH_SIZE_$size,},"
done | sort
"""
BOARDS = {
"agruminolemon": {
"name": "Lifely Agrumino Lemon v4",
"flash_size": FLASH_SIZE_4_MB,
},
"d1_mini_lite": {
"name": "WeMos D1 mini Lite",
"flash_size": FLASH_SIZE_1_MB,
},
"d1_mini": {
"name": "WeMos D1 R2 and mini",
"flash_size": FLASH_SIZE_4_MB,
},
"d1_mini_pro": {
"name": "WeMos D1 mini Pro",
"flash_size": FLASH_SIZE_16_MB,
},
"d1": {
"name": "WEMOS D1 R1",
"flash_size": FLASH_SIZE_4_MB,
},
"eduinowifi": {
"name": "Schirmilabs Eduino WiFi",
"flash_size": FLASH_SIZE_4_MB,
},
"esp01_1m": {
"name": "Espressif Generic ESP8266 ESP-01 1M",
"flash_size": FLASH_SIZE_1_MB,
},
"esp01": {
"name": "Espressif Generic ESP8266 ESP-01 512k",
"flash_size": FLASH_SIZE_512_KB,
},
"esp07": {
"name": "Espressif Generic ESP8266 ESP-07 1MB",
"flash_size": FLASH_SIZE_1_MB,
},
"esp07s": {
"name": "Espressif Generic ESP8266 ESP-07S",
"flash_size": FLASH_SIZE_4_MB,
},
"esp12e": {
"name": "Espressif ESP8266 ESP-12E",
"flash_size": FLASH_SIZE_4_MB,
},
"esp210": {
"name": "SweetPea ESP-210",
"flash_size": FLASH_SIZE_4_MB,
},
"esp8285": {
"name": "Generic ESP8285 Module",
"flash_size": FLASH_SIZE_1_MB,
},
"espduino": {
"name": "ESPDuino (ESP-13 Module)",
"flash_size": FLASH_SIZE_4_MB,
},
"espectro": {
"name": "ESPectro Core",
"flash_size": FLASH_SIZE_4_MB,
},
"espino": {
"name": "ESPino",
"flash_size": FLASH_SIZE_4_MB,
},
"espinotee": {
"name": "ThaiEasyElec ESPino",
"flash_size": FLASH_SIZE_4_MB,
},
"espmxdevkit": {
"name": "ESP-Mx DevKit (ESP8285)",
"flash_size": FLASH_SIZE_1_MB,
},
"espresso_lite_v1": {
"name": "ESPresso Lite 1.0",
"flash_size": FLASH_SIZE_4_MB,
},
"espresso_lite_v2": {
"name": "ESPresso Lite 2.0",
"flash_size": FLASH_SIZE_4_MB,
},
"esp_wroom_02": {
"name": "ESP-WROOM-02",
"flash_size": FLASH_SIZE_2_MB,
},
"gen4iod": {
"name": "4D Systems gen4 IoD Range",
"flash_size": FLASH_SIZE_512_KB,
},
"heltec_wifi_kit_8": {
"name": "Heltec Wifi kit 8",
"flash_size": FLASH_SIZE_4_MB,
},
"huzzah": {
"name": "Adafruit HUZZAH ESP8266",
"flash_size": FLASH_SIZE_4_MB,
},
"inventone": {
"name": "Invent One",
"flash_size": FLASH_SIZE_4_MB,
},
"modwifi": {
"name": "Olimex MOD-WIFI-ESP8266(-DEV)",
"flash_size": FLASH_SIZE_2_MB,
},
"nodemcu": {
"name": "NodeMCU 0.9 (ESP-12 Module)",
"flash_size": FLASH_SIZE_4_MB,
},
"nodemcuv2": {
"name": "NodeMCU 1.0 (ESP-12E Module)",
"flash_size": FLASH_SIZE_4_MB,
},
"oak": {
"name": "DigiStump Oak",
"flash_size": FLASH_SIZE_4_MB,
},
"phoenix_v1": {
"name": "Phoenix 1.0",
"flash_size": FLASH_SIZE_4_MB,
},
"phoenix_v2": {
"name": "Phoenix 2.0",
"flash_size": FLASH_SIZE_4_MB,
},
"sonoff_basic": {
"name": "Sonoff Basic",
"flash_size": FLASH_SIZE_1_MB,
},
"sonoff_s20": {
"name": "Sonoff S20",
"flash_size": FLASH_SIZE_1_MB,
},
"sonoff_sv": {
"name": "Sonoff SV",
"flash_size": FLASH_SIZE_1_MB,
},
"sonoff_th": {
"name": "Sonoff TH",
"flash_size": FLASH_SIZE_1_MB,
},
"sparkfunBlynk": {
"name": "SparkFun Blynk Board",
"flash_size": FLASH_SIZE_4_MB,
},
"thingdev": {
"name": "SparkFun ESP8266 Thing Dev",
"flash_size": FLASH_SIZE_512_KB,
},
"thing": {
"name": "SparkFun ESP8266 Thing",
"flash_size": FLASH_SIZE_512_KB,
},
"wifiduino": {
"name": "WiFiduino",
"flash_size": FLASH_SIZE_4_MB,
},
"wifinfo": {
"name": "WifInfo",
"flash_size": FLASH_SIZE_1_MB,
},
"wifi_slot": {
"name": "WiFi Slot",
"flash_size": FLASH_SIZE_4_MB,
},
"wio_link": {
"name": "Wio Link",
"flash_size": FLASH_SIZE_4_MB,
},
"wio_node": {
"name": "Wio Node",
"flash_size": FLASH_SIZE_4_MB,
},
"xinabox_cw01": {
"name": "XinaBox CW01",
"flash_size": FLASH_SIZE_4_MB,
},
}

View File

@@ -5,6 +5,7 @@ KEY_BOARD = "board"
KEY_PIN_INITIAL_STATES = "pin_initial_states"
CONF_RESTORE_FROM_FLASH = "restore_from_flash"
CONF_EARLY_PIN_INIT = "early_pin_init"
KEY_FLASH_SIZE = "flash_size"
# esp8266 namespace is already defined by arduino, manually prefix esphome
esp8266_ns = cg.global_ns.namespace("esphome").namespace("esp8266")