diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..854a5a5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.pyc
+venv
diff --git a/index.html b/index.html
deleted file mode 100644
index e03e2db..0000000
--- a/index.html
+++ /dev/null
@@ -1,191 +0,0 @@
-
-
-
-
-
- Power Control
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
- Foration 2014
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lighttpd.conf b/lighttpd.conf
deleted file mode 100644
index f54262d..0000000
--- a/lighttpd.conf
+++ /dev/null
@@ -1,33 +0,0 @@
-server.modules = (
- "mod_access",
- "mod_alias",
- "mod_compress",
- "mod_redirect",
- "mod_cgi",
-# "mod_rewrite",
-)
-
-server.document-root = "/var/www"
-server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
-server.errorlog = "/var/log/lighttpd/error.log"
-server.pid-file = "/var/run/lighttpd.pid"
-server.username = "www-data"
-server.groupname = "www-data"
-server.port = 80
-
-
-index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
-url.access-deny = ( "~", ".inc" )
-static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
-
-compress.cache-dir = "/var/cache/lighttpd/compress/"
-compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )
-
-# default listening port for IPv6 falls back to the IPv4 port
-include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
-include_shell "/usr/share/lighttpd/create-mime.assign.pl"
-include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
-
-$HTTP["url"] =~ "^/cgi-bin/" {
- cgi.assign = (".py" => "/usr/bin/python")
-}
diff --git a/power.py b/power.py
index cd61f70..1733635 100644
--- a/power.py
+++ b/power.py
@@ -1,66 +1,45 @@
+# add flask here
+from flask import Flask
+app = Flask(__name__)
+app.debug = True
+# keep your code
import time
import cgi
-form = cgi.FieldStorage()
-
-print "Content-Type: text/html"
-print
-print ''
-print 'Power'
-
-if not ("device" in form and "power" in form and "pass" in form):
- print " Incorrect params have been provided."
- print ""
- print "
"
- print """"""
- print ""
- exit() #end here if errors
-
-device_id, power, powerOnTime = int(form['device'].value), form['power'].value, int(form['time'].value)
-
-if not ('pass' in form and form['pass'].value == "p@ssw0rd"):
- print " Password is incorrect."
- exit()
-
from tellcore.telldus import TelldusCore
core = TelldusCore()
devices = core.devices()
-
-if not (power in ['off','on','time'] and
- device_id <= len(devices)):
- print "
Incorrect values for the params have been provided."
- print ""
- print "
"
- print """"""
- print ""
- exit() #end here if errors
-device = devices[device_id]
-if power == 'on':
- device.turn_on()
-if power == 'off':
- device.turn_off()
+# define a "power ON api endpoint"
+@app.route("/API/v1.0/power-on/",methods=['POST'])
+def powerOnDevice(deviceId):
+ payload = {}
+ #get the device by id somehow
+ device = devices[deviceId]
+ # get some extra parameters
+ # let's say how long to stay on
+ params = request.get_json()
+ try:
+ device.turn_on()
+ payload['success'] = True
+ return payload
+ except:
+ payload['success'] = False
+ # add an exception description here
+ return payload
+
+# define a "power OFF api endpoint"
+@app.route("/API/v1.0/power-off/",methods=['POST'])
+def powerOffDevice(deviceId):
+ payload = {}
+ #get the device by id somehow
+ device = devices[deviceId]
+ try:
+ device.turn_off()
+ payload['success'] = True
+ return payload
+ except:
+ payload['success'] = False
+ # add an exception description here
+ return payload
-if powerOnTime > 0:
- device.turn_on()
- time.sleep(powerOnTime)
- device.turn_off()
-print ' Device ID %s has been turned %s for %s seconds' % (device_id,power,powerOnTime)
-print ""
-print "
"
-print """"""
-print ""
+app.run()