mirror of
https://github.com/esphome/esphome.git
synced 2025-09-27 07:32:22 +01:00
Fix colorlog removing colors and refactor color code (#1671)
This commit is contained in:
@@ -6,7 +6,8 @@ import unicodedata
|
||||
import voluptuous as vol
|
||||
|
||||
import esphome.config_validation as cv
|
||||
from esphome.helpers import color, get_bool_env, write_file
|
||||
from esphome.helpers import get_bool_env, write_file
|
||||
from esphome.log import color, Fore
|
||||
|
||||
# pylint: disable=anomalous-backslash-in-string
|
||||
from esphome.pins import ESP32_BOARD_PINS, ESP8266_BOARD_PINS
|
||||
@@ -148,13 +149,13 @@ def wizard(path):
|
||||
if not path.endswith(".yaml") and not path.endswith(".yml"):
|
||||
safe_print(
|
||||
"Please make your configuration file {} have the extension .yaml or .yml"
|
||||
"".format(color("cyan", path))
|
||||
"".format(color(Fore.CYAN, path))
|
||||
)
|
||||
return 1
|
||||
if os.path.exists(path):
|
||||
safe_print(
|
||||
"Uh oh, it seems like {} already exists, please delete that file first "
|
||||
"or chose another configuration file.".format(color("cyan", path))
|
||||
"or chose another configuration file.".format(color(Fore.CYAN, path))
|
||||
)
|
||||
return 2
|
||||
safe_print("Hi there!")
|
||||
@@ -171,7 +172,7 @@ def wizard(path):
|
||||
safe_print()
|
||||
safe_print_step(1, CORE_BIG)
|
||||
safe_print(
|
||||
"First up, please choose a " + color("green", "name") + " for your node."
|
||||
"First up, please choose a " + color(Fore.GREEN, "name") + " for your node."
|
||||
)
|
||||
safe_print(
|
||||
"It should be a unique name that can be used to identify the device later."
|
||||
@@ -179,12 +180,12 @@ def wizard(path):
|
||||
sleep(1)
|
||||
safe_print(
|
||||
"For example, I like calling the node in my living room {}.".format(
|
||||
color("bold_white", "livingroom")
|
||||
color(Fore.BOLD_WHITE, "livingroom")
|
||||
)
|
||||
)
|
||||
safe_print()
|
||||
sleep(1)
|
||||
name = input(color("bold_white", "(name): "))
|
||||
name = input(color(Fore.BOLD_WHITE, "(name): "))
|
||||
|
||||
while True:
|
||||
try:
|
||||
@@ -193,7 +194,7 @@ def wizard(path):
|
||||
except vol.Invalid:
|
||||
safe_print(
|
||||
color(
|
||||
"red",
|
||||
Fore.RED,
|
||||
f'Oh noes, "{name}" isn\'t a valid name. Names can only '
|
||||
f"include numbers, lower-case letters, underscores and "
|
||||
f"hyphens.",
|
||||
@@ -202,12 +203,12 @@ def wizard(path):
|
||||
name = strip_accents(name).lower().replace(" ", "_")
|
||||
name = "".join(c for c in name if c in ALLOWED_NAME_CHARS)
|
||||
safe_print(
|
||||
'Shall I use "{}" as the name instead?'.format(color("cyan", name))
|
||||
'Shall I use "{}" as the name instead?'.format(color(Fore.CYAN, name))
|
||||
)
|
||||
sleep(0.5)
|
||||
name = default_input("(name [{}]): ", name)
|
||||
|
||||
safe_print('Great! Your node is now called "{}".'.format(color("cyan", name)))
|
||||
safe_print('Great! Your node is now called "{}".'.format(color(Fore.CYAN, name)))
|
||||
sleep(1)
|
||||
safe_print_step(2, ESP_BIG)
|
||||
safe_print(
|
||||
@@ -216,16 +217,16 @@ def wizard(path):
|
||||
)
|
||||
safe_print(
|
||||
"Are you using an "
|
||||
+ color("green", "ESP32")
|
||||
+ color(Fore.GREEN, "ESP32")
|
||||
+ " or "
|
||||
+ color("green", "ESP8266")
|
||||
+ color(Fore.GREEN, "ESP8266")
|
||||
+ " platform? (Choose ESP8266 for Sonoff devices)"
|
||||
)
|
||||
while True:
|
||||
sleep(0.5)
|
||||
safe_print()
|
||||
safe_print("Please enter either ESP32 or ESP8266.")
|
||||
platform = input(color("bold_white", "(ESP32/ESP8266): "))
|
||||
platform = input(color(Fore.BOLD_WHITE, "(ESP32/ESP8266): "))
|
||||
try:
|
||||
platform = vol.All(vol.Upper, vol.Any("ESP32", "ESP8266"))(platform)
|
||||
break
|
||||
@@ -235,7 +236,7 @@ def wizard(path):
|
||||
'"{}". Please try again.'.format(platform)
|
||||
)
|
||||
safe_print(
|
||||
"Thanks! You've chosen {} as your platform.".format(color("cyan", platform))
|
||||
"Thanks! You've chosen {} as your platform.".format(color(Fore.CYAN, platform))
|
||||
)
|
||||
safe_print()
|
||||
sleep(1)
|
||||
@@ -250,37 +251,39 @@ def wizard(path):
|
||||
)
|
||||
|
||||
safe_print(
|
||||
"Next, I need to know what " + color("green", "board") + " you're using."
|
||||
"Next, I need to know what " + color(Fore.GREEN, "board") + " you're using."
|
||||
)
|
||||
sleep(0.5)
|
||||
safe_print("Please go to {} and choose a board.".format(color("green", board_link)))
|
||||
safe_print(
|
||||
"Please go to {} and choose a board.".format(color(Fore.GREEN, board_link))
|
||||
)
|
||||
if platform == "ESP32":
|
||||
safe_print("(Type " + color("green", "esp01_1m") + " for Sonoff devices)")
|
||||
safe_print("(Type " + color(Fore.GREEN, "esp01_1m") + " for Sonoff devices)")
|
||||
safe_print()
|
||||
# Don't sleep because user needs to copy link
|
||||
if platform == "ESP32":
|
||||
safe_print('For example "{}".'.format(color("bold_white", "nodemcu-32s")))
|
||||
safe_print('For example "{}".'.format(color(Fore.BOLD_WHITE, "nodemcu-32s")))
|
||||
boards = list(ESP32_BOARD_PINS.keys())
|
||||
else:
|
||||
safe_print('For example "{}".'.format(color("bold_white", "nodemcuv2")))
|
||||
safe_print('For example "{}".'.format(color(Fore.BOLD_WHITE, "nodemcuv2")))
|
||||
boards = list(ESP8266_BOARD_PINS.keys())
|
||||
safe_print("Options: {}".format(", ".join(sorted(boards))))
|
||||
|
||||
while True:
|
||||
board = input(color("bold_white", "(board): "))
|
||||
board = input(color(Fore.BOLD_WHITE, "(board): "))
|
||||
try:
|
||||
board = vol.All(vol.Lower, vol.Any(*boards))(board)
|
||||
break
|
||||
except vol.Invalid:
|
||||
safe_print(
|
||||
color("red", f'Sorry, I don\'t think the board "{board}" exists.')
|
||||
color(Fore.RED, f'Sorry, I don\'t think the board "{board}" exists.')
|
||||
)
|
||||
safe_print()
|
||||
sleep(0.25)
|
||||
safe_print()
|
||||
|
||||
safe_print(
|
||||
"Way to go! You've chosen {} as your board.".format(color("cyan", board))
|
||||
"Way to go! You've chosen {} as your board.".format(color(Fore.CYAN, board))
|
||||
)
|
||||
safe_print()
|
||||
sleep(1)
|
||||
@@ -291,20 +294,20 @@ def wizard(path):
|
||||
sleep(1)
|
||||
safe_print(
|
||||
"First, what's the "
|
||||
+ color("green", "SSID")
|
||||
+ color(Fore.GREEN, "SSID")
|
||||
+ f" (the name) of the WiFi network {name} I should connect to?"
|
||||
)
|
||||
sleep(1.5)
|
||||
safe_print('For example "{}".'.format(color("bold_white", "Abraham Linksys")))
|
||||
safe_print('For example "{}".'.format(color(Fore.BOLD_WHITE, "Abraham Linksys")))
|
||||
while True:
|
||||
ssid = input(color("bold_white", "(ssid): "))
|
||||
ssid = input(color(Fore.BOLD_WHITE, "(ssid): "))
|
||||
try:
|
||||
ssid = cv.ssid(ssid)
|
||||
break
|
||||
except vol.Invalid:
|
||||
safe_print(
|
||||
color(
|
||||
"red",
|
||||
Fore.RED,
|
||||
'Unfortunately, "{}" doesn\'t seem to be a valid SSID. '
|
||||
"Please try again.".format(ssid),
|
||||
)
|
||||
@@ -314,20 +317,20 @@ def wizard(path):
|
||||
|
||||
safe_print(
|
||||
'Thank you very much! You\'ve just chosen "{}" as your SSID.'
|
||||
"".format(color("cyan", ssid))
|
||||
"".format(color(Fore.CYAN, ssid))
|
||||
)
|
||||
safe_print()
|
||||
sleep(0.75)
|
||||
|
||||
safe_print(
|
||||
"Now please state the "
|
||||
+ color("green", "password")
|
||||
+ color(Fore.GREEN, "password")
|
||||
+ " of the WiFi network so that I can connect to it (Leave empty for no password)"
|
||||
)
|
||||
safe_print()
|
||||
safe_print('For example "{}"'.format(color("bold_white", "PASSWORD42")))
|
||||
safe_print('For example "{}"'.format(color(Fore.BOLD_WHITE, "PASSWORD42")))
|
||||
sleep(0.5)
|
||||
psk = input(color("bold_white", "(PSK): "))
|
||||
psk = input(color(Fore.BOLD_WHITE, "(PSK): "))
|
||||
safe_print(
|
||||
"Perfect! WiFi is now set up (you can create static IPs and so on later)."
|
||||
)
|
||||
@@ -340,12 +343,12 @@ def wizard(path):
|
||||
)
|
||||
safe_print(
|
||||
"This can be insecure if you do not trust the WiFi network. Do you want to set "
|
||||
"a " + color("green", "password") + " for connecting to this ESP?"
|
||||
"a " + color(Fore.GREEN, "password") + " for connecting to this ESP?"
|
||||
)
|
||||
safe_print()
|
||||
sleep(0.25)
|
||||
safe_print("Press ENTER for no password")
|
||||
password = input(color("bold_white", "(password): "))
|
||||
password = input(color(Fore.BOLD_WHITE, "(password): "))
|
||||
|
||||
wizard_write(
|
||||
path=path,
|
||||
@@ -359,8 +362,8 @@ def wizard(path):
|
||||
|
||||
safe_print()
|
||||
safe_print(
|
||||
color("cyan", "DONE! I've now written a new configuration file to ")
|
||||
+ color("bold_cyan", path)
|
||||
color(Fore.CYAN, "DONE! I've now written a new configuration file to ")
|
||||
+ color(Fore.BOLD_CYAN, path)
|
||||
)
|
||||
safe_print()
|
||||
safe_print("Next steps:")
|
||||
|
Reference in New Issue
Block a user