|
|
@@ -231,26 +231,34 @@ class Stream(NilmApp): |
|
|
|
@cherrypy.expose |
|
|
|
@cherrypy.tools.json_in() |
|
|
|
@cherrypy.tools.json_out() |
|
|
|
@exception_to_httperror(NilmDBError, LookupError, TypeError) |
|
|
|
@exception_to_httperror(NilmDBError, LookupError) |
|
|
|
@cherrypy.tools.CORS_allow(methods = ["POST"]) |
|
|
|
def set_metadata(self, path, data): |
|
|
|
"""Set metadata for the named stream, replacing any |
|
|
|
existing metadata. Data should be a json-encoded |
|
|
|
dictionary""" |
|
|
|
data_dict = json.loads(data) |
|
|
|
self.db.stream_set_metadata(path, data_dict) |
|
|
|
"""Set metadata for the named stream, replacing any existing |
|
|
|
metadata. Data can be json-encoded or a plain dictionary (if |
|
|
|
it was sent as application/json to begin with)""" |
|
|
|
if not isinstance(data, dict): |
|
|
|
try: |
|
|
|
data = dict(json.loads(data)) |
|
|
|
except TypeError as e: |
|
|
|
raise NilmDBError("can't parse 'data' parameter: " + e.message) |
|
|
|
self.db.stream_set_metadata(path, data) |
|
|
|
|
|
|
|
# /stream/update_metadata?path=/newton/prep&data=<json> |
|
|
|
@cherrypy.expose |
|
|
|
@cherrypy.tools.json_in() |
|
|
|
@cherrypy.tools.json_out() |
|
|
|
@exception_to_httperror(NilmDBError, LookupError, TypeError) |
|
|
|
@exception_to_httperror(NilmDBError, LookupError) |
|
|
|
@cherrypy.tools.CORS_allow(methods = ["POST"]) |
|
|
|
def update_metadata(self, path, data): |
|
|
|
"""Update metadata for the named stream. Data |
|
|
|
should be a json-encoded dictionary""" |
|
|
|
data_dict = json.loads(data) |
|
|
|
self.db.stream_update_metadata(path, data_dict) |
|
|
|
if not isinstance(data, dict): |
|
|
|
try: |
|
|
|
data = dict(json.loads(data)) |
|
|
|
except TypeError as e: |
|
|
|
raise NilmDBError("can't parse 'data' parameter: " + e.message) |
|
|
|
self.db.stream_update_metadata(path, data) |
|
|
|
|
|
|
|
# /stream/insert?path=/newton/prep |
|
|
|
@cherrypy.expose |
|
|
|