mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 01:08:03 +01:00
Use new platform component config blocks for wizard (#2885)
This commit is contained in:
parent
e763469af8
commit
fbc84861c7
2 changed files with 27 additions and 6 deletions
|
@ -45,9 +45,9 @@ OTA_BIG = r""" ____ _______
|
||||||
|
|
||||||
BASE_CONFIG = """esphome:
|
BASE_CONFIG = """esphome:
|
||||||
name: {name}
|
name: {name}
|
||||||
platform: {platform}
|
"""
|
||||||
board: {board}
|
|
||||||
|
|
||||||
|
LOGGER_API_CONFIG = """
|
||||||
# Enable logging
|
# Enable logging
|
||||||
logger:
|
logger:
|
||||||
|
|
||||||
|
@ -55,6 +55,18 @@ logger:
|
||||||
api:
|
api:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
ESP8266_CONFIG = """
|
||||||
|
esp8266:
|
||||||
|
board: {board}
|
||||||
|
"""
|
||||||
|
|
||||||
|
ESP32_CONFIG = """
|
||||||
|
esp32:
|
||||||
|
board: {board}
|
||||||
|
framework:
|
||||||
|
type: arduino
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def sanitize_double_quotes(value):
|
def sanitize_double_quotes(value):
|
||||||
return value.replace("\\", "\\\\").replace('"', '\\"')
|
return value.replace("\\", "\\\\").replace('"', '\\"')
|
||||||
|
@ -71,6 +83,14 @@ def wizard_file(**kwargs):
|
||||||
|
|
||||||
config = BASE_CONFIG.format(**kwargs)
|
config = BASE_CONFIG.format(**kwargs)
|
||||||
|
|
||||||
|
config += (
|
||||||
|
ESP8266_CONFIG.format(**kwargs)
|
||||||
|
if kwargs["platform"] == "ESP8266"
|
||||||
|
else ESP32_CONFIG.format(**kwargs)
|
||||||
|
)
|
||||||
|
|
||||||
|
config += LOGGER_API_CONFIG
|
||||||
|
|
||||||
# Configure API
|
# Configure API
|
||||||
if "password" in kwargs:
|
if "password" in kwargs:
|
||||||
config += f" password: \"{kwargs['password']}\"\n"
|
config += f" password: \"{kwargs['password']}\"\n"
|
||||||
|
|
|
@ -11,7 +11,7 @@ def default_config():
|
||||||
return {
|
return {
|
||||||
"name": "test-name",
|
"name": "test-name",
|
||||||
"platform": "test_platform",
|
"platform": "test_platform",
|
||||||
"board": "test_board",
|
"board": "esp01_1m",
|
||||||
"ssid": "test_ssid",
|
"ssid": "test_ssid",
|
||||||
"psk": "test_psk",
|
"psk": "test_psk",
|
||||||
"password": "",
|
"password": "",
|
||||||
|
@ -105,6 +105,7 @@ def test_wizard_write_sets_platform(default_config, tmp_path, monkeypatch):
|
||||||
If the platform is not explicitly set, use "ESP8266" if the board is one of the ESP8266 boards
|
If the platform is not explicitly set, use "ESP8266" if the board is one of the ESP8266 boards
|
||||||
"""
|
"""
|
||||||
# Given
|
# Given
|
||||||
|
del default_config["platform"]
|
||||||
monkeypatch.setattr(wz, "write_file", MagicMock())
|
monkeypatch.setattr(wz, "write_file", MagicMock())
|
||||||
|
|
||||||
# When
|
# When
|
||||||
|
@ -112,7 +113,7 @@ def test_wizard_write_sets_platform(default_config, tmp_path, monkeypatch):
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
generated_config = wz.write_file.call_args.args[1]
|
generated_config = wz.write_file.call_args.args[1]
|
||||||
assert f"platform: {default_config['platform']}" in generated_config
|
assert "esp8266:" in generated_config
|
||||||
|
|
||||||
|
|
||||||
def test_wizard_write_defaults_platform_from_board_esp8266(
|
def test_wizard_write_defaults_platform_from_board_esp8266(
|
||||||
|
@ -132,7 +133,7 @@ def test_wizard_write_defaults_platform_from_board_esp8266(
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
generated_config = wz.write_file.call_args.args[1]
|
generated_config = wz.write_file.call_args.args[1]
|
||||||
assert "platform: ESP8266" in generated_config
|
assert "esp8266:" in generated_config
|
||||||
|
|
||||||
|
|
||||||
def test_wizard_write_defaults_platform_from_board_esp32(
|
def test_wizard_write_defaults_platform_from_board_esp32(
|
||||||
|
@ -152,7 +153,7 @@ def test_wizard_write_defaults_platform_from_board_esp32(
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
generated_config = wz.write_file.call_args.args[1]
|
generated_config = wz.write_file.call_args.args[1]
|
||||||
assert "platform: ESP32" in generated_config
|
assert "esp32:" in generated_config
|
||||||
|
|
||||||
|
|
||||||
def test_safe_print_step_prints_step_number_and_description(monkeypatch):
|
def test_safe_print_step_prints_step_number_and_description(monkeypatch):
|
||||||
|
|
Loading…
Reference in a new issue