Add ESP32C3 and ESP32S2 support to dashboard (#3152)

* Add ESP32C3 and ESP32S2 support to dashboard

* Format

* Fix tests
This commit is contained in:
Otto Winter 2022-02-19 15:47:50 +01:00 committed by GitHub
parent b8d10a62c2
commit debcaf6fb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 19 deletions

View file

@ -61,8 +61,8 @@ def set_core_data(config):
return config
def get_esp32_variant():
return CORE.data[KEY_ESP32][KEY_VARIANT]
def get_esp32_variant(core_obj=None):
return (core_obj or CORE).data[KEY_ESP32][KEY_VARIANT]
def only_on_variant(*, supported=None, unsupported=None):

View file

@ -64,7 +64,7 @@ class StorageJSON:
# Web server port of the ESP, for example 80
assert web_port is None or isinstance(web_port, int)
self.web_port = web_port # type: int
# The type of ESP in use, either ESP32 or ESP8266
# The type of hardware in use, like "ESP32", "ESP32C3", "ESP8266", etc.
self.target_platform = target_platform # type: str
# The absolute path to the platformio project
self.build_path = build_path # type: str
@ -99,6 +99,11 @@ class StorageJSON:
def from_esphome_core(
esph, old
): # type: (CoreType, Optional[StorageJSON]) -> StorageJSON
hardware = esph.target_platform
if esph.is_esp32:
from esphome.components import esp32
hardware = esp32.get_esp32_variant(esph)
return StorageJSON(
storage_version=1,
name=esph.name,
@ -107,15 +112,14 @@ class StorageJSON:
src_version=1,
address=esph.address,
web_port=esph.web_port,
target_platform=esph.target_platform,
target_platform=hardware,
build_path=esph.build_path,
firmware_bin_path=esph.firmware_bin,
loaded_integrations=list(esph.loaded_integrations),
)
@staticmethod
def from_wizard(name, address, esp_platform):
# type: (str, str, str) -> StorageJSON
def from_wizard(name: str, address: str, esp_platform: str) -> "StorageJSON":
return StorageJSON(
storage_version=1,
name=name,

View file

@ -67,6 +67,27 @@ esp32:
type: arduino
"""
ESP32S2_CONFIG = """
esp32:
board: {board}
framework:
type: esp-idf
"""
ESP32C3_CONFIG = """
esp32:
board: {board}
framework:
type: esp-idf
"""
HARDWARE_BASE_CONFIGS = {
"ESP8266": ESP8266_CONFIG,
"ESP32": ESP32_CONFIG,
"ESP32S2": ESP32S2_CONFIG,
"ESP32C3": ESP32C3_CONFIG,
}
def sanitize_double_quotes(value):
return value.replace("\\", "\\\\").replace('"', '\\"')
@ -83,11 +104,7 @@ def wizard_file(**kwargs):
config = BASE_CONFIG.format(**kwargs)
config += (
ESP8266_CONFIG.format(**kwargs)
if kwargs["platform"] == "ESP8266"
else ESP32_CONFIG.format(**kwargs)
)
config += HARDWARE_BASE_CONFIGS[kwargs["platform"]].format(**kwargs)
config += LOGGER_API_CONFIG
@ -119,6 +136,7 @@ def wizard_file(**kwargs):
"""
# pylint: disable=consider-using-f-string
if kwargs["platform"] in ["ESP8266", "ESP32"]:
config += """
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
@ -126,6 +144,15 @@ def wizard_file(**kwargs):
password: "{fallback_psk}"
captive_portal:
""".format(
**kwargs
)
else:
config += """
# Enable fallback hotspot in case wifi connection fails
ap:
ssid: "{fallback_name}"
password: "{fallback_psk}"
""".format(
**kwargs
)
@ -147,10 +174,10 @@ def wizard_write(path, **kwargs):
kwargs["platform"] = (
"ESP8266" if board in esp8266_boards.ESP8266_BOARD_PINS else "ESP32"
)
platform = kwargs["platform"]
hardware = kwargs["platform"]
write_file(path, wizard_file(**kwargs))
storage = StorageJSON.from_wizard(name, f"{name}.local", platform)
storage = StorageJSON.from_wizard(name, f"{name}.local", hardware)
storage_path = ext_storage_path(os.path.dirname(path), os.path.basename(path))
storage.save(storage_path)

View file

@ -3,14 +3,14 @@
import esphome.wizard as wz
import pytest
from esphome.components.esp8266.boards import ESP8266_BOARD_PINS
from mock import MagicMock
from unittest.mock import MagicMock
@pytest.fixture
def default_config():
return {
"name": "test-name",
"platform": "test_platform",
"platform": "ESP8266",
"board": "esp01_1m",
"ssid": "test_ssid",
"psk": "test_psk",