Skip to content

Commit

Permalink
Rework image creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dielee committed Oct 28, 2024
1 parent 75db5da commit d3d5114
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
5 changes: 5 additions & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
2 changes: 1 addition & 1 deletion src/config.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/const.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
48 changes: 17 additions & 31 deletions src/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d3d5114

Please sign in to comment.