Commit cfbc9016 authored by GromeTT's avatar GromeTT
Browse files

fix: Complete features and change to_json method of role

Now, to_json returns its name as well.
parent 17cd9428
......@@ -3,7 +3,16 @@
class Acceleration(Value):
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(
namespace=namespace,
name=name,
identifier=identifier)
super().__init__(namespace=namespace, name=name, identifier=identifier)
self.maxValue = [0, 0, 0]
self.meanValue = [0, 0, 0]
self.minValue = [0, 0, 0]
self.rmsValue = [0, 0, 0]
def to_json(self):
tmp = super().to_json()
tmp["maxValue"] = self.maxValue
tmp["meanValue"] = self.meanValue
tmp["minValue"] = self.minValue
tmp["rmsValue"] = self.rmsValue
return tmp
......@@ -3,7 +3,20 @@
class AcousticIndices(Value):
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(
namespace=namespace,
name=name,
identifier=identifier)
super().__init__(namespace=namespace, name=name, identifier=identifier)
self.acousticComplexityIndex = 0
self.acousticDiversityIndex = 0
self.acousticEvennessIndex = 0
self.bioacousticIndex = 0
self.normalizedDifferenceSoundscapeIndex = 0
def to_json(self):
tmp = super().to_json()
tmp["acousticComplexityIndex"] = self.acousticComplexityIndex
tmp["acousticDiversityIndex"] = self.acousticDiversityIndex
tmp["acousticEvennessIndex"] = self.acousticEvennessIndex
tmp["bioacousticIndex"] = self.bioacousticIndex
tmp[
"normalizedDifferenceSoundscapeIndex"
] = self.normalizedDifferenceSoundscapeIndex
return tmp
......@@ -3,8 +3,10 @@
class AirPressure(Value):
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(
namespace=namespace,
name=name,
identifier=identifier
)
super().__init__(namespace=namespace, name=name, identifier=identifier)
self.value = 0
def to_json(self):
tmp = super().to_json()
tmp["value"] = self.value
return tmp
......@@ -3,8 +3,10 @@
class Brightness(Value):
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(
namespace=namespace,
name=name,
identifier=identifier
)
super().__init__(namespace=namespace, name=name, identifier=identifier)
self.value = 0
def to_json(self):
tmp = super().to_json()
tmp["value"] = self.value
return tmp
......@@ -3,7 +3,16 @@
class GyroscopeValue(Value):
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(
namespace=namespace,
name=name,
identifier=identifier)
super().__init__(namespace=namespace, name=name, identifier=identifier)
self.maxValue = [0, 0, 0]
self.meanValue = [0, 0, 0]
self.minValue = [0, 0, 0]
self.rmsValue = [0, 0, 0]
def to_json(self):
tmp = super().to_json()
tmp["maxValue"] = self.maxValue
tmp["meanValue"] = self.meanValue
tmp["minValue"] = self.minValue
tmp["rmsValue"] = self.rmsValue
return tmp
......@@ -2,9 +2,11 @@
class Infrared(Value):
def __init__(self, namespace="ml40",name="", identifier=""):
super().__init__(
namespace=namespace,
name=name,
identifier=identifier
)
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(namespace=namespace, name=name, identifier=identifier)
self.value = 0
def to_json(self):
tmp = super().to_json()
tmp["value"] = self.value
return tmp
......@@ -3,7 +3,14 @@
class RGBColor(Value):
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(
namespace=namespace,
name=name,
identifier=identifier)
super().__init__(namespace=namespace, name=name, identifier=identifier)
self.blue = 0
self.green = 0
self.red = 0
def to_json(self):
tmp = super().to_json()
tmp["blue"] = self.blue
tmp["red"] = self.red
tmp["green"] = self.green
return tmp
......@@ -3,7 +3,10 @@
class SoundLevel(Value):
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(
namespace=namespace,
name=name,
identifier=identifier)
super().__init__(namespace=namespace, name=name, identifier=identifier)
self.maxValue = 0
def to_json(self):
tmp = super().to_json()
tmp["maxValue"] = self.maxValue
return tmp
......@@ -3,7 +3,10 @@
class WhiteLevel(Value):
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(
namespace=namespace,
name=name,
identifier=identifier)
super().__init__(namespace=namespace, name=name, identifier=identifier)
self.value = 0
def to_json(self):
tmp = super().to_json()
tmp["value"] = self.value
return tmp
......@@ -3,6 +3,7 @@
class Accelerometer(Sensor):
def __init__(self, namespace="ml40", name="", identifier=""):
super().__init__(
namespace=namespace, name=name, identifier=identifier
)
super().__init__(namespace=namespace, name=name, identifier=identifier)
def to_json(self):
return super().to_json()
......@@ -20,8 +20,10 @@ def __init__(self, namespace, name="", identifier=""):
self.__identifier = identifier
self.__name = name
if name == "":
self.__name = self.__class__.__name__
self.__class_name = f"{namespace}::{self.__class__.__name__}"
self.__json_out = dict()
@property
def class_name(self):
......@@ -77,9 +79,7 @@ def identifier(self, value):
def to_json(self):
"""Returns a JSON representation of this role."""
self.__json_out = {
"class": self.__class_name,
}
out = {"class": self.__class_name, "name": self.__name}
if self.identifier:
self.__json_out["identifier"] = self.identifier
return self.__json_out
out["identifier"] = self.identifier
return out
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment