add device profile
ref #3062
Change-Id: I849737fd99dff8ae587e99bba81885427cf6920a
diff --git a/device_profile.py b/device_profile.py
index e63f01a..d6feec6 100644
--- a/device_profile.py
+++ b/device_profile.py
@@ -21,6 +21,114 @@
This module defines the DeviceProfile class with holds descriptors of device
"""
-class DeviceProfile(object):
- pass
-
+class DeviceProfile(object):
+
+ def __init__(self, prefix = None, location = None, manufacturer = None, category = None, type_ = None, model = None, serialNumber = None, serviceProfileList = None):
+ '''initialize device profile.'''
+ self._prefix = prefix
+ self._location = location
+ self._manufacturer = manufacturer
+ self._category = category
+ self._type = type_
+ self._model = model
+ self._serialNumber = serialNumber
+ if serviceProfileList is None:
+ self._serviceProfileList = []
+ else:
+ self._serviceProfileList = serviceProfileList
+ self._metadata = ['prefix', 'location', 'manufacturer', 'category', 'type', 'model', 'serialNumber', 'serviceProfileList']
+
+ def __str__(self):
+ info ='prefix: '+ self._prefix + '\nlocation: '+ self._location + '\nmanufacturer: ' + self._manufacturer + '\ncategory: ' + self._category + '\ntype: ' + self._type + '\nserial number: ' + self._serialNumber + '\nservice profile list: '
+ info += ', '.join(self._serviceProfileList)
+ info += '\nmetadata: '
+ info += ', '.join(self._metadata)
+ return info
+
+ def getPrefix(self):
+ '''get device prefix from profile'''
+ return self._prefix
+
+ def getLocation(self):
+ '''get device location from profile'''
+ return self._location
+
+ def getManufacturer(self):
+ '''get device manufacturer from profile'''
+ return self._manufacturer
+
+ def getCategory(self):
+ '''get device category from profile'''
+ return self._category
+
+ def getType(self):
+ '''get device type from profile'''
+ return self._type
+
+ def getModel(self):
+ '''get device model from profile'''
+ return self._model
+
+ def getSerialNumber(self):
+ '''get device serial number from profile'''
+ return self._serialNumber
+
+ def getServiceProfileList(self):
+ '''get the service profile list that the device support'''
+ return self._serviceProfileList
+
+ def getMetadata(self):
+ '''get metadata from profile'''
+ return self._metadata
+
+ def setPrefix(self, prefix):
+ '''set device prefix from profile'''
+ self._prefix = prefix
+
+ def setLocation(self, location):
+ '''set device location from profile'''
+ self._location = location
+
+ def setManufacturer(self, manufacturer):
+ '''set device manufacturer from profile'''
+ self._manufacturer = manufacturer
+
+ def setCategory(self, category):
+ '''set device category from profile'''
+ self._category = category
+
+ def setType(self, type_):
+ '''set device type from profile'''
+ self._type = type_
+
+ def setModel(self, model):
+ '''set device model from profile'''
+ self._model = model
+
+ def setSerialNumber(self, serialNumber):
+ '''set device serial number from profile'''
+ self._serialNumber = serialNumber
+
+ def setServiceProfile(self, serviceProfileList):
+ '''set the service profile list that the device support'''
+ self._serviceProfileList = serviceProfileList
+
+ def addServiceProfile(self, newServiceProfile):
+ '''
+ add one or several service profiles to the service profile list.
+ :param str/list _serviceProfile: a service profile or several profiles in the form of a list
+ '''
+ if isinstance(newServiceProfile, str):
+ self._serviceProfileList.append(newServiceProfile)
+ elif type(newServiceProfile) is list:
+ self._serviceProfileList += newServiceProfile
+
+ def addMetadata(self, newMetadata):
+ '''
+ add device one or several attributes to metadata.
+ :param str/list _newMetadata: new attributes to be added
+ '''
+ if isinstance(newMetadata, str):
+ self._metadata.append(newMetadata)
+ elif type(newMetadata) is list:
+ self._metadata += newMetadata
diff --git a/tests/test_device_profile.py b/tests/test_device_profile.py
new file mode 100644
index 0000000..52986ce
--- /dev/null
+++ b/tests/test_device_profile.py
@@ -0,0 +1,73 @@
+from device_profile import DeviceProfile
+
+def readProfile(profile):
+ print ' prefix: ', profile.getPrefix()
+ print ' location: ', profile.getLocation()
+ print ' manufacturer: ', profile.getManufacturer()
+ print ' category: ', profile.getCategory()
+ print ' type: ', profile.getType()
+ print ' serial number: ', profile.getSerialNumber()
+ print ' service profile list:', profile.getServiceProfileList()
+ print ' metadata', profile.getMetadata()
+
+def test():
+ print 'starting to test device_profile.py'
+ print "initilize with category ='sensors', serialNumer = 'T9000000'..."
+ profile = DeviceProfile(category = 'sensors', serialNumber = 'T9000000')
+
+ print 'read profile...'
+ readProfile(profile)
+
+ print "set prefix to '/home/sensor/LED/23'..."
+ profile.setPrefix('/home/sensor/LED/23')
+
+ print "set location to 'Alice's bedroom'..."
+ profile.setLocation('Alice\'s bedroom')
+
+ print "set manufacturer to 'Intel'..."
+ profile.setManufacturer('Intel')
+
+ print "set type to 'LED'..."
+ profile.setType('LED')
+
+ print "set serial number to 'T9273659'..."
+ profile.setSerialNumber('T9273659')
+
+ print "add a service profile '/standard/sensor/simple-LED-control/v0'..."
+ profile.addServiceProfile('/standard/sensor/simple-LED-control/v0')
+
+ print 'read profile...'
+ readProfile(profile)
+
+ print "add sevice profiles ['/standard/sensor/simple-camera-control/v0', '/standard/sensor/simple-motionsensor-control/v0']..."
+ profile.addServiceProfile(['/standard/sensor/simple-camera-control/v0', '/standard/sensor/simple-motionsensor-control/v0'])
+
+ print 'read profile...'
+ readProfile(profile)
+
+ print "set service profile to ['/standard/sensor/simple-camera-control/v0']... "
+ profile.setServiceProfile(['/standard/sensor/simple-camera-control/v0'])
+
+ print 'read profile...'
+ readProfile(profile)
+
+ print "add metadata 'name'... "
+ profile.addMetadata('name')
+
+ print 'read profile...'
+ readProfile(profile)
+
+ print "add metadata ['status', 'id']"
+ profile.addMetadata(['status', 'id'])
+
+ print 'read profile...'
+ readProfile(profile)
+
+ print "test 'print profile'..."
+ print profile
+
+ print "Unit tests: passed"
+
+if __name__ =='__main__':
+ test()
+