Skip to content

Commit

Permalink
feat: Specify which SW update is available
Browse files Browse the repository at this point in the history
closes: #21
  • Loading branch information
JakobLichterfeld committed Mar 16, 2024
1 parent 8c208a0 commit f0ba749
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### New Features

- feat: Specify which SW update is available (#21)

### Enhancements

- ci: use Environment File instead of deprecated set-output
Expand Down
23 changes: 15 additions & 8 deletions src/teslamte_telegram_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

# MQTT topics
teslamate_topic_update_available = f"teslamate/cars/{car_id}/update_available"
teslamate_topic_update_version =f"teslamate/cars/{car_id}/update_version"

########################################################################################

Expand Down Expand Up @@ -60,18 +61,24 @@ def on_connect(client, userdata, flags, reason_code):
# reconnect then subscriptions will be renewed.
client.subscribe(teslamate_topic_update_available)

update_version = 'unknown'
def on_message(client, userdata, msg):
""" The callback for when a PUBLISH message is received from the server."""
global update_version
print(msg.topic+" "+str(msg.payload))

if msg.payload.decode() == "true":
print("A new SW update for your Tesla is available!")
bot.send_message(
chat_id,
# text="<b>"+"SW Update"+"</b>\n"+"A new SW update for your Tesla is available!\n\n<b>"+msg.topic+"</b>\n"+str(msg.payload.decode()),
text="<b>"+"SW Update"+"</b>\n"+"A new SW update for your Tesla is available!",
parse_mode=ParseMode.HTML,
)
if msg.topic == teslamate_topic_update_version:
update_version = msg.payload.decode()
print(f"Update to version {update_version} available.")

if msg.topic == teslamate_topic_update_available:
if msg.payload.decode() == "true":
print(f"A new SW update to version: {update_version} for your Tesla is available!")
bot.send_message(
chat_id,
text="<b>"+"SW Update"+"</b>\n"+"A new SW update to version: "+ update_version + " for your Tesla is available!",
parse_mode=ParseMode.HTML,
)

def setup_mqtt_client():
""" Setup the MQTT client """
Expand Down

0 comments on commit f0ba749

Please sign in to comment.