Package: cloudio-glue-python
Cloud.iO GlueIntroductionThis package is an extension to thecloudio-endpoint-pythonpackage providing features not present in thejava-endpointimplementation.It supports the developer with theModel2CloudConnectorclass and the'cloudio_attribute' decorator.The fast and simple solution to connect an object to the cloud is to inheritthe class fromCloudioNodeand automatically all attributes getsynchronized to the cloud. The drawback here is that the developer does nothave the choice to prohibit the synchronisation of some attributes.There is where theModel2CloudConnectorclass comes in. Inheriting from thisclass allows specifying which attribute should be synchronized to the cloudusing theattribute mappingfeature.Download and InstallThe library is available on python's package distribution systemPyPi.From the console you can download and install it using the following command:pip install cloudio-glue-pythonModel2CloudConnector ClassTheModel2CloudConnectorclass allows to synchronise some attributes of a class.Which attributes to synchronise is done with an attribute mapping.To use theModel2CloudConnectorclass you need to inherit from it and thenspecify which of the attributes to synchronize using theset_attribute_mapping()method.Attribute MappingHere is an example on how to bring attributes (or properties)xandyof theComputerMouseclass to the cloud:fromcloudio.glueimportModel2CloudConnectorclassComputerMouse(Model2CloudConnector):def__init__(self):super(ComputerMouse,self).__init__()self._x=0self._y=0# Define the attributes which are going to be mapped to cloud.iOself.set_attribute_mapping({'x':{'topic':'position.x','attributeType':float,'constraints':('read',)},# ('read', 'write')'y':{'topic':'position.y','attributeType':float,'constraints':('read',)},})@propertydefx(self):returnself._x@x.setterdefx(self,value):self._x=value@propertydefy(self):returnself._y@y.setterdefy(self,value):self._y=valueAttribute Access PolicyFor each attribute the access policy can be specified. Following values can be givenreadwriteor both.Thereadaccess policy allows to read the attribute from the cloud. Giving thewriteaccess policy allows to change the attribute via the cloud.cloudio_attribute DecoratorAn attribute can be automatically synchronized to the cloud by assigningthecloudio_attributedecorator to the property.To assign for example the decorator to the x property change the code above as follows. Removethe @property decorator and replace it with the@cloudio_attributedecorator.The example below shows the@cloudio_attributedecorator applied to thexandyproperty:fromcloudio.glueimportModel2CloudConnectorfromcloudio.glueimportcloudio_attributeclassComputerMouse(Model2CloudConnector):def__init__(self):super(ComputerMouse,self).__init__()self._x=0self._y=0# Define the attributes which are going to be mapped to cloud.iOself.set_attribute_mapping({'x':{'topic':'position.x','attributeType':float,'constraints':('read',)},# ('read', 'write')'y':{'topic':'position.y','attributeType':float,'constraints':('read',)},})@cloudio_attributedefx(self):returnself._x@x.setterdefx(self,value):self._x=value@cloudio_attributedefy(self):returnself._y@y.setterdefy(self,value):self._y=valueNow every time thexoryproperty gets changed, the value is automatically updated to the cloud.