First commit.
This commit is contained in:
35
python/baseController.py
Normal file
35
python/baseController.py
Normal file
@@ -0,0 +1,35 @@
|
||||
class BaseController:
|
||||
|
||||
def set_stream_func(self, stream_func):
|
||||
self._stream_func = stream_func
|
||||
|
||||
def send(self, data):
|
||||
if getattr(self, "_stream_func", None) is not None:
|
||||
self._stream_func(data)
|
||||
|
||||
def setProperty(self, params):
|
||||
name = params.get("name")
|
||||
value = params.get("value")
|
||||
|
||||
if not isinstance(name, str):
|
||||
return {"error": "Property name must be a string"}
|
||||
|
||||
if not hasattr(self, name):
|
||||
return {"error": f"Property '{name}' does not exist"}
|
||||
|
||||
setattr(self, name, value)
|
||||
|
||||
return {"success": True}
|
||||
|
||||
|
||||
def getProperty(self, params):
|
||||
|
||||
name = params.get("name")
|
||||
|
||||
if not hasattr(self, name):
|
||||
|
||||
return {"error": f"Property '{name}' does not exist"}
|
||||
|
||||
value = getattr(self, name)
|
||||
|
||||
return {"value": value}
|
||||
Reference in New Issue
Block a user