Skip to content

Commit

Permalink
Catch TimezoneFinder.timezone_at struct.error exception
Browse files Browse the repository at this point in the history
  • Loading branch information
pnbruckner committed Mar 21, 2024
1 parent ffcfc95 commit 305f1c1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion custom_components/entity_tz/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from enum import Enum, auto
from functools import lru_cache
import logging
import struct
from typing import Any, cast
from zoneinfo import available_timezones

Expand Down Expand Up @@ -80,7 +81,13 @@ def _get_tz_from_loc(tzf: TimezoneFinder, lat: float, lng: float) -> tzinfo | No
This must be run in an executor since timezone_at may do file I/O.
"""
if (tz_name := tzf.timezone_at(lat=lat, lng=lng)) is None:
try:
if (tz_name := tzf.timezone_at(lat=lat, lng=lng)) is None:
return None
except struct.error as err:
_LOGGER.debug(
"Getting time zone at (%f, %f) resulted in error: %r", lat, lng, err
)
return None
return dt_util.get_time_zone(tz_name)

Expand Down

0 comments on commit 305f1c1

Please sign in to comment.