cyberjunky / home-assistant-garmin_connect

The Garmin Connect integration allows you to expose data from Garmin Connect to Home Assistant.
MIT License
249 stars 36 forks source link

Detected blocking call warning as of Home Assistant 2024.5 (due to using get_localzone() function) #181

Open Broekman opened 5 months ago

Broekman commented 5 months ago

Detected blocking call warning as of Home Assistant 2024.5 (call to open in get_localzone() function)

Detected blocking call to open inside the event loop by custom integration 'garmin_connect' at custom_components/garmin_connect/sensor.py, line 196: tz = get_localzone() (offender: /usr/local/lib/python3.12/site-packages/tzlocal/unix.py, line 62: with open(tzpath) as tzfile:), please create a bug report at https://github.com/cyberjunky/home-assistant-garmin_connect/issues

As of Home Assistant 2024.5 this generates a warning during startup for each call.

Affected are lines 186 and line 196 in sensor.py

Option would make tz = get_localzone() constant at a top level and use it further down.

E.g. at top of sensor.py: __TZ = get_localzone()

Remove lines 186 and 196 and update "timezone_date_time_obj = date_time_obj.replace(tzinfo=tz)" with "timezone_date_time_obj = date_time_obj.replace(tzinfo=__TZ)"

Not sure if that works though.