7
7
import requests
8
8
import base64
9
9
from flask_babel import gettext
10
- from subprocess import Popen , PIPE
10
+ #from subprocess import Popen, PIPE
11
+ import subprocess
11
12
from .telegramNotifications import telegramMsgDict
12
13
13
14
################################################################################################################
@@ -27,6 +28,7 @@ def __init__(self, main):
27
28
self .conSettingsTemp = []
28
29
self .dirHashDict = {}
29
30
self .tmpFileHash = ""
31
+ self ._spoolManagerPluginImplementation = None
30
32
self .port = self .main ._settings .global_get (["server" ,"port" ])
31
33
self .commandDict = {
32
34
"Yes" : {'cmd' : self .cmdYes , 'bind_none' : True },
@@ -303,14 +305,14 @@ def cmdSettings(self,chat_id,from_id,cmd,parameter):
303
305
return
304
306
else :
305
307
if self .main ._settings .get_boolean (["send_gif" ]):
306
- gif_txt = "Desactivate gif"
308
+ gif_txt = "Deactivate gif"
307
309
gif_emo = self .gEmo ('check' )
308
310
else :
309
311
gif_txt = "Activate gif"
310
312
gif_emo = self .gEmo ('error' )
311
313
312
314
if self .main ._settings .get_boolean (["multicam" ]):
313
- multicam_txt = "Desactivate management of multicam"
315
+ multicam_txt = "Deactivate management of multicam"
314
316
multicam_emo = self .gEmo ('check' )
315
317
else :
316
318
multicam_txt = "Activate mangement of multicam"
@@ -1244,6 +1246,105 @@ def cmdFilament(self,chat_id,from_id,cmd,parameter):
1244
1246
keys .append ([[self .main .emojis ['cross mark' ]+ gettext (" Close" ),"No" ]])
1245
1247
msg_id = self .main .getUpdateMsgId (chat_id ) if parameter == "back" else ""
1246
1248
self .main .send_msg (message ,chatID = chat_id ,responses = keys ,msg_id = msg_id )
1249
+ elif self .main ._plugin_manager .get_plugin ("SpoolManager" ,True ):
1250
+ if parameter and parameter != "back" :
1251
+ self ._logger .info ("Parameter received for filament: %s" % parameter )
1252
+ params = parameter .split ('_' )
1253
+ apikey = self .main ._settings .global_get (['api' ,'key' ])
1254
+ errorText = ""
1255
+ if params [0 ] == "spools" :
1256
+ try :
1257
+
1258
+ if self ._spoolManagerPluginImplementation == None :
1259
+ self ._spoolManagerPluginImplementation = self .main ._plugin_manager .get_plugin ("SpoolManager" ,True )
1260
+ message = "SpoolManager: " + str (self ._spoolManagerPluginImplementation .SpoolManagerAPI .load_allSpools ())
1261
+ #selectedSpool = self._spoolManagerPluginImplementation.filamentManager.loadSelectedSpool()
1262
+ #allSpool = self._spoolManagerPluginImplementation.filamentManager.load_allSpools
1263
+ #message ="selectedSpool= " +str(selectedSpool) + "\nallSpool=" +str(allSpool)
1264
+
1265
+ # resp = requests.get("http://localhost:" + str(self.port) + "/plugin/spoolmanager/loadSpoolsByQuery?="+query)
1266
+ # resp2 = requests.get("http://localhost:" + str(self.port) + "/plugin/filamentmanager/selections?apikey="+apikey)
1267
+ # if (resp.status_code != 200):
1268
+ # errorText = resp.text
1269
+ # resp = resp.json()
1270
+ # resp2 = resp2.json()
1271
+ # self._logger.info("Spools: %s" % resp["spools"])
1272
+ # message = self.gEmo('info') + " Available filament spools are:\n"
1273
+ # for spool in resp["spools"]:
1274
+ # weight = spool["weight"]
1275
+ # used = spool["used"]
1276
+ # percent = int(100 - (used / weight * 100))
1277
+ # message += str(spool["profile"]["vendor"]) + " " + str(spool["name"]) + " " + str(spool["profile"]["material"]) + " [" + str(percent) + "%]\n"
1278
+ # for selection in resp2["selections"]:
1279
+ # if selection["tool"] == 0:
1280
+ # message += "\n\nCurrently selected: " + str(selection["spool"]["profile"]["vendor"]) + " " + str(selection["spool"]["name"]) + " " + str(selection["spool"]["profile"]["material"])
1281
+ msg_id = self .main .getUpdateMsgId (chat_id )
1282
+ self .main .send_msg (message ,chatID = chat_id ,msg_id = msg_id ,inline = False )
1283
+ except ValueError :
1284
+ message = self .gEmo ('mistake' )+ " Error getting spools. Are you sure, you have installed the Spool Manager Plugin?"
1285
+ if (errorText != "" ):
1286
+ message += "\n Error text: " + str (errorText )
1287
+ msg_id = self .main .getUpdateMsgId (chat_id )
1288
+ self .main .send_msg (message ,chatID = chat_id ,msg_id = msg_id ,inline = False )
1289
+ if params [0 ] == "changeSpool" :
1290
+ self ._logger .info ("Command to change spool: %s" % params )
1291
+ if len (params ) > 1 :
1292
+ self ._logger .info ("Changing to spool: %s" % params [1 ])
1293
+ try :
1294
+ payload = {"selection" : {"spool" : {"id" : params [1 ]},"tool" : 0 }}
1295
+ self ._logger .info ("Payload: %s" % payload )
1296
+ resp = requests .patch ("http://localhost:" + str (self .port ) + "/plugin/filamentmanager/selections/0?apikey=" + apikey , json = payload , headers = {'Content-Type' : 'application/json' })
1297
+ if (resp .status_code != 200 ):
1298
+ errorText = resp .text
1299
+ self ._logger .info ("Response: %s" % resp )
1300
+ resp = resp .json ()
1301
+ message = self .gEmo ('check' ) + " Selected spool is now: " + str (resp ["selection" ]["spool" ]["profile" ]["vendor" ]) + " " + str (resp ["selection" ]["spool" ]["name" ]) + " " + str (resp ["selection" ]["spool" ]["profile" ]["material" ])
1302
+ msg_id = self .main .getUpdateMsgId (chat_id )
1303
+ self .main .send_msg (message ,chatID = chat_id ,msg_id = msg_id ,inline = False )
1304
+ except ValueError :
1305
+ message = self .gEmo ('mistake' )+ " Error changing spool"
1306
+ if (errorText != "" ):
1307
+ message += "\n Error text: " + str (errorText )
1308
+ msg_id = self .main .getUpdateMsgId (chat_id )
1309
+ self .main .send_msg (message ,chatID = chat_id ,msg_id = msg_id ,inline = False )
1310
+ else :
1311
+ self ._logger .info ("Asking for spool" )
1312
+ try :
1313
+ resp = requests .get ("http://localhost:" + str (self .port ) + "/plugin/filamentmanager/spools?apikey=" + apikey )
1314
+ if (resp .status_code != 200 ):
1315
+ errorText = resp .text
1316
+ resp = resp .json ()
1317
+ message = self .gEmo ('question' ) + " which filament spool do you want to select?"
1318
+ keys = []
1319
+ tmpKeys = []
1320
+ i = 1
1321
+ for spool in resp ["spools" ]:
1322
+ self ._logger .info ("Appending spool: %s" % spool )
1323
+ tmpKeys .append ([str (spool ["profile" ]["vendor" ]) + " " + str (spool ['name' ]) + " " + str (spool ["profile" ]["material" ]) ,"/filament_changeSpool_" + str (spool ['id' ])])
1324
+ if i % 2 == 0 :
1325
+ keys .append (tmpKeys )
1326
+ tmpKeys = []
1327
+ i += 1
1328
+ if len (tmpKeys ) > 0 :
1329
+ keys .append (tmpKeys )
1330
+ keys .append ([[self .main .emojis ['cross mark' ]+ gettext (" Close" ),"No" ]])
1331
+ msg_id = self .main .getUpdateMsgId (chat_id )
1332
+ self ._logger .info ("Sending message" )
1333
+ self .main .send_msg (message ,chatID = chat_id ,responses = keys ,msg_id = msg_id )
1334
+ except ValueError :
1335
+ message = self .gEmo ('mistake' )+ " Error changing spool"
1336
+ if (errorText != "" ):
1337
+ message += "\n Error text: " + str (errorText )
1338
+ msg_id = self .main .getUpdateMsgId (chat_id )
1339
+ self .main .send_msg (message ,chatID = chat_id ,msg_id = msg_id ,inline = False )
1340
+ else :
1341
+ message = self .gEmo ('info' ) + " The following Filament Manager commands are known."
1342
+ keys = []
1343
+ keys .append ([["Show spools" ,"/filament_spools" ]])
1344
+ keys .append ([["Change spool" ,"/filament_changeSpool" ]])
1345
+ keys .append ([[self .main .emojis ['cross mark' ]+ gettext (" Close" ),"No" ]])
1346
+ msg_id = self .main .getUpdateMsgId (chat_id ) if parameter == "back" else ""
1347
+ self .main .send_msg (message ,chatID = chat_id ,responses = keys ,msg_id = msg_id )
1247
1348
else :
1248
1349
message = self .gEmo ('warning' ) + " No filament manager plugin installed."
1249
1350
msg_id = self .main .getUpdateMsgId (chat_id ) if parameter == "back" else ""
0 commit comments