From aea2e9a6bb08936cb40463718c96381377d4182c Mon Sep 17 00:00:00 2001 From: Ian Leeder Date: Thu, 30 Jul 2020 08:02:34 +1000 Subject: [PATCH] Add hyphen to supported name characters (#1223) Co-authored-by: Otto Winter --- esphome/config_validation.py | 2 +- esphome/const.py | 2 +- esphome/dashboard/templates/index.html | 2 +- esphome/wizard.py | 5 +++-- tests/test4.yaml | 2 +- tests/unit_tests/test_config_validation.py | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/esphome/config_validation.py b/esphome/config_validation.py index 1e54c04fe5..9862a52c3e 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -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 diff --git a/esphome/const.py b/esphome/const.py index a3b953397a..011eab6e90 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -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 diff --git a/esphome/dashboard/templates/index.html b/esphome/dashboard/templates/index.html index d7ba9373be..142bc2cd6f 100644 --- a/esphome/dashboard/templates/index.html +++ b/esphome/dashboard/templates/index.html @@ -359,7 +359,7 @@

Names must be all lowercase and must not contain any spaces! Characters that are allowed are: a-z, - 0-9 and _. + 0-9, _ and -.

diff --git a/esphome/wizard.py b/esphome/wizard.py index b1a0b17072..97c45c9e1a 100644 --- a/esphome/wizard.py +++ b/esphome/wizard.py @@ -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))) diff --git a/tests/test4.yaml b/tests/test4.yaml index 61c1e278c4..ab78e22fef 100644 --- a/tests/test4.yaml +++ b/tests/test4.yaml @@ -5,7 +5,7 @@ esphome: build_path: build/test4 substitutions: - devicename: test4 + devicename: test-4 ethernet: type: LAN8720 diff --git a/tests/unit_tests/test_config_validation.py b/tests/unit_tests/test_config_validation.py index ced75af105..846df71a94 100644 --- a/tests/unit_tests/test_config_validation.py +++ b/tests/unit_tests/test_config_validation.py @@ -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)