added controller adding logic

This commit is contained in:
Giovanni Harting
2015-07-14 16:35:54 +02:00
parent 36d7efc37f
commit d915757185
2 changed files with 21 additions and 10 deletions

View File

@@ -21,8 +21,6 @@ ALLLED_OFF_L = 0xFC
ALLLED_OFF_H = 0xFD
class Controller:
"""
A controller controls a number of stripes.
@@ -89,7 +87,8 @@ class Stripe:
@classmethod
def from_db(cls, controller, row):
return cls(controller, name=row["name"], rgb=row["rgb"], channels=(row["channel_r"],row["channel_g"],row["channel_b"]))
return cls(controller, name=row["name"], rgb=row["rgb"],
channels=(row["channel_r"], row["channel_g"], row["channel_b"]))
def set_color(self, c):
self._color = c

View File

@@ -28,8 +28,10 @@ from . import controller
class Daemon:
daemonSection = 'daemon'
databaseSection = 'db'
instance = None
def __init__(self):
Daemon.instance = self
config = configparser.ConfigParser()
try:
self.config = configparser.ConfigParser()
@@ -47,8 +49,8 @@ class Daemon:
self.sqldb.commit()
self.controller = controller.Controller.from_db(self.sqldb)
print(self.controller)
self.controllers = controller.Controller.from_db(self.sqldb)
print(self.controllers)
server = self.SocketServer(self.config.get(self.daemonSection, 'host', fallback='0.0.0.0'),
self.config.get(self.daemonSection, 'port', fallback=1425))
@@ -105,12 +107,22 @@ class Daemon:
elif json_decoded['action'] == "get_color":
# TODO: add stripe color get logic
print("recieved action: {}".format(json_decoded['action']))
elif json_decoded['action'] == "add_stripes":
if "stripes" in json_decoded:
for stripe in json_decoded['stripes']:
# TODO: add stripe here
print(len(json_decoded['stripes']))
elif json_decoded['action'] == "add_controller":
ncontroller = controller.Controller(self.daemon.sqldb, 0, json_decoded['channels'],
json_decoded['i2c_dev'], json_decoded['address'])
self.send(ncontroller.id)
Daemon.instance.controllers.append(ncontroller)
else:
print("no action found, ignoring")
except (TypeError, ValueError):
print("No valid JSON found!")
class SocketServer(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)