Add hyphen to supported name characters (#1223)

Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Ian Leeder 2020-07-30 08:02:34 +10:00 committed by GitHub
parent 3f6f3c14c4
commit aea2e9a6bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 7 deletions

View File

@ -40,7 +40,7 @@ ALLOW_EXTRA = vol.ALLOW_EXTRA
UNDEFINED = vol.UNDEFINED
RequiredFieldInvalid = vol.RequiredFieldInvalid
ALLOWED_NAME_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789_'
ALLOWED_NAME_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789_-'
RESERVED_IDS = [
# C++ keywords http://en.cppreference.com/w/cpp/keyword

View File

@ -10,7 +10,7 @@ ESP_PLATFORM_ESP32 = 'ESP32'
ESP_PLATFORM_ESP8266 = 'ESP8266'
ESP_PLATFORMS = [ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266]
ALLOWED_NAME_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789_'
ALLOWED_NAME_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789_-'
# Lookup table from ESP32 arduino framework version to latest platformio
# package with that version
# See also https://github.com/platformio/platform-espressif32/releases

View File

@ -359,7 +359,7 @@
<p>
Names must be all <strong>lowercase</strong> and <strong>must not contain any spaces</strong>!
Characters that are allowed are: <code class="inlinecode">a-z</code>,
<code class="inlinecode">0-9</code> and <code class="inlinecode">_</code>.
<code class="inlinecode">0-9</code>, <code class="inlinecode">_</code> and <code class="inlinecode">-</code>.
</p>
<div class="input-field col s12">

View File

@ -168,8 +168,9 @@ def wizard(path):
name = cv.valid_name(name)
break
except vol.Invalid:
safe_print(color("red", "Oh noes, \"{}\" isn't a valid name. Names can only include "
"numbers, lower-case letters and underscores.".format(name)))
safe_print(color("red", f"Oh noes, \"{name}\" isn't a valid name. Names can only "
f"include numbers, lower-case letters, underscores and "
f"hyphens."))
name = strip_accents(name).lower().replace(' ', '_')
name = ''.join(c for c in name if c in cv.ALLOWED_NAME_CHARS)
safe_print("Shall I use \"{}\" as the name instead?".format(color('cyan', name)))

View File

@ -5,7 +5,7 @@ esphome:
build_path: build/test4
substitutions:
devicename: test4
devicename: test-4
ethernet:
type: LAN8720

View File

@ -27,7 +27,7 @@ def test_alphanumeric__invalid(value):
actual = config_validation.alphanumeric(value)
@given(value=text(alphabet=string.ascii_lowercase + string.digits + "_"))
@given(value=text(alphabet=string.ascii_lowercase + string.digits + "_-"))
def test_valid_name__valid(value):
actual = config_validation.valid_name(value)