sensor yaml: allow custom sensor names
Currently, we can only name sensors based on data from the dbus object
implementing a sensor's interface. While this mostly works, there may
not be a sensible name to extract in all cases.
This change introduces an optional sensorName property to the sensor
YAML description, which allows a custom name to be used.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Change-Id: I3f3b8ef581c70fbde94db122d4f3c0ca181c6ff7
diff --git a/scripts/writesensor.mako.cpp b/scripts/writesensor.mako.cpp
index 69a44f4..8b26805 100644
--- a/scripts/writesensor.mako.cpp
+++ b/scripts/writesensor.mako.cpp
@@ -3,6 +3,7 @@
// !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!!
<%
interfaceDict = {}
+sensorNameMaxLength = 16
%>\
%for key in sensorDict.keys():
<%
@@ -52,12 +53,19 @@
scale = sensor.get("scale", 0)
hasScale = "true" if "scale" in sensor.keys() else "false"
valueReadingType = sensor["readingType"]
- sensorNamePattern = sensor.get("sensorNamePattern", "nameLeaf")
- sensorNameFunc = "get::" + sensorNamePattern
updateFunc = interfaceDict[serviceInterface]["updateFunc"]
updateFunc += sensor["readingType"]
getFunc = interfaceDict[serviceInterface]["getFunc"]
getFunc += sensor["readingType"]
+ sensorName = sensor.get("sensorName", None)
+ if sensorName:
+ assert len(sensorName) <= sensorNameMaxLength, \
+ "sensor name '%s' is too long (%d bytes max)" % \
+ (sensorName, sensorNameMaxLength)
+ else:
+ sensorNameFunc = "get::" + sensor.get("sensorNamePattern",
+ "nameLeaf")
+
if "readingAssertion" == valueReadingType or "readingData" == valueReadingType:
for interface,properties in interfaces.items():
for dbus_property,property_value in properties.items():
@@ -87,7 +95,11 @@
.updateFunc = ${updateFunc},
.getFunc = ${getFunc},
.mutability = Mutability(${mutability}),
+ % if sensorName:
+ .sensorName = "${sensorName}",
+ % else:
.sensorNameFunc = ${sensorNameFunc},
+ % endif
.propertyInterfaces = {
% for interface,properties in interfaces.items():
{"${interface}",{