Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Add interior and exterior image entities #62
Browse files Browse the repository at this point in the history
  • Loading branch information
Dielee committed Jul 9, 2023
1 parent 10c3e7b commit 96805d4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v1.7.6
### 🚀 Features:

- Added support for interior and exterior images via the new [MQTT Image](https://www.home-assistant.io/integrations/image.mqtt/) entity. #62

<b>NOTE: This feature is only available using homeassistant version 2023.7.1 or greater.</b>

## v1.7.5
### 🚀 Features:

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.7.5"
version: "1.7.6"
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.7.5"
VERSION = "v1.7.6"

OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
Expand Down
42 changes: 40 additions & 2 deletions src/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,43 @@ def connect():
mqtt_client = client


def send_car_images(vin, data, device):
if util.keys_exists(data, "images"):
for entity in [{"name": "Exterior Image", "id": "exterior_image"},
{"name": "Interior Image", "id": "interior_image"}]:
url_topic = f"homeassistant/image/{vin}_{entity['id']}/image_url"
config = {
"name": entity["name"],
"object_id": f"volvo_{vin}_{entity['id']}",
"schema": "state",
"icon": "mdi:image-area",
"url_topic": url_topic,
"device": device,
"unique_id": f"volvoAAOS2mqtt_{vin}_{entity['id']}",
"availability_topic": availability_topic
}

mqtt_client.publish(
f"homeassistant/image/volvoAAOS2mqtt/{vin}_{entity['id']}/config",
json.dumps(config),
retain=True
)

if entity["id"] == "exterior_image":
mqtt_client.publish(
url_topic,
data["images"]["exteriorDefaultUrl"],
retain=True
)

if entity["id"] == "interior_image":
mqtt_client.publish(
url_topic,
data["images"]["interiorDefaultUrl"],
retain=True
)


def on_connect(client, userdata, flags, rc):
send_heartbeat()
if len(subscribed_topics) > 0:
Expand Down Expand Up @@ -232,12 +269,13 @@ def create_ha_devices():

if entity.get("domain") == "device_tracker":
config["json_attributes_topic"] = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/attributes"

if entity.get("domain") in ["switch", "lock", "button"]:
elif entity.get("domain") in ["switch", "lock", "button"]:
command_topic = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/command"
config["command_topic"] = command_topic
subscribed_topics.append(command_topic)
mqtt_client.subscribe(command_topic)
elif entity.get("domain") == "image":
config["url_topic"] = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/image_url"

mqtt_client.publish(
f"homeassistant/{entity['domain']}/volvoAAOS2mqtt/{vin}_{entity['id']}/config",
Expand Down
1 change: 1 addition & 0 deletions src/volvo.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def get_vehicle_details(vin):
"model": data['descriptions']['model'],
"name": f"{data['descriptions']['model']} ({data['modelYear']}) - {vin}",
}
mqtt.send_car_images(vin, data, device)
elif response.status_code == 500 and not settings.volvoData["vin"]:
# Workaround for some cars that are not returning vehicle details
device = {
Expand Down

0 comments on commit 96805d4

Please sign in to comment.