rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
382 stars 74 forks source link

Is snapshot making proper jpg with mimetype? #200

Open pszafer opened 2 years ago

pszafer commented 2 years ago

Version of the custom_component

Version 0.9.40

Configuration


Error sending photo: Image_process_failed. Args: (), kwargs: {'chat_id': 839230461, 'photo': <_io.BufferedReader name='/config/www/tmp/sn_front.jpg'>, 'caption': 'Auto', 'disable_notification': False, 'reply_markup': None, 'timeout': None, 'parse_mode': 'Markdown'}

Describe the bug

Hello, first, thanks for this integration! I want to send picture via telegram bot when somebody is detected.

I used automation like this:

 - service: camera.snapshot
    data:
      filename: /config/www/tmp/sn_front.jpeg
    target:
      entity_id: camera.front_sub_2
  - service: notify.tgw
    data:
      data:
        photo:
          file: /config/www/tmp/sn_front.jpeg
          caption: Auto
      message: Samochod front

it end up with log as above. Looking through other issues it seems that snapshot service is making jpg without proper mimetype. https://github.com/home-assistant/core/issues/7413

Can you check it out? Thanks!

pszafer commented 2 years ago

Just if somebody has same issue, I made workaround with pyscript addon from HACS:

from PIL import Image

@service
def convert_image(filename):
   with Image.open(f"/config/www/tmp/{filename}", "r") as im:
      im.save(f"/config/www/tmp/{filename}")

and run service just before sending to telegram_bot.

@rroller let me know if you'd like to get some more info or should I close the issue (I guess it's more Dahua firmware bug)

jrb80 commented 1 year ago

I have the same issue with a DB61 doorbell but when I checked the mime type of the file it read correctly as image/jpeg. Identical to other fully functional Dahua cameras. I suspect there is something else preventing the snapshot camera service from working. If I use the ONVIF integration with the same DB61 doorbell camera the snapshot service works just fine, the problem is something to do with the HTTP API / Dahua integration...