@@ -193,8 +193,8 @@ async def unsubscribe(client, uuid):
193
193
except KeyError :
194
194
# This happens on windows, I don't know why
195
195
pass
196
- except Exception as e :
197
- telegram_send . send ( messages = [ "` Exception: ` " + str (e )], parse_mode = "markdown" )
196
+ except Exception as ex :
197
+ sendToTelegram ( " Exception: " + str (ex ), "markdown" )
198
198
print ("Exception: " , e )
199
199
200
200
async def move_to (client , target ):
@@ -257,7 +257,6 @@ def _move_to(sender, data):
257
257
await asyncio .wait_for (move_done , timeout = config ['movement_timeout' ])
258
258
except asyncio .TimeoutError as e :
259
259
print ('Timed out while waiting for desk' )
260
- telegram_send .send (messages = ["`Timed out while waiting for desk`" ], parse_mode = 'markdown' )
261
260
await unsubscribe (client , UUID_HEIGHT )
262
261
263
262
def unpickle_desk ():
@@ -368,21 +367,31 @@ async def run_command(client, config):
368
367
await asyncio .sleep (1 )
369
368
final_height , speed = struct .unpack ("<Hh" , await client .read_gatt_char (UUID_HEIGHT ))
370
369
print ("Final height: {:4.0f}mm (Target: {:4.0f}mm)" .format (rawToMM (final_height ), rawToMM (target )))
370
+ printFinalHeightToFile (rawToMM (final_height ))
371
+
372
+ def printFinalHeightToFile (height ):
373
+ writePath = os .path .dirname (os .path .realpath (__file__ )) + "/desk_height.json"
374
+ with open (writePath , "w" ) as file :
375
+ height_wo_unit = str (height ).split ("mm" )[0 ]
376
+ file .write ('{"final_height": ' + height_wo_unit + '}' )
371
377
372
378
def skip_check ():
373
- """ If force flag is provided, do not skip"""
379
+ # If force flag is provided, do not skip"""
374
380
args , leftovers = parser .parse_known_args ()
375
381
if args .force is not False :
376
- telegram_send . send ( messages = [ "` Force mode`" ], parse_mode = "markdown" )
382
+ sendToTelegram ( " Force mode" , "markdown" )
377
383
return False
378
- """ Check the script's modification date to see if it was 'touched' today"""
384
+ # Check the script's modification date to see if it was 'touched' today"""
379
385
t = os .path .getmtime (__file__ )
380
386
modification_day = datetime .datetime .fromtimestamp (t ).day
381
387
if (modification_day == datetime .date .today ().day ):
382
- telegram_send . send ( messages = [ "` Skipping`" ], parse_mode = "markdown" )
388
+ sendToTelegram ( " Skipping" , "markdown" )
383
389
return True
384
390
return False
385
391
392
+ def sendToTelegram (message , parse_mode ):
393
+ telegram_send .send (messages = ["`" + message + "`" ], parse_mode = parse_mode )
394
+
386
395
async def run_server (client , config ):
387
396
"""Start a tcp server to listen for commands"""
388
397
def disconnect_callback (client , _ = None ):
0 commit comments