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