pnbruckner / ha-entity-tz

Home Assistant Entity Time Zone Sensor
The Unlicense
3 stars 0 forks source link

Handle timezonefinder exception #9

Closed pnbruckner closed 7 months ago

pnbruckner commented 8 months ago

This sometimes happens:

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/entity_tz/helpers.py:83
integration: Entity Time Zone (documentation, issues)
First occurred: March 17, 2024 at 11:31:54 AM (2 occurrences)
Last logged: 7:57:54 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/entity_tz/__init__.py", line 102, in update_from_entity
    entity_tz = await get_tz(hass, new_state)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/entity_tz/helpers.py", line 98, in get_tz
    tz = await hass.async_add_executor_job(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/entity_tz/helpers.py", line 83, in _get_tz_from_loc
    if (tz_name := tzf.timezone_at(lat=lat, lng=lng)) is None:
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/timezonefinder/timezonefinder.py", line 677, in timezone_at
    ids = self.id_list(possible_polygons, nr_possible_polygons)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/timezonefinder/timezonefinder.py", line 435, in id_list
    zone_id = self.id_of(polygon_id)
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/timezonefinder/timezonefinder.py", line 274, in id_of
    return unpack(DTYPE_FORMAT_H, poly_zone_ids.read(NR_BYTES_H))[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack requires a buffer of 2 bytes