fulvia/modules/iot.py

61 lines
1.5 KiB
Python
Raw Normal View History

2018-03-16 03:13:43 -04:00
#!/usr/bin/env python3
"""
Long live the Internet of Things!
"""
import requests
import module
@module.require_admin
@module.commands('lamp')
def lampToggle(bot, trigger):
"""
Turns my lamp on and off. The glory of IoT!
"""
try:
res = requests.get("http://192.168.1.12/gpio?0=toggle", timeout=10)
except requests.exceptions.ReadTimeout:
return bot.say("Connection error. Timeout reached.")
except requests.exceptions.ConnectionError:
return bot.say("Connection error. Is the unit dead?")
if res.text[32] == 'L':
bot.say("Lamp is now OFF.")
elif res.text[32] == 'H':
bot.say("Lamp is now ON.")
#@module.require_admin
@module.commands('roomtemp')
def roomTemp(bot, trigger):
"""
Gets the temperature of my room.
"""
try:
res = requests.get("http://192.168.1.25/", timeout=10)
except requests.exceptions.ReadTimeout:
return bot.say("Connection error. Timeout reached.")
except requests.exceptions.ConnectionError:
return bot.say("Connection error. Is the unit dead?")
bot.say(res.text)
@module.require_admin
@module.commands('inkwrite')
def inkWrite(bot, trigger):
"""
Writes shit to my e-ink screen.
"""
text = trigger.replace(".inkwrite ", "")
if not text:
return bot.say("Need something to write.")
try:
res = requests.get(f"http://192.168.1.125:8000/?text={text}",
timeout=10)
except requests.exceptions.ReadTimeout:
return bot.say("Connection error. Timeout reached.")
except requests.exceptions.ConnectionError:
return bot.say("Connection error. Is the unit dead?")
bot.say("Wrote: " + res.text)