unified way how all platforms handle get_download_types (#7617)

Co-authored-by: Tomasz Duda <tomaszduda23@gmai.com>
This commit is contained in:
tomaszduda23 2024-10-24 23:25:19 +02:00 committed by GitHub
parent 4fa3c6915c
commit c20e1975d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@ import datetime
import functools import functools
import gzip import gzip
import hashlib import hashlib
import importlib
import json import json
import logging import logging
import os import os
@ -595,26 +596,18 @@ class DownloadListRequestHandler(BaseHandler):
downloads = [] downloads = []
platform: str = storage_json.target_platform.lower() 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) if platform.upper() in ESP32_VARIANTS:
elif platform == const.PLATFORM_ESP8266: platform = "esp32"
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)
elif platform in (const.PLATFORM_RTL87XX, const.PLATFORM_BK72XX): elif platform in (const.PLATFORM_RTL87XX, const.PLATFORM_BK72XX):
from esphome.components.libretiny import ( platform = "libretiny"
get_download_types as libretiny_types,
)
downloads = libretiny_types(storage_json) try:
else: module = importlib.import_module(f"esphome.components.{platform}")
raise ValueError(f"Unknown platform {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_status(200)
self.set_header("content-type", "application/json") self.set_header("content-type", "application/json")