HASwitchPlate / openHASP-custom-component

Home Assistant custom component for openHASP
https://www.openhasp.com
MIT License
49 stars 9 forks source link

Image resizing does not work after Home Assitant update 2023.8 because of new pillow version #111

Closed DirkFust closed 11 months ago

DirkFust commented 11 months ago

Perform all steps below and tick them with [x]

Describe the bug

The Home Assitant service openhasp.push_image failed with an error. This seems to be caused by the new pillow version in HomeAssistant 2023.8.0 (pillow 10.0.0 instead of pillow 9.5.0 in 2023.7.0)

 File "/config/custom_components/openhasp/image.py", line 35, in image_to_rgb565
    im.thumbnail((height, width), Image.ANTIALIAS)
                                  ^^^^^^^^^^^^^^^
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

To Reproduce

Create an automation in HomeAssistant and copy and paste this code in yaml mode, objand entitiy_idhave to be adapted to the local plate. Then run this automation manually

alias: BUG DEMO
trigger:
  - platform: time
    at: "00:00:00"
condition: []
action:
  - service: openhasp.push_image
    data:
      image: https://www.openhasp.com/0.6.3/assets/images/logo.png
      width: 240
      height: 240
      obj: p1b1
    target:
      entity_id: openhasp.plate1
mode: single

Expected behavior

The image should be scaled and shown

Possible solution

In file image.py change line 35 from im.thumbnail((height, width), Image.ANTIALIAS) to im.thumbnail((height, width), Image.Resampling.LANCZOS)

Other values are possible (BILINEAR, BICUBIC, ...) but as far as I understood, the old ANTIALIAS used LANCZOS. Other filters produce worse quality but have better performance. But since I assume that only a few images are scaled at a time and displyed on the small screen and those likely are (hopefully) not that large to begin with, LANCZOS should be fine...

Screenshots or video

fvanroie commented 11 months ago

Duplicate of #110

Woutch commented 9 months ago

@fvanroie Any Idea when this is going to stable? I use this to send the doorbell image to my plates to see who is at the door :-)

fvanroie commented 9 months ago

Pre-release version 0.7.1 will become "Stable" when the firmware version 0.7.0 is released. For that to happen, the docs need to be updated and some (minor) issue fixed... There is no timeline, so I don't know yet.