mirror of
https://github.com/esphome/esphome.git
synced 2024-12-21 16:27:44 +01:00
unified way how all platforms handle get_download_types (#7617)
Co-authored-by: Tomasz Duda <tomaszduda23@gmai.com>
This commit is contained in:
parent
4fa3c6915c
commit
c20e1975d1
@ -7,6 +7,7 @@ import datetime
|
||||
import functools
|
||||
import gzip
|
||||
import hashlib
|
||||
import importlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@ -595,26 +596,18 @@ class DownloadListRequestHandler(BaseHandler):
|
||||
|
||||
downloads = []
|
||||
platform: str = storage_json.target_platform.lower()
|
||||
if platform == const.PLATFORM_RP2040:
|
||||
from esphome.components.rp2040 import get_download_types as rp2040_types
|
||||
|
||||
downloads = rp2040_types(storage_json)
|
||||
elif platform == const.PLATFORM_ESP8266:
|
||||
from esphome.components.esp8266 import get_download_types as esp8266_types
|
||||
|
||||
downloads = esp8266_types(storage_json)
|
||||
elif platform.upper() in ESP32_VARIANTS:
|
||||
from esphome.components.esp32 import get_download_types as esp32_types
|
||||
|
||||
downloads = esp32_types(storage_json)
|
||||
if platform.upper() in ESP32_VARIANTS:
|
||||
platform = "esp32"
|
||||
elif platform in (const.PLATFORM_RTL87XX, const.PLATFORM_BK72XX):
|
||||
from esphome.components.libretiny import (
|
||||
get_download_types as libretiny_types,
|
||||
)
|
||||
platform = "libretiny"
|
||||
|
||||
downloads = libretiny_types(storage_json)
|
||||
else:
|
||||
raise ValueError(f"Unknown platform {platform}")
|
||||
try:
|
||||
module = importlib.import_module(f"esphome.components.{platform}")
|
||||
get_download_types = getattr(module, "get_download_types")
|
||||
except AttributeError as exc:
|
||||
raise ValueError(f"Unknown platform {platform}") from exc
|
||||
downloads = get_download_types(storage_json)
|
||||
|
||||
self.set_status(200)
|
||||
self.set_header("content-type", "application/json")
|
||||
|
Loading…
Reference in New Issue
Block a user