mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-03 19:38:30 +02:00
Bump pylint from 2.10.2 to 2.11.1 (#2334)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Otto winter <otto@otto-winter.com>
This commit is contained in:
@@ -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":
|
||||
@@ -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])
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
|
||||
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]))
|
||||
|
||||
@@ -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:
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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):
|
||||
@@ -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))}}}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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(
|
||||
@@ -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]),
|
||||
|
||||
@@ -20,8 +20,7 @@ GPIOLCDDisplay = lcd_gpio_ns.class_("GPIOLCDDisplay", lcd_base.LCDDisplay)
|
||||
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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -490,8 +490,7 @@ def validate_effects(allowed_effects):
|
||||
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],
|
||||
)
|
||||
)
|
||||
@@ -500,8 +499,7 @@ def validate_effects(allowed_effects):
|
||||
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],
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -30,16 +30,14 @@ CONF_FONT_ID = "font_id"
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -20,8 +20,7 @@ PartitionLightOutput = partitions_ns.class_(
|
||||
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
|
||||
|
||||
|
||||
@@ -63,9 +63,7 @@ SENSORS_TO_TYPE = {
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -491,8 +491,7 @@ def validate_raw_alternating(value):
|
||||
if i != 0:
|
||||
if this_negative == last_negative:
|
||||
raise cv.Invalid(
|
||||
"Values must alternate between being positive and negative, "
|
||||
"please see index {} and {}".format(i, i + 1),
|
||||
f"Values must alternate between being positive and negative, please see index {i} and {i + 1}",
|
||||
[i],
|
||||
)
|
||||
last_negative = this_negative
|
||||
@@ -619,13 +618,11 @@ def validate_rc_switch_code(value):
|
||||
for c in value:
|
||||
if c not in ("0", "1"):
|
||||
raise cv.Invalid(
|
||||
"Invalid RCSwitch code character '{}'. Only '0' and '1' are allowed"
|
||||
"".format(c)
|
||||
f"Invalid RCSwitch code character '{c}'. Only '0' and '1' are allowed"
|
||||
)
|
||||
if len(value) > 64:
|
||||
raise cv.Invalid(
|
||||
"Maximum length for RCSwitch codes is 64, code '{}' has length {}"
|
||||
"".format(value, len(value))
|
||||
f"Maximum length for RCSwitch codes is 64, code '{value}' has length {len(value)}"
|
||||
)
|
||||
if not value:
|
||||
raise cv.Invalid("RCSwitch code must not be empty")
|
||||
@@ -638,14 +635,11 @@ def validate_rc_switch_raw_code(value):
|
||||
for c in value:
|
||||
if c not in ("0", "1", "x"):
|
||||
raise cv.Invalid(
|
||||
"Invalid RCSwitch raw code character '{}'.Only '0', '1' and 'x' are allowed".format(
|
||||
c
|
||||
)
|
||||
f"Invalid RCSwitch raw code character '{c}'.Only '0', '1' and 'x' are allowed"
|
||||
)
|
||||
if len(value) > 64:
|
||||
raise cv.Invalid(
|
||||
"Maximum length for RCSwitch raw codes is 64, code '{}' has length {}"
|
||||
"".format(value, len(value))
|
||||
f"Maximum length for RCSwitch raw codes is 64, code '{value}' has length {len(value)}"
|
||||
)
|
||||
if not value:
|
||||
raise cv.Invalid("RCSwitch raw code must not be empty")
|
||||
|
||||
@@ -49,8 +49,7 @@ def validate_min_max_value(config):
|
||||
max_val = config[CONF_MAX_VALUE]
|
||||
if min_val >= max_val:
|
||||
raise cv.Invalid(
|
||||
"Max value {} must be smaller than min value {}"
|
||||
"".format(max_val, min_val)
|
||||
f"Max value {max_val} must be smaller than min value {min_val}"
|
||||
)
|
||||
return config
|
||||
|
||||
|
||||
@@ -109,8 +109,7 @@ def validate_send_first_at(value):
|
||||
send_every = value[CONF_SEND_EVERY]
|
||||
if send_first_at is not None and send_first_at > send_every:
|
||||
raise cv.Invalid(
|
||||
"send_first_at must be smaller than or equal to send_every! {} <= {}"
|
||||
"".format(send_first_at, send_every)
|
||||
f"send_first_at must be smaller than or equal to send_every! {send_first_at} <= {send_every}"
|
||||
)
|
||||
return value
|
||||
|
||||
@@ -459,8 +458,7 @@ CONF_DEGREE = "degree"
|
||||
def validate_calibrate_polynomial(config):
|
||||
if config[CONF_DEGREE] >= len(config[CONF_DATAPOINTS]):
|
||||
raise cv.Invalid(
|
||||
"Degree is too high! Maximum possible degree with given datapoints is "
|
||||
"{}".format(len(config[CONF_DATAPOINTS]) - 1),
|
||||
f"Degree is too high! Maximum possible degree with given datapoints is {len(config[CONF_DATAPOINTS]) - 1}",
|
||||
[CONF_DEGREE],
|
||||
)
|
||||
return config
|
||||
|
||||
@@ -25,8 +25,7 @@ def validate_substitution_key(value):
|
||||
for char in value:
|
||||
if char not in VALID_SUBSTITUTIONS_CHARACTERS:
|
||||
raise cv.Invalid(
|
||||
"Substitution must only consist of upper/lowercase characters, the underscore "
|
||||
"and numbers. The character '{}' cannot be used".format(char)
|
||||
f"Substitution must only consist of upper/lowercase characters, the underscore and numbers. The character '{char}' cannot be used"
|
||||
)
|
||||
return value
|
||||
|
||||
@@ -42,6 +41,7 @@ async def to_code(config):
|
||||
pass
|
||||
|
||||
|
||||
# pylint: disable=consider-using-f-string
|
||||
VARIABLE_PROG = re.compile(
|
||||
"\\$([{0}]+|\\{{[{0}]*\\}})".format(VALID_SUBSTITUTIONS_CHARACTERS)
|
||||
)
|
||||
@@ -133,8 +133,7 @@ def do_substitution_pass(config, command_line_substitutions):
|
||||
with cv.prepend_path("substitutions"):
|
||||
if not isinstance(substitutions, dict):
|
||||
raise cv.Invalid(
|
||||
"Substitutions must be a key to value mapping, got {}"
|
||||
"".format(type(substitutions))
|
||||
f"Substitutions must be a key to value mapping, got {type(substitutions)}"
|
||||
)
|
||||
|
||||
replace_keys = []
|
||||
|
||||
@@ -67,9 +67,7 @@ def _week_of_month(dt):
|
||||
|
||||
def _tz_dst_str(dt):
|
||||
td = datetime.timedelta(hours=dt.hour, minutes=dt.minute, seconds=dt.second)
|
||||
return "M{}.{}.{}/{}".format(
|
||||
dt.month, _week_of_month(dt), dt.isoweekday() % 7, _tz_timedelta(td)
|
||||
)
|
||||
return f"M{dt.month}.{_week_of_month(dt)}.{dt.isoweekday() % 7}/{_tz_timedelta(td)}"
|
||||
|
||||
|
||||
def _safe_tzname(tz, dt):
|
||||
@@ -88,7 +86,7 @@ def _non_dst_tz(tz, dt):
|
||||
_LOGGER.info(
|
||||
"Detected timezone '%s' with UTC offset %s", tzname, _tz_timedelta(utcoffset)
|
||||
)
|
||||
tzbase = "{}{}".format(tzname, _tz_timedelta(-1 * utcoffset))
|
||||
tzbase = f"{tzname}{_tz_timedelta(-1 * utcoffset)}"
|
||||
return tzbase
|
||||
|
||||
|
||||
@@ -129,14 +127,9 @@ def convert_tz(pytz_obj):
|
||||
dst_ends_utc = transition_times[idx2]
|
||||
dst_ends_local = dst_ends_utc + utcoffset_on
|
||||
|
||||
tzbase = "{}{}".format(tzname_off, _tz_timedelta(-1 * utcoffset_off))
|
||||
tzbase = f"{tzname_off}{_tz_timedelta(-1 * utcoffset_off)}"
|
||||
|
||||
tzext = "{}{},{},{}".format(
|
||||
tzname_on,
|
||||
_tz_timedelta(-1 * utcoffset_on),
|
||||
_tz_dst_str(dst_begins_local),
|
||||
_tz_dst_str(dst_ends_local),
|
||||
)
|
||||
tzext = f"{tzname_on}{_tz_timedelta(-1 * utcoffset_on)},{_tz_dst_str(dst_begins_local)},{_tz_dst_str(dst_ends_local)}"
|
||||
_LOGGER.info(
|
||||
"Detected timezone '%s' with UTC offset %s and daylight saving time from "
|
||||
"%s to %s",
|
||||
@@ -176,9 +169,7 @@ def _parse_cron_part(part, min_value, max_value, special_mapping):
|
||||
data = part.split("/")
|
||||
if len(data) > 2:
|
||||
raise cv.Invalid(
|
||||
"Can't have more than two '/' in one time expression, got {}".format(
|
||||
part
|
||||
)
|
||||
f"Can't have more than two '/' in one time expression, got {part}"
|
||||
)
|
||||
offset, repeat = data
|
||||
offset_n = 0
|
||||
@@ -194,18 +185,14 @@ def _parse_cron_part(part, min_value, max_value, special_mapping):
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise cv.Invalid(
|
||||
"Repeat for '/' time expression must be an integer, got {}".format(
|
||||
repeat
|
||||
)
|
||||
f"Repeat for '/' time expression must be an integer, got {repeat}"
|
||||
)
|
||||
return set(range(offset_n, max_value + 1, repeat_n))
|
||||
if "-" in part:
|
||||
data = part.split("-")
|
||||
if len(data) > 2:
|
||||
raise cv.Invalid(
|
||||
"Can't have more than two '-' in range time expression '{}'".format(
|
||||
part
|
||||
)
|
||||
f"Can't have more than two '-' in range time expression '{part}'"
|
||||
)
|
||||
begin, end = data
|
||||
begin_n = _parse_cron_int(
|
||||
@@ -233,13 +220,11 @@ def cron_expression_validator(name, min_value, max_value, special_mapping=None):
|
||||
for v in value:
|
||||
if not isinstance(v, int):
|
||||
raise cv.Invalid(
|
||||
"Expected integer for {} '{}', got {}".format(v, name, type(v))
|
||||
f"Expected integer for {v} '{name}', got {type(v)}"
|
||||
)
|
||||
if v < min_value or v > max_value:
|
||||
raise cv.Invalid(
|
||||
"{} {} is out of range (min={} max={}).".format(
|
||||
name, v, min_value, max_value
|
||||
)
|
||||
f"{name} {v} is out of range (min={min_value} max={max_value})."
|
||||
)
|
||||
return list(sorted(value))
|
||||
value = cv.string(value)
|
||||
@@ -295,8 +280,7 @@ def validate_cron_raw(value):
|
||||
value = value.split(" ")
|
||||
if len(value) != 6:
|
||||
raise cv.Invalid(
|
||||
"Cron expression must consist of exactly 6 space-separated parts, "
|
||||
"not {}".format(len(value))
|
||||
f"Cron expression must consist of exactly 6 space-separated parts, not {len(value)}"
|
||||
)
|
||||
seconds, minutes, hours, days_of_month, months, days_of_week = value
|
||||
return {
|
||||
|
||||
@@ -57,6 +57,7 @@ def wrapped_load_pem_private_key(value, password):
|
||||
|
||||
|
||||
def read_relative_config_path(value):
|
||||
# pylint: disable=unspecified-encoding
|
||||
return Path(CORE.relative_config_path(value)).read_text()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user