mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-07-16 19:10:32 +02:00
Correct mqtt @UlrichThiess
https://github.com/alexbelgium/hassio-addons/issues/1515
This commit is contained in:
@@ -27,12 +27,11 @@ settings_dict = dict(conf)
|
||||
mqtt_server = "%%mqtt_server%%"
|
||||
mqtt_user = "%%mqtt_user%%"
|
||||
mqtt_pass = "%%mqtt_pass%%"
|
||||
mqtt_port = "%%mqtt_port%%"
|
||||
mqtt_port = %%mqtt_port%%
|
||||
mqtt_topic = 'birdnet'
|
||||
|
||||
bird_lookup_url_base = 'http://en.wikipedia.org/wiki/'
|
||||
|
||||
def on_connect(client, userdata, flags, rc, properties=None):
|
||||
def on_connect(client, userdata, flags, rc ): #, properties=None):
|
||||
""" Callback for when the client receives a CONNACK response from the server. """
|
||||
if rc == 0:
|
||||
log.info("Connected to MQTT Broker!")
|
||||
@@ -50,9 +49,7 @@ def get_bird_code(scientific_name):
|
||||
|
||||
return bird_dict.get(scientific_name)
|
||||
|
||||
def automatic_mqtt_publish(file, detections):
|
||||
path = ""
|
||||
for detection in detections:
|
||||
def automatic_mqtt_publish(file, detection, path):
|
||||
bird = {}
|
||||
bird['Date'] = file.date
|
||||
bird['Time'] = file.time
|
||||
@@ -61,7 +58,7 @@ def automatic_mqtt_publish(file, detections):
|
||||
bird['Confidence'] = detection.confidence
|
||||
bird['SpeciesCode'] = get_bird_code(detection.scientific_name)
|
||||
bird['ClipName'] = path
|
||||
bird['url'] = bird_lookup_url_base + detection.scientific_name
|
||||
bird['url'] = bird_lookup_url_base + detection.scientific_name.replace(' ', '_')
|
||||
|
||||
# Flickimage
|
||||
image_url = ""
|
||||
@@ -84,9 +81,11 @@ def automatic_mqtt_publish(file, detections):
|
||||
image_url = ""
|
||||
else:
|
||||
image_url = flickr_images[common_name]
|
||||
bird['Flickrimage'] = image_url
|
||||
|
||||
bird['FlickrImage'] = image_url
|
||||
|
||||
json_bird = json.dumps(bird)
|
||||
mqttc.reconnect()
|
||||
mqttc.publish(mqtt_topic, json_bird, 1)
|
||||
log.info("Posted to MQTT: ok")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user