Message owner when UPS goes on and off battery.

dev
pocketjawa 2018-04-16 01:20:13 -04:00
parent 87b7a15c5a
commit ae459a06f5
1 changed files with 24 additions and 1 deletions

View File

@ -45,9 +45,32 @@ client = discord.Client()
#Subroutine to get UPS Status #Subroutine to get UPS Status
@asyncio.coroutine @asyncio.coroutine
def ups_check(): def ups_check():
yield from client.wait_until_ready()
while not client.is_closed: while not client.is_closed:
yield from asyncio.create_subprocess_exec("/bin/bash", cwd + "/ups_status.sh") yield from asyncio.create_subprocess_exec("/bin/bash", cwd + "/ups_status.sh")
yield from asyncio.sleep(60) yield from asyncio.sleep(5)
#Make temp status file if it doesn't exist
if not os.path.isfile(cwd + "/tmp/ups_status.txt"):
ups_temp = open(cwd + "/tmp/ups_status.txt", "w")
ups_temp.write("ONLINE")
ups_temp.close()
#Message and set status if on battery
if 'ONBATT' in open('/tmp/ups_status.txt').read() and 'ONLINE' in open(cwd + '/tmp/ups_status.txt').read():
yield from client.send_message(bot_channel_id, "<@"+owner_id.id+"> UPS is on battery!")
ups_status = open("/tmp/ups_status.txt","r")
yield from client.send_message(bot_channel_id, ups_status.read())
ups_temp = open(cwd + "/tmp/ups_status.txt", "w")
ups_temp.write("ONBATT")
ups_temp.close()
#Message and set status back to normal when power comes back on
elif 'ONLINE' in open('/tmp/ups_status.txt').read() and 'ONBATT' in open(cwd + '/tmp/ups_status.txt').read():
yield from client.send_message(bot_channel_id, "<@"+owner_id.id+"> UPS is back online!")
ups_status = open("/tmp/ups_status.txt","r")
yield from client.send_message(bot_channel_id, ups_status.read())
ups_temp = open(cwd + "/tmp/ups_status.txt", "w")
ups_temp.write("ONLINE")
ups_temp.close()
yield from asyncio.sleep(55)
@client.event @client.event