-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from JakobLichterfeld/feature/2-python-implemen…
…tation Python implementation, closes: #2
- Loading branch information
Showing
5 changed files
with
78 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Lines starting with '#' are comments. | ||
# Each line is a file pattern followed by one or more owners. | ||
|
||
# These owners will be the default owners for everything in the repo. | ||
|
||
|
||
# Order is important. The last matching pattern has the most precedence. | ||
# So if a pull request only touches javascript files, only these owners | ||
# will be requested to review. | ||
|
||
|
||
# You can also use email addresses if you prefer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import paho.mqtt.client as mqtt | ||
|
||
from telegram.bot import Bot | ||
from telegram.parsemode import ParseMode | ||
|
||
# initializing the bot with API | ||
bot = Bot('api_key') | ||
|
||
# The callback for when the client receives a CONNACK response from the server. | ||
|
||
|
||
def on_connect(client, userdata, flags, rc): | ||
print("Connected successfully to broker") | ||
|
||
# Subscribing in on_connect() means that if we lose the connection and | ||
# reconnect then subscriptions will be renewed. | ||
|
||
#client.subscribe("teslamate/cars/1/version") | ||
client.subscribe("teslamate/cars/1/update_available") | ||
|
||
|
||
# The callback for when a PUBLISH message is received from the server. | ||
|
||
|
||
def on_message(client, userdata, msg): | ||
print(msg.topic+" "+str(msg.payload.decode())) | ||
|
||
if msg.payload.decode() == "true": | ||
print("A new SW update for your Tesla is available!") | ||
bot.send_message( | ||
chat_id='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, | ||
) | ||
|
||
|
||
client = mqtt.Client() | ||
client.on_connect = on_connect | ||
client.on_message = on_message | ||
|
||
client.connect(mqtt_config.mqtt_data['mqtt_broker_host', 'mqtt_broker_port', 60) | ||
|
||
|
||
# Blocking call that processes network traffic, dispatches callbacks and | ||
# handles reconnecting. | ||
# Other loop*() functions are available that give a threaded interface and a | ||
# manual interface. | ||
# client.loop_forever() | ||
|
||
|
||
client.loop_start() # start the loop | ||
|
||
client.disconnect() | ||
|
||
client.loop_stop() |