|
@@ -1,6 +1,6 @@
|
1
|
1
|
import config
|
2
|
2
|
import logging
|
3
|
|
-import paho.mqtt.client as paho
|
|
3
|
+import mqtt
|
4
|
4
|
import report
|
5
|
5
|
import socket
|
6
|
6
|
import subprocess
|
|
@@ -18,6 +18,8 @@ except ImportError:
|
18
|
18
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main')
|
19
|
19
|
|
20
|
20
|
|
|
21
|
+mc = mqtt.mqtt_client(config.APP_NAME, config.MQTT_SERVER, 1883, config.MQTT_USER, config.MQTT_PASS)
|
|
22
|
+
|
21
|
23
|
class librespot(object):
|
22
|
24
|
ON_CMD = ['play', ]
|
23
|
25
|
OFF_CMD = ['pause', 'stop', ]
|
|
@@ -99,26 +101,14 @@ class librespot(object):
|
99
|
101
|
|
100
|
102
|
|
101
|
103
|
def send_state_msg_mqtt(state):
|
102
|
|
- client= paho.Client(config.APP_NAME)
|
103
|
|
- client.username_pw_set(config.MQTT_USER, config.MQTT_PASS)
|
104
|
|
- try:
|
105
|
|
- client.connect(config.MQTT_SERVER, 1883)
|
106
|
|
- topic = config.MQTT_TOPIC + "/state"
|
107
|
|
- logger.info("Sending Spotify status information to mqtt %s = %s", topic, str(state))
|
108
|
|
- client.publish(topic, "true" if state else "false")
|
109
|
|
- except (socket.timeout, OSError) as e:
|
110
|
|
- logger.warning("Erro while sending state information")
|
|
104
|
+ topic = config.MQTT_TOPIC + "/state"
|
|
105
|
+ logger.info("Sending Spotify status information to mqtt %s = %s", topic, str(state))
|
|
106
|
+ mc.send(topic, "true" if state else "false")
|
111
|
107
|
|
112
|
108
|
def send_title_msg_mqtt(title):
|
113
|
|
- client= paho.Client(config.APP_NAME)
|
114
|
|
- client.username_pw_set(config.MQTT_USER, config.MQTT_PASS)
|
115
|
|
- try:
|
116
|
|
- client.connect(config.MQTT_SERVER, 1883)
|
117
|
|
- topic = config.MQTT_TOPIC + "/title"
|
118
|
|
- logger.info("Sending Spotify status information to mqtt %s = %s", topic, title)
|
119
|
|
- client.publish(topic, title)
|
120
|
|
- except (socket.timeout, OSError) as e:
|
121
|
|
- logger.warning("Erro while sending title information")
|
|
109
|
+ topic = config.MQTT_TOPIC + "/title"
|
|
110
|
+ logger.info("Sending Spotify status information to mqtt %s = %s", topic, title)
|
|
111
|
+ mc.send(topic, title)
|
122
|
112
|
|
123
|
113
|
|
124
|
114
|
if __name__ == '__main__':
|