From b31ac31136c568f322015cf170371c6b43909ce6 Mon Sep 17 00:00:00 2001 From: clydebarrow <2366188+clydebarrow@users.noreply.github.com> Date: Wed, 28 Aug 2024 19:08:42 +1000 Subject: [PATCH] Revise tests and imports --- esphome/components/image/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/esphome/components/image/__init__.py b/esphome/components/image/__init__.py index 72823c9228..16bf5529e1 100644 --- a/esphome/components/image/__init__.py +++ b/esphome/components/image/__init__.py @@ -6,8 +6,6 @@ import logging from pathlib import Path import re -from PIL import UnidentifiedImageError - from esphome import core, external_files import esphome.codegen as cg from esphome.components import font @@ -259,7 +257,7 @@ def load_svg_image(file: bytes, resize: tuple[int, int]): async def to_code(config): # Local import only to allow "validate_pillow_installed" to run *before* importing it - from PIL import Image + from PIL import Image, UnidentifiedImageError conf_file = config[CONF_FILE] @@ -272,6 +270,9 @@ async def to_code(config): elif conf_file[CONF_SOURCE] == SOURCE_WEB: path = compute_local_image_path(conf_file).as_posix() + else: + raise core.EsphomeError("Unknown image source type") + try: with open(path, "rb") as f: file_contents = f.read() @@ -284,7 +285,10 @@ async def to_code(config): if resize: image.thumbnail(resize) except UnidentifiedImageError as exc: - if "