Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump pylint from 2.10.2 to 2.11.1 #2334

Merged
merged 2 commits into from Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions esphome/__main__.py
Expand Up @@ -72,7 +72,7 @@ def choose_upload_log_host(default, check_default, show_ota, show_mqtt, show_api
if default == "OTA":
return CORE.address
if show_mqtt and "mqtt" in CORE.config:
options.append(("MQTT ({})".format(CORE.config["mqtt"][CONF_BROKER]), "MQTT"))
options.append((f"MQTT ({CORE.config['mqtt'][CONF_BROKER]})", "MQTT"))
if default == "OTA":
return "MQTT"
if default is not None:
Expand Down Expand Up @@ -415,30 +415,30 @@ def print_bar(middle_text):
click.echo(f"{half_line}{middle_text}{half_line}")

for f in files:
print("Updating {}".format(color(Fore.CYAN, f)))
print(f"Updating {color(Fore.CYAN, f)}")
print("-" * twidth)
print()
rc = run_external_process(
"esphome", "--dashboard", "run", f, "--no-logs", "--device", "OTA"
)
if rc == 0:
print_bar("[{}] {}".format(color(Fore.BOLD_GREEN, "SUCCESS"), f))
print_bar(f"[{color(Fore.BOLD_GREEN, 'SUCCESS')}] {f}")
success[f] = True
else:
print_bar("[{}] {}".format(color(Fore.BOLD_RED, "ERROR"), f))
print_bar(f"[{color(Fore.BOLD_RED, 'ERROR')}] {f}")
success[f] = False

print()
print()
print()

print_bar("[{}]".format(color(Fore.BOLD_WHITE, "SUMMARY")))
print_bar(f"[{color(Fore.BOLD_WHITE, 'SUMMARY')}]")
failed = 0
for f in files:
if success[f]:
print(" - {}: {}".format(f, color(Fore.GREEN, "SUCCESS")))
print(f" - {f}: {color(Fore.GREEN, 'SUCCESS')}")
else:
print(" - {}: {}".format(f, color(Fore.BOLD_RED, "FAILED")))
print(f" - {f}: {color(Fore.BOLD_RED, 'FAILED')}")
failed += 1
return failed

Expand Down
16 changes: 6 additions & 10 deletions esphome/components/binary_sensor/__init__.py
Expand Up @@ -231,17 +231,16 @@ def parse_multi_click_timing_str(value):
parts = value.lower().split(" ")
if len(parts) != 5:
raise cv.Invalid(
"Multi click timing grammar consists of exactly 5 words, not {}"
"".format(len(parts))
f"Multi click timing grammar consists of exactly 5 words, not {len(parts)}"
)
try:
state = cv.boolean(parts[0])
except cv.Invalid:
# pylint: disable=raise-missing-from
raise cv.Invalid("First word must either be ON or OFF, not {}".format(parts[0]))
raise cv.Invalid(f"First word must either be ON or OFF, not {parts[0]}")

if parts[1] != "for":
raise cv.Invalid("Second word must be 'for', got {}".format(parts[1]))
raise cv.Invalid(f"Second word must be 'for', got {parts[1]}")

if parts[2] == "at":
if parts[3] == "least":
Expand All @@ -250,8 +249,7 @@ def parse_multi_click_timing_str(value):
key = CONF_MAX_LENGTH
else:
raise cv.Invalid(
"Third word after at must either be 'least' or 'most', got {}"
"".format(parts[3])
f"Third word after at must either be 'least' or 'most', got {parts[3]}"
)
try:
length = cv.positive_time_period_milliseconds(parts[4])
Expand Down Expand Up @@ -296,13 +294,11 @@ def validate_multi_click_timing(value):
new_state = v_.get(CONF_STATE, not state)
if new_state == state:
raise cv.Invalid(
"Timings must have alternating state. Indices {} and {} have "
"the same state {}".format(i, i + 1, state)
f"Timings must have alternating state. Indices {i} and {i + 1} have the same state {state}"
)
if max_length is not None and max_length < min_length:
raise cv.Invalid(
"Max length ({}) must be larger than min length ({})."
"".format(max_length, min_length)
f"Max length ({max_length}) must be larger than min length ({min_length})."
)

state = new_state
Expand Down
3 changes: 1 addition & 2 deletions esphome/components/deep_sleep/__init__.py
Expand Up @@ -16,8 +16,7 @@ def validate_pin_number(value):
valid_pins = [0, 2, 4, 12, 13, 14, 15, 25, 26, 27, 32, 33, 34, 35, 36, 37, 38, 39]
if value[CONF_NUMBER] not in valid_pins:
raise cv.Invalid(
"Only pins {} support wakeup"
"".format(", ".join(str(x) for x in valid_pins))
f"Only pins {', '.join(str(x) for x in valid_pins)} support wakeup"
)
return value

Expand Down
4 changes: 1 addition & 3 deletions esphome/components/esp32_ble_beacon/__init__.py
Expand Up @@ -24,9 +24,7 @@

async def to_code(config):
uuid = config[CONF_UUID].hex
uuid_arr = [
cg.RawExpression("0x{}".format(uuid[i : i + 2])) for i in range(0, len(uuid), 2)
]
uuid_arr = [cg.RawExpression(f"0x{uuid[i:i + 2]}") for i in range(0, len(uuid), 2)]
var = cg.new_Pvariable(config[CONF_ID], uuid_arr)
await cg.register_component(var, config)
cg.add(var.set_major(config[CONF_MAJOR]))
Expand Down
13 changes: 4 additions & 9 deletions esphome/components/esp32_ble_tracker/__init__.py
Expand Up @@ -51,8 +51,7 @@ def validate_scan_parameters(config):

if window > interval:
raise cv.Invalid(
"Scan window ({}) needs to be smaller than scan interval ({})"
"".format(window, interval)
f"Scan window ({window}) needs to be smaller than scan interval ({interval})"
)

if interval.total_milliseconds * 3 > duration.total_milliseconds:
Expand Down Expand Up @@ -97,9 +96,7 @@ def bt_uuid(value):
)
return value
raise cv.Invalid(
"Service UUID must be in 16 bit '{}', 32 bit '{}', or 128 bit '{}' format".format(
bt_uuid16_format, bt_uuid32_format, bt_uuid128_format
)
f"Service UUID must be in 16 bit '{bt_uuid16_format}', 32 bit '{bt_uuid32_format}', or 128 bit '{bt_uuid128_format}' format"
)


Expand All @@ -112,9 +109,7 @@ def as_hex_array(value):
cpp_array = [
f"0x{part}" for part in [value[i : i + 2] for i in range(0, len(value), 2)]
]
return cg.RawExpression(
"(uint8_t*)(const uint8_t[16]){{{}}}".format(",".join(cpp_array))
)
return cg.RawExpression(f"(uint8_t*)(const uint8_t[16]){{{','.join(cpp_array)}}}")


def as_reversed_hex_array(value):
Expand All @@ -123,7 +118,7 @@ def as_reversed_hex_array(value):
f"0x{part}" for part in [value[i : i + 2] for i in range(0, len(value), 2)]
]
return cg.RawExpression(
"(uint8_t*)(const uint8_t[16]){{{}}}".format(",".join(reversed(cpp_array)))
f"(uint8_t*)(const uint8_t[16]){{{','.join(reversed(cpp_array))}}}"
)


Expand Down
5 changes: 2 additions & 3 deletions esphome/components/font/__init__.py
Expand Up @@ -61,8 +61,7 @@ def validate_pillow_installed(value):
def validate_truetype_file(value):
if value.endswith(".zip"): # for Google Fonts downloads
raise cv.Invalid(
"Please unzip the font archive '{}' first and then use the .ttf files "
"inside.".format(value)
f"Please unzip the font archive '{value}' first and then use the .ttf files inside."
)
if not value.endswith(".ttf"):
raise cv.Invalid(
Expand Down Expand Up @@ -131,7 +130,7 @@ async def to_code(config):
("a_char", glyph),
(
"data",
cg.RawExpression(str(prog_arr) + " + " + str(glyph_args[glyph][0])),
cg.RawExpression(f"{str(prog_arr)} + {str(glyph_args[glyph][0])}"),
),
("offset_x", glyph_args[glyph][1]),
("offset_y", glyph_args[glyph][2]),
Expand Down
3 changes: 1 addition & 2 deletions esphome/components/lcd_gpio/display.py
Expand Up @@ -20,8 +20,7 @@
def validate_pin_length(value):
if len(value) != 4 and len(value) != 8:
raise cv.Invalid(
"LCD Displays can either operate in 4-pin or 8-pin mode,"
"not {}-pin mode".format(len(value))
f"LCD Displays can either operate in 4-pin or 8-pin mode,not {len(value)}-pin mode"
)
return value

Expand Down
6 changes: 2 additions & 4 deletions esphome/components/ledc/output.py
Expand Up @@ -28,13 +28,11 @@ def validate_frequency(value):
max_freq = calc_max_frequency(1)
if value < min_freq:
raise cv.Invalid(
"This frequency setting is not possible, please choose a higher "
"frequency (at least {}Hz)".format(int(min_freq))
f"This frequency setting is not possible, please choose a higher frequency (at least {int(min_freq)}Hz)"
)
if value > max_freq:
raise cv.Invalid(
"This frequency setting is not possible, please choose a lower "
"frequency (at most {}Hz)".format(int(max_freq))
f"This frequency setting is not possible, please choose a lower frequency (at most {int(max_freq)}Hz)"
)
return value

Expand Down
6 changes: 2 additions & 4 deletions esphome/components/light/effects.py
Expand Up @@ -490,8 +490,7 @@ def validator(value):
if key not in allowed_effects:
errors.append(
cv.Invalid(
"The effect '{}' is not allowed for this "
"light type".format(key),
f"The effect '{key}' is not allowed for this light type",
[i],
)
)
Expand All @@ -500,8 +499,7 @@ def validator(value):
if name in names:
errors.append(
cv.Invalid(
"Found the effect name '{}' twice. All effects must have "
"unique names".format(name),
f"Found the effect name '{name}' twice. All effects must have unique names",
[i],
)
)
Expand Down
8 changes: 3 additions & 5 deletions esphome/components/logger/__init__.py
Expand Up @@ -86,8 +86,7 @@ def validate_local_no_higher_than_global(value):
for tag, level in value.get(CONF_LOGS, {}).items():
if LOG_LEVEL_SEVERITY.index(level) > LOG_LEVEL_SEVERITY.index(global_level):
raise EsphomeError(
"The local log level {} for {} must be less severe than the "
"global log level {}.".format(level, tag, global_level)
f"The local log level {level} for {tag} must be less severe than the global log level {global_level}."
)
return value

Expand Down Expand Up @@ -145,7 +144,7 @@ async def to_code(config):
level = config[CONF_LEVEL]
cg.add_define("USE_LOGGER")
this_severity = LOG_LEVEL_SEVERITY.index(level)
cg.add_build_flag("-DESPHOME_LOG_LEVEL={}".format(LOG_LEVELS[level]))
cg.add_build_flag(f"-DESPHOME_LOG_LEVEL={LOG_LEVELS[level]}")

verbose_severity = LOG_LEVEL_SEVERITY.index("VERBOSE")
very_verbose_severity = LOG_LEVEL_SEVERITY.index("VERY_VERBOSE")
Expand Down Expand Up @@ -220,8 +219,7 @@ def validate_printf(value):
matches = re.findall(cfmt, value[CONF_FORMAT], flags=re.X)
if len(matches) != len(value[CONF_ARGS]):
raise cv.Invalid(
"Found {} printf-patterns ({}), but {} args were given!"
"".format(len(matches), ", ".join(matches), len(value[CONF_ARGS]))
f"Found {len(matches)} printf-patterns ({', '.join(matches)}), but {len(value[CONF_ARGS])} args were given!"
)
return value

Expand Down
7 changes: 2 additions & 5 deletions esphome/components/mqtt/__init__.py
Expand Up @@ -266,8 +266,7 @@ async def to_code(config):
if CONF_SSL_FINGERPRINTS in config:
for fingerprint in config[CONF_SSL_FINGERPRINTS]:
arr = [
cg.RawExpression("0x{}".format(fingerprint[i : i + 2]))
for i in range(0, 40, 2)
cg.RawExpression(f"0x{fingerprint[i:i + 2]}") for i in range(0, 40, 2)
]
cg.add(var.add_ssl_fingerprint(arr))
cg.add_build_flag("-DASYNC_TCP_SSL_ENABLED=1")
Expand Down Expand Up @@ -353,9 +352,7 @@ def get_default_topic_for(data, component_type, name, suffix):
sanitized_name = "".join(
x for x in name.lower().replace(" ", "_") if x in allowlist
)
return "{}/{}/{}/{}".format(
data.topic_prefix, component_type, sanitized_name, suffix
)
return f"{data.topic_prefix}/{component_type}/{sanitized_name}/{suffix}"


async def register_mqtt_component(var, config):
Expand Down
8 changes: 3 additions & 5 deletions esphome/components/neopixelbus/light.py
Expand Up @@ -40,7 +40,7 @@ def validate_type(value):
raise cv.Invalid("Must have B in type")
rest = set(value) - set("RGBW")
if rest:
raise cv.Invalid("Type has invalid color: {}".format(", ".join(rest)))
raise cv.Invalid(f"Type has invalid color: {', '.join(rest)}")
if len(set(value)) != len(value):
raise cv.Invalid("Type has duplicate color!")
return value
Expand Down Expand Up @@ -95,9 +95,7 @@ def validate_method_pin(value):
for opt in (CONF_PIN, CONF_CLOCK_PIN, CONF_DATA_PIN):
if opt in value and value[opt] not in pins_:
raise cv.Invalid(
"Method {} only supports pin(s) {}".format(
method, ", ".join(f"GPIO{x}" for x in pins_)
),
f"Method {method} only supports pin(s) {', '.join(f'GPIO{x}' for x in pins_)}",
path=[CONF_METHOD],
)
return value
Expand Down Expand Up @@ -139,7 +137,7 @@ def format_method(config):

if config[CONF_INVERT]:
if method == "ESP8266_DMA":
variant = "Inverted" + variant
variant = f"Inverted{variant}"
else:
variant += "Inverted"

Expand Down
6 changes: 2 additions & 4 deletions esphome/components/nextion/base_component.py
Expand Up @@ -30,16 +30,14 @@


def NextionName(value):
valid_chars = ascii_letters + digits + "."
valid_chars = f"{ascii_letters + digits}."
if not isinstance(value, str) or len(value) > 29:
raise cv.Invalid("Must be a string less than 29 characters")

for char in value:
if char not in valid_chars:
raise cv.Invalid(
"Must only consist of upper/lowercase characters, numbers and the period '.'. The character '{}' cannot be used.".format(
char
)
f"Must only consist of upper/lowercase characters, numbers and the period '.'. The character '{char}' cannot be used."
)

return value
Expand Down
4 changes: 1 addition & 3 deletions esphome/components/ntc/sensor.py
Expand Up @@ -105,9 +105,7 @@ def process_calibration(value):
a, b, c = calc_steinhart_hart(value)
else:
raise cv.Invalid(
"Calibration parameter accepts either a list for steinhart-hart "
"calibration, or mapping for b-constant calibration, "
"not {}".format(type(value))
f"Calibration parameter accepts either a list for steinhart-hart calibration, or mapping for b-constant calibration, not {type(value)}"
)

return {
Expand Down
3 changes: 1 addition & 2 deletions esphome/components/packages/__init__.py
Expand Up @@ -151,8 +151,7 @@ def do_packages_pass(config: dict):
packages = CONFIG_SCHEMA(packages)
if not isinstance(packages, dict):
raise cv.Invalid(
"Packages must be a key to value mapping, got {} instead"
"".format(type(packages))
f"Packages must be a key to value mapping, got {type(packages)} instead"
)

for package_name, package_config in packages.items():
Expand Down
3 changes: 1 addition & 2 deletions esphome/components/partition/light.py
Expand Up @@ -20,8 +20,7 @@
def validate_from_to(value):
if value[CONF_FROM] > value[CONF_TO]:
raise cv.Invalid(
"From ({}) must not be larger than to ({})"
"".format(value[CONF_FROM], value[CONF_TO])
f"From ({value[CONF_FROM]}) must not be larger than to ({value[CONF_TO]})"
)
return value

Expand Down
4 changes: 1 addition & 3 deletions esphome/components/pmsx003/sensor.py
Expand Up @@ -63,9 +63,7 @@
def validate_pmsx003_sensors(value):
for key, types in SENSORS_TO_TYPE.items():
if key in value and value[CONF_TYPE] not in types:
raise cv.Invalid(
"{} does not have {} sensor!".format(value[CONF_TYPE], key)
)
raise cv.Invalid(f"{value[CONF_TYPE]} does not have {key} sensor!")
return value


Expand Down