2018-04-07 01:23:03 +02:00
|
|
|
import os
|
2019-06-09 17:03:51 +02:00
|
|
|
import random
|
|
|
|
import string
|
2018-04-07 01:23:03 +02:00
|
|
|
import unicodedata
|
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-02-13 16:54:02 +01:00
|
|
|
import esphome.config_validation as cv
|
2021-04-08 13:58:01 +02:00
|
|
|
from esphome.helpers import get_bool_env, write_file
|
|
|
|
from esphome.log import color, Fore
|
2021-03-07 20:03:16 +01:00
|
|
|
|
2018-04-10 17:17:46 +02:00
|
|
|
# pylint: disable=anomalous-backslash-in-string
|
2019-02-13 16:54:02 +01:00
|
|
|
from esphome.storage_json import StorageJSON, ext_storage_path
|
|
|
|
from esphome.util import safe_print
|
2020-12-21 22:19:26 +01:00
|
|
|
from esphome.const import ALLOWED_NAME_CHARS, ENV_QUICKWIZARD
|
2018-09-23 18:58:41 +02:00
|
|
|
|
2019-01-02 14:11:11 +01:00
|
|
|
CORE_BIG = r""" _____ ____ _____ ______
|
2018-04-07 01:23:03 +02:00
|
|
|
/ ____/ __ \| __ \| ____|
|
2018-04-10 17:17:46 +02:00
|
|
|
| | | | | | |__) | |__
|
|
|
|
| | | | | | _ /| __|
|
|
|
|
| |___| |__| | | \ \| |____
|
2018-04-07 01:23:03 +02:00
|
|
|
\_____\____/|_| \_\______|
|
|
|
|
"""
|
2019-01-02 14:11:11 +01:00
|
|
|
ESP_BIG = r""" ______ _____ _____
|
2018-04-10 17:17:46 +02:00
|
|
|
| ____|/ ____| __ \\
|
2018-04-07 01:23:03 +02:00
|
|
|
| |__ | (___ | |__) |
|
2018-04-10 17:17:46 +02:00
|
|
|
| __| \___ \| ___/
|
|
|
|
| |____ ____) | |
|
|
|
|
|______|_____/|_|
|
2018-04-07 01:23:03 +02:00
|
|
|
"""
|
2019-01-02 14:11:11 +01:00
|
|
|
WIFI_BIG = r""" __ ___ ______ _
|
2018-04-07 01:23:03 +02:00
|
|
|
\ \ / (_) ____(_)
|
2018-04-10 17:17:46 +02:00
|
|
|
\ \ /\ / / _| |__ _
|
2018-04-07 01:23:03 +02:00
|
|
|
\ \/ \/ / | | __| | |
|
|
|
|
\ /\ / | | | | |
|
|
|
|
\/ \/ |_|_| |_|
|
|
|
|
"""
|
2019-01-02 14:11:11 +01:00
|
|
|
OTA_BIG = r""" ____ _______
|
2018-04-10 17:17:46 +02:00
|
|
|
/ __ \__ __|/\\
|
|
|
|
| | | | | | / \\
|
|
|
|
| | | | | | / /\ \\
|
|
|
|
| |__| | | |/ ____ \\
|
2018-04-07 01:23:03 +02:00
|
|
|
\____/ |_/_/ \_\\
|
|
|
|
"""
|
|
|
|
|
2019-12-07 18:28:55 +01:00
|
|
|
BASE_CONFIG = """esphome:
|
2018-04-07 01:23:03 +02:00
|
|
|
name: {name}
|
2021-12-07 21:22:03 +01:00
|
|
|
"""
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-12-07 21:22:03 +01:00
|
|
|
LOGGER_API_CONFIG = """
|
2018-04-07 01:23:03 +02:00
|
|
|
# Enable logging
|
|
|
|
logger:
|
|
|
|
|
2018-12-18 19:31:43 +01:00
|
|
|
# Enable Home Assistant API
|
|
|
|
api:
|
2018-04-07 01:23:03 +02:00
|
|
|
"""
|
|
|
|
|
2021-12-07 21:22:03 +01:00
|
|
|
ESP8266_CONFIG = """
|
|
|
|
esp8266:
|
|
|
|
board: {board}
|
|
|
|
"""
|
|
|
|
|
|
|
|
ESP32_CONFIG = """
|
|
|
|
esp32:
|
|
|
|
board: {board}
|
|
|
|
framework:
|
|
|
|
type: arduino
|
|
|
|
"""
|
|
|
|
|
2022-02-19 15:47:50 +01:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2018-05-21 16:40:22 +02:00
|
|
|
|
2019-04-15 21:49:21 +02:00
|
|
|
def sanitize_double_quotes(value):
|
2021-03-07 20:03:16 +01:00
|
|
|
return value.replace("\\", "\\\\").replace('"', '\\"')
|
2019-04-15 21:49:21 +02:00
|
|
|
|
|
|
|
|
2018-05-21 16:40:22 +02:00
|
|
|
def wizard_file(**kwargs):
|
2019-06-09 17:03:51 +02:00
|
|
|
letters = string.ascii_letters + string.digits
|
2021-03-07 20:03:16 +01:00
|
|
|
ap_name_base = kwargs["name"].replace("_", " ").title()
|
2019-12-07 18:28:55 +01:00
|
|
|
ap_name = f"{ap_name_base} Fallback Hotspot"
|
2019-06-30 09:14:04 +02:00
|
|
|
if len(ap_name) > 32:
|
|
|
|
ap_name = ap_name_base
|
2021-03-07 20:03:16 +01:00
|
|
|
kwargs["fallback_name"] = ap_name
|
|
|
|
kwargs["fallback_psk"] = "".join(random.choice(letters) for _ in range(12))
|
2019-06-09 17:03:51 +02:00
|
|
|
|
2018-05-21 16:40:22 +02:00
|
|
|
config = BASE_CONFIG.format(**kwargs)
|
|
|
|
|
2022-02-19 15:47:50 +01:00
|
|
|
config += HARDWARE_BASE_CONFIGS[kwargs["platform"]].format(**kwargs)
|
2021-12-07 21:22:03 +01:00
|
|
|
|
|
|
|
config += LOGGER_API_CONFIG
|
|
|
|
|
2021-06-12 00:49:05 +02:00
|
|
|
# Configure API
|
|
|
|
if "password" in kwargs:
|
2021-09-19 19:22:28 +02:00
|
|
|
config += f" password: \"{kwargs['password']}\"\n"
|
2022-05-11 01:38:05 +02:00
|
|
|
if "api_encryption_key" in kwargs:
|
|
|
|
config += f" encryption:\n key: \"{kwargs['api_encryption_key']}\"\n"
|
2021-06-12 00:49:05 +02:00
|
|
|
|
|
|
|
# Configure OTA
|
|
|
|
config += "\nota:\n"
|
|
|
|
if "ota_password" in kwargs:
|
2021-09-19 19:22:28 +02:00
|
|
|
config += f" password: \"{kwargs['ota_password']}\""
|
2021-06-12 00:49:05 +02:00
|
|
|
elif "password" in kwargs:
|
2021-09-19 19:22:28 +02:00
|
|
|
config += f" password: \"{kwargs['password']}\""
|
2021-06-12 00:49:05 +02:00
|
|
|
|
|
|
|
# Configuring wifi
|
|
|
|
config += "\n\nwifi:\n"
|
|
|
|
|
|
|
|
if "ssid" in kwargs:
|
2021-12-06 08:58:51 +01:00
|
|
|
if kwargs["ssid"].startswith("!secret"):
|
|
|
|
template = " ssid: {ssid}\n password: {psk}\n"
|
|
|
|
else:
|
|
|
|
template = """ ssid: "{ssid}"\n password: "{psk}"\n"""
|
|
|
|
config += template.format(**kwargs)
|
2018-05-21 16:40:22 +02:00
|
|
|
else:
|
2021-06-12 00:49:05 +02:00
|
|
|
config += """ # ssid: "My SSID"
|
|
|
|
# password: "mypassword"
|
|
|
|
|
|
|
|
networks:
|
|
|
|
"""
|
|
|
|
|
2021-09-19 19:22:28 +02:00
|
|
|
# pylint: disable=consider-using-f-string
|
2022-02-19 15:47:50 +01:00
|
|
|
if kwargs["platform"] in ["ESP8266", "ESP32"]:
|
|
|
|
config += """
|
2021-06-12 00:49:05 +02:00
|
|
|
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
|
|
|
ap:
|
|
|
|
ssid: "{fallback_name}"
|
|
|
|
password: "{fallback_psk}"
|
|
|
|
|
|
|
|
captive_portal:
|
2022-02-19 15:47:50 +01:00
|
|
|
""".format(
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
config += """
|
|
|
|
# Enable fallback hotspot in case wifi connection fails
|
|
|
|
ap:
|
|
|
|
ssid: "{fallback_name}"
|
|
|
|
password: "{fallback_psk}"
|
|
|
|
""".format(
|
|
|
|
**kwargs
|
|
|
|
)
|
2018-05-21 16:40:22 +02:00
|
|
|
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
def wizard_write(path, **kwargs):
|
2021-09-20 11:47:51 +02:00
|
|
|
from esphome.components.esp8266 import boards as esp8266_boards
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
name = kwargs["name"]
|
|
|
|
board = kwargs["board"]
|
2019-04-15 21:49:21 +02:00
|
|
|
|
2021-06-12 00:49:05 +02:00
|
|
|
for key in ("ssid", "psk", "password", "ota_password"):
|
|
|
|
if key in kwargs:
|
|
|
|
kwargs[key] = sanitize_double_quotes(kwargs[key])
|
2019-04-15 21:49:21 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
if "platform" not in kwargs:
|
2021-09-20 11:47:51 +02:00
|
|
|
kwargs["platform"] = (
|
|
|
|
"ESP8266" if board in esp8266_boards.ESP8266_BOARD_PINS else "ESP32"
|
|
|
|
)
|
2022-02-19 15:47:50 +01:00
|
|
|
hardware = kwargs["platform"]
|
2018-12-05 21:22:06 +01:00
|
|
|
|
2019-10-24 21:53:42 +02:00
|
|
|
write_file(path, wizard_file(**kwargs))
|
2022-02-19 15:47:50 +01:00
|
|
|
storage = StorageJSON.from_wizard(name, f"{name}.local", hardware)
|
2018-12-05 21:22:06 +01:00
|
|
|
storage_path = ext_storage_path(os.path.dirname(path), os.path.basename(path))
|
|
|
|
storage.save(storage_path)
|
|
|
|
|
|
|
|
|
2020-12-21 22:19:26 +01:00
|
|
|
if get_bool_env(ENV_QUICKWIZARD):
|
2021-03-07 20:03:16 +01:00
|
|
|
|
2018-04-11 22:51:56 +02:00
|
|
|
def sleep(time):
|
|
|
|
pass
|
2021-03-07 20:03:16 +01:00
|
|
|
|
2018-04-11 22:51:56 +02:00
|
|
|
else:
|
|
|
|
from time import sleep
|
|
|
|
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2018-10-20 12:41:00 +02:00
|
|
|
def safe_print_step(step, big):
|
|
|
|
safe_print()
|
|
|
|
safe_print()
|
2019-12-07 18:28:55 +01:00
|
|
|
safe_print(f"============= STEP {step} =============")
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print(big)
|
|
|
|
safe_print("===================================")
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(0.25)
|
|
|
|
|
|
|
|
|
|
|
|
def default_input(text, default):
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2019-12-07 18:28:55 +01:00
|
|
|
safe_print(f"Press ENTER for default ({default})")
|
|
|
|
return input(text.format(default)) or default
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
# From https://stackoverflow.com/a/518232/8924614
|
2019-06-09 17:03:51 +02:00
|
|
|
def strip_accents(value):
|
2021-03-07 20:03:16 +01:00
|
|
|
return "".join(
|
|
|
|
c
|
|
|
|
for c in unicodedata.normalize("NFD", str(value))
|
|
|
|
if unicodedata.category(c) != "Mn"
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
def wizard(path):
|
2021-09-20 11:47:51 +02:00
|
|
|
from esphome.components.esp32 import boards as esp32_boards
|
|
|
|
from esphome.components.esp8266 import boards as esp8266_boards
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
if not path.endswith(".yaml") and not path.endswith(".yml"):
|
|
|
|
safe_print(
|
2021-09-19 19:22:28 +02:00
|
|
|
f"Please make your configuration file {color(Fore.CYAN, path)} have the extension .yaml or .yml"
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
return 1
|
|
|
|
if os.path.exists(path):
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
2021-09-19 19:22:28 +02:00
|
|
|
f"Uh oh, it seems like {color(Fore.CYAN, path)} already exists, please delete that file first or chose another configuration file."
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2020-07-23 23:51:14 +02:00
|
|
|
return 2
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print("Hi there!")
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1.5)
|
2018-12-18 19:31:43 +01:00
|
|
|
safe_print("I'm the wizard of ESPHome :)")
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1.25)
|
2018-12-18 19:31:43 +01:00
|
|
|
safe_print("And I'm here to help you get started with ESPHome.")
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(2.0)
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
|
|
|
"In 4 steps I'm going to guide you through creating a basic "
|
|
|
|
"configuration file for your custom ESP8266/ESP32 firmware. Yay!"
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(3.0)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
|
|
|
safe_print_step(1, CORE_BIG)
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"First up, please choose a {color(Fore.GREEN, 'name')} for your node.")
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
|
|
|
"It should be a unique name that can be used to identify the device later."
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1)
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
2021-09-19 19:22:28 +02:00
|
|
|
f"For example, I like calling the node in my living room {color(Fore.BOLD_WHITE, 'livingroom')}."
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1)
|
2021-04-08 13:58:01 +02:00
|
|
|
name = input(color(Fore.BOLD_WHITE, "(name): "))
|
2020-07-23 23:51:14 +02:00
|
|
|
|
2018-04-07 01:23:03 +02:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
name = cv.valid_name(name)
|
|
|
|
break
|
|
|
|
except vol.Invalid:
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
|
|
|
color(
|
2021-04-08 13:58:01 +02:00
|
|
|
Fore.RED,
|
2021-03-07 20:03:16 +01:00
|
|
|
f'Oh noes, "{name}" isn\'t a valid name. Names can only '
|
2021-04-08 14:26:01 +02:00
|
|
|
f"include numbers, lower-case letters and hyphens. ",
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
|
|
|
)
|
2021-04-08 14:26:01 +02:00
|
|
|
name = strip_accents(name).lower().replace(" ", "-")
|
|
|
|
name = strip_accents(name).lower().replace("_", "-")
|
2021-03-07 20:03:16 +01:00
|
|
|
name = "".join(c for c in name if c in ALLOWED_NAME_CHARS)
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f'Shall I use "{color(Fore.CYAN, name)}" as the name instead?')
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(0.5)
|
2019-12-07 18:28:55 +01:00
|
|
|
name = default_input("(name [{}]): ", name)
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f'Great! Your node is now called "{color(Fore.CYAN, name)}".')
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print_step(2, ESP_BIG)
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
|
|
|
"Now I'd like to know what microcontroller you're using so that I can compile "
|
|
|
|
"firmwares for it."
|
|
|
|
)
|
|
|
|
safe_print(
|
2021-09-19 19:22:28 +02:00
|
|
|
f"Are you using an {color(Fore.GREEN, 'ESP32')} or {color(Fore.GREEN, 'ESP8266')} platform? (Choose ESP8266 for Sonoff devices)"
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
while True:
|
|
|
|
sleep(0.5)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
|
|
|
safe_print("Please enter either ESP32 or ESP8266.")
|
2021-04-08 13:58:01 +02:00
|
|
|
platform = input(color(Fore.BOLD_WHITE, "(ESP32/ESP8266): "))
|
2018-04-07 01:23:03 +02:00
|
|
|
try:
|
2021-03-07 20:03:16 +01:00
|
|
|
platform = vol.All(vol.Upper, vol.Any("ESP32", "ESP8266"))(platform)
|
2018-04-07 01:23:03 +02:00
|
|
|
break
|
|
|
|
except vol.Invalid:
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
2021-09-19 19:22:28 +02:00
|
|
|
f'Unfortunately, I can\'t find an espressif microcontroller called "{platform}". Please try again.'
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"Thanks! You've chosen {color(Fore.CYAN, platform)} as your platform.")
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1)
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
if platform == "ESP32":
|
|
|
|
board_link = (
|
|
|
|
"http://docs.platformio.org/en/latest/platforms/espressif32.html#boards"
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
else:
|
2021-03-07 20:03:16 +01:00
|
|
|
board_link = (
|
|
|
|
"http://docs.platformio.org/en/latest/platforms/espressif8266.html#boards"
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"Next, I need to know what {color(Fore.GREEN, 'board')} you're using.")
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(0.5)
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"Please go to {color(Fore.GREEN, board_link)} and choose a board.")
|
2021-03-07 20:03:16 +01:00
|
|
|
if platform == "ESP32":
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"(Type {color(Fore.GREEN, 'esp01_1m')} for Sonoff devices)")
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
# Don't sleep because user needs to copy link
|
2021-03-07 20:03:16 +01:00
|
|
|
if platform == "ESP32":
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"For example \"{color(Fore.BOLD_WHITE, 'nodemcu-32s')}\".")
|
2021-09-20 11:47:51 +02:00
|
|
|
boards = list(esp32_boards.ESP32_BOARD_PINS.keys())
|
2018-04-07 01:23:03 +02:00
|
|
|
else:
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"For example \"{color(Fore.BOLD_WHITE, 'nodemcuv2')}\".")
|
2021-09-20 11:47:51 +02:00
|
|
|
boards = list(esp8266_boards.ESP8266_BOARD_PINS.keys())
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"Options: {', '.join(sorted(boards))}")
|
2018-12-18 19:31:43 +01:00
|
|
|
|
2018-04-07 01:23:03 +02:00
|
|
|
while True:
|
2021-04-08 13:58:01 +02:00
|
|
|
board = input(color(Fore.BOLD_WHITE, "(board): "))
|
2018-04-07 01:23:03 +02:00
|
|
|
try:
|
|
|
|
board = vol.All(vol.Lower, vol.Any(*boards))(board)
|
|
|
|
break
|
|
|
|
except vol.Invalid:
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
2021-04-08 13:58:01 +02:00
|
|
|
color(Fore.RED, f'Sorry, I don\'t think the board "{board}" exists.')
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(0.25)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"Way to go! You've chosen {color(Fore.CYAN, board)} as your board.")
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1)
|
|
|
|
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print_step(3, WIFI_BIG)
|
2022-06-21 06:27:33 +02:00
|
|
|
safe_print("In this step, I'm going to create the configuration for WiFi.")
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1)
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
2021-09-19 19:22:28 +02:00
|
|
|
f"First, what's the {color(Fore.GREEN, 'SSID')} (the name) of the WiFi network {name} should connect to?"
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1.5)
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"For example \"{color(Fore.BOLD_WHITE, 'Abraham Linksys')}\".")
|
2018-04-07 01:23:03 +02:00
|
|
|
while True:
|
2021-04-08 13:58:01 +02:00
|
|
|
ssid = input(color(Fore.BOLD_WHITE, "(ssid): "))
|
2018-04-07 01:23:03 +02:00
|
|
|
try:
|
|
|
|
ssid = cv.ssid(ssid)
|
|
|
|
break
|
|
|
|
except vol.Invalid:
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
|
|
|
color(
|
2021-04-08 13:58:01 +02:00
|
|
|
Fore.RED,
|
2021-09-19 19:22:28 +02:00
|
|
|
f'Unfortunately, "{ssid}" doesn\'t seem to be a valid SSID. Please try again.',
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
|
|
|
)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1)
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
2021-09-19 19:22:28 +02:00
|
|
|
f'Thank you very much! You\'ve just chosen "{color(Fore.CYAN, ssid)}" as your SSID.'
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(0.75)
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
2021-09-19 19:22:28 +02:00
|
|
|
f"Now please state the {color(Fore.GREEN, 'password')} of the WiFi network so that I can connect to it (Leave empty for no password)"
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2021-09-19 19:22:28 +02:00
|
|
|
safe_print(f"For example \"{color(Fore.BOLD_WHITE, 'PASSWORD42')}\"")
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(0.5)
|
2021-04-08 13:58:01 +02:00
|
|
|
psk = input(color(Fore.BOLD_WHITE, "(PSK): "))
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
|
|
|
"Perfect! WiFi is now set up (you can create static IPs and so on later)."
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(1.5)
|
|
|
|
|
2018-12-18 19:31:43 +01:00
|
|
|
safe_print_step(4, OTA_BIG)
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
|
|
|
"Almost there! ESPHome can automatically upload custom firmwares over WiFi "
|
|
|
|
"(over the air) and integrates into Home Assistant with a native API."
|
|
|
|
)
|
|
|
|
safe_print(
|
2021-09-19 19:22:28 +02:00
|
|
|
f"This can be insecure if you do not trust the WiFi network. Do you want to set a {color(Fore.GREEN, 'password')} for connecting to this ESP?"
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2018-04-07 01:23:03 +02:00
|
|
|
sleep(0.25)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print("Press ENTER for no password")
|
2021-04-08 13:58:01 +02:00
|
|
|
password = input(color(Fore.BOLD_WHITE, "(password): "))
|
2021-03-07 20:03:16 +01:00
|
|
|
|
|
|
|
wizard_write(
|
|
|
|
path=path,
|
|
|
|
name=name,
|
|
|
|
platform=platform,
|
|
|
|
board=board,
|
|
|
|
ssid=ssid,
|
|
|
|
psk=psk,
|
|
|
|
password=password,
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
2021-04-08 13:58:01 +02:00
|
|
|
color(Fore.CYAN, "DONE! I've now written a new configuration file to ")
|
|
|
|
+ color(Fore.BOLD_CYAN, path)
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-10-20 12:41:00 +02:00
|
|
|
safe_print()
|
|
|
|
safe_print("Next steps:")
|
2021-10-15 19:51:42 +02:00
|
|
|
safe_print(" > Follow the rest of the getting started guide:")
|
2021-03-07 20:03:16 +01:00
|
|
|
safe_print(
|
2021-10-15 19:51:42 +02:00
|
|
|
" > https://esphome.io/guides/getting_started_command_line.html#adding-some-features"
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2021-10-15 19:51:42 +02:00
|
|
|
safe_print(" > to learn how to customize ESPHome and install it to your device.")
|
2018-04-07 01:23:03 +02:00
|
|
|
return 0
|