mirror of
https://github.com/esphome/esphome.git
synced 2024-12-01 19:24:14 +01:00
Fix percentage validation for wrong data type input (#3524)
Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
This commit is contained in:
parent
31c4551890
commit
ebca936b7e
1 changed files with 15 additions and 10 deletions
|
@ -1086,6 +1086,7 @@ def possibly_negative_percentage(value):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# pylint: disable=raise-missing-from
|
# pylint: disable=raise-missing-from
|
||||||
raise Invalid("invalid number")
|
raise Invalid("invalid number")
|
||||||
|
try:
|
||||||
if value > 1:
|
if value > 1:
|
||||||
msg = "Percentage must not be higher than 100%."
|
msg = "Percentage must not be higher than 100%."
|
||||||
if not has_percent_sign:
|
if not has_percent_sign:
|
||||||
|
@ -1096,6 +1097,10 @@ def possibly_negative_percentage(value):
|
||||||
if not has_percent_sign:
|
if not has_percent_sign:
|
||||||
msg += " Please put a percent sign after the number!"
|
msg += " Please put a percent sign after the number!"
|
||||||
raise Invalid(msg)
|
raise Invalid(msg)
|
||||||
|
except TypeError:
|
||||||
|
raise Invalid( # pylint: disable=raise-missing-from
|
||||||
|
"Expected percentage or float between -1.0 and 1.0"
|
||||||
|
)
|
||||||
return negative_one_to_one_float(value)
|
return negative_one_to_one_float(value)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue