sopel/modules/light.py
2017-11-22 19:26:40 -05:00

42 lines
1.0 KiB
Python
Executable File

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
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)