From d3d511477ba2e28e6edd5c7374cf7a15bd012704 Mon Sep 17 00:00:00 2001 From: linus Date: Mon, 28 Oct 2024 07:26:02 +0100 Subject: [PATCH] Rework image creation --- src/CHANGELOG.md | 5 +++++ src/config.yaml | 2 +- src/const.py | 2 +- src/mqtt.py | 48 +++++++++++++++++------------------------------- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index fdc39aa..7c2075a 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.10.5 +### 🐛 Bug Fixes: + +- Fix interior and exterior images if more than one car is in use + ## v1.10.4 ### 🐛 Bug Fixes: diff --git a/src/config.yaml b/src/config.yaml index 987cb97..87a8b5e 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -1,6 +1,6 @@ name: "Volvo2Mqtt" description: "Volvo AAOS MQTT bridge" -version: "1.10.4" +version: "1.10.5" slug: "volvo2mqtt" init: false url: "https://github.com/Dielee/volvo2mqtt" diff --git a/src/const.py b/src/const.py index f4988b7..6143151 100644 --- a/src/const.py +++ b/src/const.py @@ -1,6 +1,6 @@ from config import settings -VERSION = "v1.10.4" +VERSION = "v1.10.5" OAUTH_TOKEN_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2" OAUTH_AUTH_URL = "https://volvoid.eu.volvocars.com/as/authorization.oauth2" diff --git a/src/mqtt.py b/src/mqtt.py index 712cfb4..ec598a4 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -108,37 +108,23 @@ def send_car_images(vin, data, device): "sec-ch-ua-platform": "\"Windows\"", "sec-fetch-dest": "document", "Accept-Encoding": "gzip, deflate, br, zstd", "sec-fetch-mode": "navigate", "sec-fetch-site": "none", "sec-fetch-user": "?1", "upgrade-insecure-requests": "1"} - # Post exterior image - if entity["id"] == "exterior_image": - if not os.path.exists("exterior_image.png"): - response = requests.get(data["images"]["exteriorImageUrl"], headers=headers) - if response.status_code == 200: - with open("exterior_image.png", 'wb') as image: - image.write(response.content) - - if os.path.exists("exterior_image.png"): - ext_image = open("exterior_image.png", mode="rb").read() - mqtt_client.publish( - image_topic, - ext_image, - retain=True - ) - - if entity["id"] == "interior_image": - # Post interior Image - if not os.path.exists("interior_image.png"): - response = requests.get(data["images"]["internalImageUrl"], headers=headers) - if response.status_code == 200: - with open("interior_image.png", 'wb') as image: - image.write(response.content) - - if os.path.exists("interior_image.png"): - int_image = open("interior_image.png", mode="rb").read() - mqtt_client.publish( - image_topic, - int_image, - retain=True - ) + # Post Images + if not os.path.exists(f'{entity["id"]}_{vin}.png'): + data_path = "exteriorImageUrl" if entity["id"] == "exterior_image" else "internalImageUrl" + response = requests.get(data["images"][data_path], headers=headers) + if response.status_code == 200: + with open(f'{entity["id"]}_{vin}.png', 'wb') as image: + image.write(response.content) + else: + logging.warning("Error getting car images: " + str(response.status_code) + " Message: " + response.text) + + if os.path.exists(f'{entity["id"]}_{vin}.png'): + ext_image = open(f'{entity["id"]}_{vin}.png', mode="rb").read() + mqtt_client.publish( + image_topic, + ext_image, + retain=True + ) def on_connect(client, userdata, flags, rc):