RenierM26 / ha-ezviz

Ezviz component for HASSIO, testing latest additions to official integration. (The few I work on at least)
GNU General Public License v3.0
45 stars 21 forks source link

[Feature Request] Encrypted last motion images support #128

Open Choochmeque opened 1 year ago

Choochmeque commented 1 year ago

Hello! It would be great to have support for encrypted images as well.

martinl commented 5 months ago

pyezviz implements the required the decrypt_image function. Here is a quick POC that downloads the last motion image, decrypts it if encryption is enabled and writes it to disk.

from pyezviz import EzvizClient, EzvizCamera, constants
from pyezviz.utils import decrypt_image
import sys
import pprint
import requests

def main():
    client = EzvizClient("email", "password", "eu")
    decrypt_key = "decrypt-key"
    try:
        client.login()
        camera = EzvizCamera(client, "serial")
        status = camera.status()
        pprint.pprint(status)
        encryption = status['encrypted']
        last_motion_image_url = status['last_alarm_pic']

        print(last_motion_image_url)
        response = requests.get(last_motion_image_url)

        if response.status_code == 200:
          image_content = decrypt_image(response.content, decrypt_key) if encryption else response.content

          with open("last_motion_image.jpg", "wb") as file:
            file.write(image_content)
            print("image downloaded")

    except BaseException as exp:
        print(exp)
        return 1
    finally:
        client.close_session()
if __name__ == '__main__':
    sys.exit(main())
martinl commented 5 months ago

open PR https://github.com/home-assistant/core/pull/112074

DeKaN commented 5 months ago

I hope @RenierM26 will find time to review the PR :)