Exception handling for MQTT
This commit is contained in:
parent
d8096b0f31
commit
826bd78926
@ -100,19 +100,24 @@ class librespot(object):
|
||||
def send_state_msg_mqtt(state):
|
||||
client= paho.Client("spotify")
|
||||
client.username_pw_set(config.MQTT_USER, config.MQTT_PASS)
|
||||
try:
|
||||
client.connect(config.MQTT_SERVER, 1883)
|
||||
topic = config.MQTT_TOPIC + "/state"
|
||||
logger.info("Sending Spotify status information to mqtt %s = %s", topic, str(state))
|
||||
client.publish(topic, "true" if state else "false")
|
||||
except (socket.timeout, OSError) as e:
|
||||
logger.warning("Erro while sending state information")
|
||||
|
||||
def send_title_msg_mqtt(title):
|
||||
client= paho.Client("spotify")
|
||||
client.username_pw_set(config.MQTT_USER, config.MQTT_PASS)
|
||||
try:
|
||||
client.connect(config.MQTT_SERVER, 1883)
|
||||
topic = config.MQTT_TOPIC + "/title"
|
||||
logger.info("Sending Spotify status information to mqtt %s = %s", topic, title)
|
||||
client.publish(topic, title)
|
||||
|
||||
except (socket.timeout, OSError) as e:
|
||||
logger.warning("Erro while sending title information")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user