From 443b678d8a56531edccd0ca05560c2c54bd9baaa Mon Sep 17 00:00:00 2001 From: Amanda Duffy Date: Tue, 2 May 2017 14:54:18 -0400 Subject: [PATCH] Add power off detection --- confluent_client/bin/confetty | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index 64764a5e..f53649e6 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -576,7 +576,7 @@ def conserver_command(filehandle, localcommand): tlvdata.send(session.connection, {'operation': 'break', 'path': currconsole}) print("break sent]\r") - elif localcommand[0] == 'p': # print + elif localcommand[0] == 'p': # power cmdlen += 1 localcommand = get_command_bytes(filehandle, localcommand, cmdlen) @@ -651,6 +651,12 @@ def conserver_command(filehandle, localcommand): else: print("Unknown power state.]\r") + global powerstate + powerstate = list(session.read('/nodes/' + consolename + '/power/state'))[0]['state']['value'] + powertime = time.time() + if powerstate == 'off': + sys.stdout.write("\r\n[powered off]\r\n") + elif localcommand[0] == '?': print("help]\r") print(". disconnect\r") @@ -757,6 +763,8 @@ elif shellargs: do_command(command, netserver) quitconfetty(fullexit=True, fixterm=False) +powerstate = None +powertime = None while inconsole or not doexit: if inconsole: rdylist, _, _ = select.select( @@ -810,6 +818,11 @@ while inconsole or not doexit: myinput = check_escape_seq(myinput, fh) if myinput: tlvdata.send(session.connection, myinput) + if powerstate is None or powertime < time.time() - 60: # Check powerstate every 60 seconds + powerstate = list(session.read('/nodes/' + consolename + '/power/state'))[0]['state']['value'] + powertime = time.time() + if powerstate == 'off': + sys.stdout.write("\r\n[powered off]\r\n") else: currcommand = prompt() try: