mirror of
https://github.com/esphome/esphome.git
synced 2026-05-23 11:16:52 +08:00
[time] Point to valid IANA timezone list on validation failure (#15110)
This commit is contained in:
committed by
Jesse Hills
parent
7ecdf6db2e
commit
e261b5de65
@@ -284,13 +284,23 @@ def validate_tz(value: str) -> str:
|
||||
tzfile = _load_tzdata(value)
|
||||
if tzfile is not None:
|
||||
value = _extract_tz_string(tzfile)
|
||||
is_iana = True
|
||||
else:
|
||||
is_iana = False
|
||||
|
||||
# Validate that the POSIX TZ string is parseable (skip empty strings)
|
||||
if value:
|
||||
try:
|
||||
parse_posix_tz_python(value)
|
||||
except ValueError as e:
|
||||
raise cv.Invalid(f"Invalid POSIX timezone string '{value}': {e}") from e
|
||||
if is_iana:
|
||||
raise cv.Invalid(f"Invalid POSIX timezone string '{value}': {e}") from e
|
||||
raise cv.Invalid(
|
||||
f"Invalid POSIX timezone string '{value}': {e}. "
|
||||
f"If you meant to use an IANA timezone, check the list of valid "
|
||||
f"timezones at "
|
||||
f"https://en.wikipedia.org/wiki/List_of_tz_database_time_zones"
|
||||
) from e
|
||||
|
||||
return value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user