added controller adding logic
This commit is contained in:
@@ -21,8 +21,6 @@ ALLLED_OFF_L = 0xFC
|
|||||||
ALLLED_OFF_H = 0xFD
|
ALLLED_OFF_H = 0xFD
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
"""
|
"""
|
||||||
A controller controls a number of stripes.
|
A controller controls a number of stripes.
|
||||||
@@ -89,7 +87,8 @@ class Stripe:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_db(cls, controller, row):
|
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):
|
def set_color(self, c):
|
||||||
self._color = c
|
self._color = c
|
||||||
|
@@ -28,8 +28,10 @@ from . import controller
|
|||||||
class Daemon:
|
class Daemon:
|
||||||
daemonSection = 'daemon'
|
daemonSection = 'daemon'
|
||||||
databaseSection = 'db'
|
databaseSection = 'db'
|
||||||
|
instance = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
Daemon.instance = self
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
try:
|
try:
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
@@ -47,8 +49,8 @@ class Daemon:
|
|||||||
|
|
||||||
self.sqldb.commit()
|
self.sqldb.commit()
|
||||||
|
|
||||||
self.controller = controller.Controller.from_db(self.sqldb)
|
self.controllers = controller.Controller.from_db(self.sqldb)
|
||||||
print(self.controller)
|
print(self.controllers)
|
||||||
|
|
||||||
server = self.SocketServer(self.config.get(self.daemonSection, 'host', fallback='0.0.0.0'),
|
server = self.SocketServer(self.config.get(self.daemonSection, 'host', fallback='0.0.0.0'),
|
||||||
self.config.get(self.daemonSection, 'port', fallback=1425))
|
self.config.get(self.daemonSection, 'port', fallback=1425))
|
||||||
@@ -105,12 +107,22 @@ class Daemon:
|
|||||||
elif json_decoded['action'] == "get_color":
|
elif json_decoded['action'] == "get_color":
|
||||||
# TODO: add stripe color get logic
|
# TODO: add stripe color get logic
|
||||||
print("recieved action: {}".format(json_decoded['action']))
|
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:
|
else:
|
||||||
print("no action found, ignoring")
|
print("no action found, ignoring")
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
print("No valid JSON found!")
|
print("No valid JSON found!")
|
||||||
|
|
||||||
|
|
||||||
class SocketServer(asyncore.dispatcher):
|
class SocketServer(asyncore.dispatcher):
|
||||||
def __init__(self, host, port):
|
def __init__(self, host, port):
|
||||||
asyncore.dispatcher.__init__(self)
|
asyncore.dispatcher.__init__(self)
|
||||||
|
Reference in New Issue
Block a user