From 3b23e7c475205e662f76bb41962b4606360a0012 Mon Sep 17 00:00:00 2001 From: tmjo <54450177+tmjo@users.noreply.github.com> Date: Sat, 5 Feb 2022 19:46:05 +0100 Subject: [PATCH] Update api.py Add broad exception to ensure catching errors caused by missing _imagingft module on some installations. Something seems to have happened in Pillow >8.2. --- custom_components/norwegianweather/api.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/custom_components/norwegianweather/api.py b/custom_components/norwegianweather/api.py index 9b679e8..2542bbb 100644 --- a/custom_components/norwegianweather/api.py +++ b/custom_components/norwegianweather/api.py @@ -274,7 +274,8 @@ def process_weather_image(self, weatherdata, filename=None, qty=6): f"Processing weather image from {len(weatherdata)} time intervals - creating {qty} images." ) cnt = 0 - font = image_font() + _LOGGER.debug(f"PIL/image version: {Image.__version__}") + font = weatherimage_font() for data in weatherdata: time = data.get("time", None) imagedata = image_create_process_data(time, data, self.location.units) @@ -666,19 +667,21 @@ def image_create(imagedata, font): return newimage -def image_font(): +def weatherimage_font(): font = None try: font = ImageFont.truetype(CONST_FILE_FONT, 25) _LOGGER.debug(f"Loaded font {CONST_FILE_FONT} {font}.") - except (TypeError, FileNotFoundError, OSError) as e: + # except (TypeError, FileNotFoundError, OSError) as e: + except Exception as e: _LOGGER.debug(f"Could not apply truetype font {CONST_FILE_FONT} ({e}).") if font is None: try: font = ImageFont.load(CONST_FILE_FONT_PIL) _LOGGER.debug(f"Loaded PIL-font {CONST_FILE_FONT_PIL}.") - except (TypeError, FileNotFoundError, OSError, AttributeError) as e: + # except (TypeError, FileNotFoundError, OSError, AttributeError) as e: + except Exception as e: _LOGGER.debug( f"Could not apply PIL-font {CONST_FILE_FONT_PIL}. Will have to use ugly default font, sorry. ({e})" )