mirror of
https://github.com/esphome/esphome.git
synced 2025-02-18 01:03:12 +01:00
Add ESP32C3 and ESP32S2 support to dashboard (#3152)
* Add ESP32C3 and ESP32S2 support to dashboard * Format * Fix tests
This commit is contained in:
parent
b8d10a62c2
commit
debcaf6fb7
4 changed files with 50 additions and 19 deletions
|
@ -61,8 +61,8 @@ def set_core_data(config):
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def get_esp32_variant():
|
def get_esp32_variant(core_obj=None):
|
||||||
return CORE.data[KEY_ESP32][KEY_VARIANT]
|
return (core_obj or CORE).data[KEY_ESP32][KEY_VARIANT]
|
||||||
|
|
||||||
|
|
||||||
def only_on_variant(*, supported=None, unsupported=None):
|
def only_on_variant(*, supported=None, unsupported=None):
|
||||||
|
|
|
@ -64,7 +64,7 @@ class StorageJSON:
|
||||||
# Web server port of the ESP, for example 80
|
# Web server port of the ESP, for example 80
|
||||||
assert web_port is None or isinstance(web_port, int)
|
assert web_port is None or isinstance(web_port, int)
|
||||||
self.web_port = web_port # type: 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
|
self.target_platform = target_platform # type: str
|
||||||
# The absolute path to the platformio project
|
# The absolute path to the platformio project
|
||||||
self.build_path = build_path # type: str
|
self.build_path = build_path # type: str
|
||||||
|
@ -99,6 +99,11 @@ class StorageJSON:
|
||||||
def from_esphome_core(
|
def from_esphome_core(
|
||||||
esph, old
|
esph, old
|
||||||
): # type: (CoreType, Optional[StorageJSON]) -> StorageJSON
|
): # 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(
|
return StorageJSON(
|
||||||
storage_version=1,
|
storage_version=1,
|
||||||
name=esph.name,
|
name=esph.name,
|
||||||
|
@ -107,15 +112,14 @@ class StorageJSON:
|
||||||
src_version=1,
|
src_version=1,
|
||||||
address=esph.address,
|
address=esph.address,
|
||||||
web_port=esph.web_port,
|
web_port=esph.web_port,
|
||||||
target_platform=esph.target_platform,
|
target_platform=hardware,
|
||||||
build_path=esph.build_path,
|
build_path=esph.build_path,
|
||||||
firmware_bin_path=esph.firmware_bin,
|
firmware_bin_path=esph.firmware_bin,
|
||||||
loaded_integrations=list(esph.loaded_integrations),
|
loaded_integrations=list(esph.loaded_integrations),
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_wizard(name, address, esp_platform):
|
def from_wizard(name: str, address: str, esp_platform: str) -> "StorageJSON":
|
||||||
# type: (str, str, str) -> StorageJSON
|
|
||||||
return StorageJSON(
|
return StorageJSON(
|
||||||
storage_version=1,
|
storage_version=1,
|
||||||
name=name,
|
name=name,
|
||||||
|
|
|
@ -67,6 +67,27 @@ esp32:
|
||||||
type: arduino
|
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):
|
def sanitize_double_quotes(value):
|
||||||
return value.replace("\\", "\\\\").replace('"', '\\"')
|
return value.replace("\\", "\\\\").replace('"', '\\"')
|
||||||
|
@ -83,11 +104,7 @@ def wizard_file(**kwargs):
|
||||||
|
|
||||||
config = BASE_CONFIG.format(**kwargs)
|
config = BASE_CONFIG.format(**kwargs)
|
||||||
|
|
||||||
config += (
|
config += HARDWARE_BASE_CONFIGS[kwargs["platform"]].format(**kwargs)
|
||||||
ESP8266_CONFIG.format(**kwargs)
|
|
||||||
if kwargs["platform"] == "ESP8266"
|
|
||||||
else ESP32_CONFIG.format(**kwargs)
|
|
||||||
)
|
|
||||||
|
|
||||||
config += LOGGER_API_CONFIG
|
config += LOGGER_API_CONFIG
|
||||||
|
|
||||||
|
@ -119,6 +136,7 @@ def wizard_file(**kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# pylint: disable=consider-using-f-string
|
# pylint: disable=consider-using-f-string
|
||||||
|
if kwargs["platform"] in ["ESP8266", "ESP32"]:
|
||||||
config += """
|
config += """
|
||||||
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
||||||
ap:
|
ap:
|
||||||
|
@ -126,6 +144,15 @@ def wizard_file(**kwargs):
|
||||||
password: "{fallback_psk}"
|
password: "{fallback_psk}"
|
||||||
|
|
||||||
captive_portal:
|
captive_portal:
|
||||||
|
""".format(
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
config += """
|
||||||
|
# Enable fallback hotspot in case wifi connection fails
|
||||||
|
ap:
|
||||||
|
ssid: "{fallback_name}"
|
||||||
|
password: "{fallback_psk}"
|
||||||
""".format(
|
""".format(
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
@ -147,10 +174,10 @@ def wizard_write(path, **kwargs):
|
||||||
kwargs["platform"] = (
|
kwargs["platform"] = (
|
||||||
"ESP8266" if board in esp8266_boards.ESP8266_BOARD_PINS else "ESP32"
|
"ESP8266" if board in esp8266_boards.ESP8266_BOARD_PINS else "ESP32"
|
||||||
)
|
)
|
||||||
platform = kwargs["platform"]
|
hardware = kwargs["platform"]
|
||||||
|
|
||||||
write_file(path, wizard_file(**kwargs))
|
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_path = ext_storage_path(os.path.dirname(path), os.path.basename(path))
|
||||||
storage.save(storage_path)
|
storage.save(storage_path)
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
import esphome.wizard as wz
|
import esphome.wizard as wz
|
||||||
import pytest
|
import pytest
|
||||||
from esphome.components.esp8266.boards import ESP8266_BOARD_PINS
|
from esphome.components.esp8266.boards import ESP8266_BOARD_PINS
|
||||||
from mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def default_config():
|
def default_config():
|
||||||
return {
|
return {
|
||||||
"name": "test-name",
|
"name": "test-name",
|
||||||
"platform": "test_platform",
|
"platform": "ESP8266",
|
||||||
"board": "esp01_1m",
|
"board": "esp01_1m",
|
||||||
"ssid": "test_ssid",
|
"ssid": "test_ssid",
|
||||||
"psk": "test_psk",
|
"psk": "test_psk",
|
||||||
|
|
Loading…
Add table
Reference in a new issue