mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 23:18:10 +01:00
Add API for dashboard to get boards list by platform (#4168)
* Add API for dashboard to get boards list by platform * Dashboard API: add board list for ESP32 S2/S3/C3 * Dashboard API: remove endpoint for all boards * Dashboard API: hide group titles for all platforms * Dashboard API: fix Python lint * Dashboard API: refactor /boards to use list output * Dashboard API: filter boards for selected platform * Dashboard API: do not duplicate esp32 boards Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
119a6920f2
commit
19bf9b1e36
2 changed files with 24 additions and 9 deletions
|
@ -995,6 +995,7 @@ KEY_TARGET_PLATFORM = "target_platform"
|
||||||
KEY_TARGET_FRAMEWORK = "target_framework"
|
KEY_TARGET_FRAMEWORK = "target_framework"
|
||||||
KEY_FRAMEWORK_VERSION = "framework_version"
|
KEY_FRAMEWORK_VERSION = "framework_version"
|
||||||
KEY_NAME = "name"
|
KEY_NAME = "name"
|
||||||
|
KEY_VARIANT = "variant"
|
||||||
|
|
||||||
# Entity categories
|
# Entity categories
|
||||||
ENTITY_CATEGORY_NONE = ""
|
ENTITY_CATEGORY_NONE = ""
|
||||||
|
|
|
@ -695,20 +695,34 @@ class PrometheusServiceDiscoveryHandler(BaseHandler):
|
||||||
|
|
||||||
class BoardsRequestHandler(BaseHandler):
|
class BoardsRequestHandler(BaseHandler):
|
||||||
@authenticated
|
@authenticated
|
||||||
def get(self):
|
def get(self, platform: str):
|
||||||
from esphome.components.esp32.boards import BOARDS as ESP32_BOARDS
|
from esphome.components.esp32.boards import BOARDS as ESP32_BOARDS
|
||||||
from esphome.components.esp8266.boards import BOARDS as ESP8266_BOARDS
|
from esphome.components.esp8266.boards import BOARDS as ESP8266_BOARDS
|
||||||
from esphome.components.rp2040.boards import BOARDS as RP2040_BOARDS
|
from esphome.components.rp2040.boards import BOARDS as RP2040_BOARDS
|
||||||
|
|
||||||
boards = {
|
platform_to_boards = {
|
||||||
"esp32": {key: val[const.KEY_NAME] for key, val in ESP32_BOARDS.items()},
|
"esp32": ESP32_BOARDS,
|
||||||
"esp8266": {
|
"esp8266": ESP8266_BOARDS,
|
||||||
key: val[const.KEY_NAME] for key, val in ESP8266_BOARDS.items()
|
"rp2040": RP2040_BOARDS,
|
||||||
},
|
|
||||||
"rp2040": {key: val[const.KEY_NAME] for key, val in RP2040_BOARDS.items()},
|
|
||||||
}
|
}
|
||||||
|
# filter all ESP32 variants by requested platform
|
||||||
|
if platform.startswith("esp32"):
|
||||||
|
boards = {
|
||||||
|
k: v
|
||||||
|
for k, v in platform_to_boards["esp32"].items()
|
||||||
|
if v[const.KEY_VARIANT] == platform.upper()
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
boards = platform_to_boards[platform]
|
||||||
|
|
||||||
|
# map to a {board_name: board_title} dict
|
||||||
|
platform_boards = {key: val[const.KEY_NAME] for key, val in boards.items()}
|
||||||
|
# sort by board title
|
||||||
|
boards_items = sorted(platform_boards.items(), key=lambda item: item[1])
|
||||||
|
output = [dict(items=dict(boards_items))]
|
||||||
|
|
||||||
self.set_header("content-type", "application/json")
|
self.set_header("content-type", "application/json")
|
||||||
self.write(json.dumps(boards))
|
self.write(json.dumps(output))
|
||||||
|
|
||||||
|
|
||||||
class MDNSStatusThread(threading.Thread):
|
class MDNSStatusThread(threading.Thread):
|
||||||
|
@ -1081,7 +1095,7 @@ def make_app(debug=get_bool_env(ENV_DEV)):
|
||||||
(f"{rel}json-config", JsonConfigRequestHandler),
|
(f"{rel}json-config", JsonConfigRequestHandler),
|
||||||
(f"{rel}rename", EsphomeRenameHandler),
|
(f"{rel}rename", EsphomeRenameHandler),
|
||||||
(f"{rel}prometheus-sd", PrometheusServiceDiscoveryHandler),
|
(f"{rel}prometheus-sd", PrometheusServiceDiscoveryHandler),
|
||||||
(f"{rel}boards", BoardsRequestHandler),
|
(f"{rel}boards/([a-z0-9]+)", BoardsRequestHandler),
|
||||||
],
|
],
|
||||||
**app_settings,
|
**app_settings,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue