コード例 #1
0
 def messagedecodesensor(self, body):
     '''deserialize sensor value '''
     message_envelope = self.deserializemessageenvelope(self.safestring(body))
     schema = SensorValueSchema()
     #minermessage_dict = schema.load(message_envelope.bodyjson()).data
     entity = schema.load(message_envelope.bodyjson()).data
     return message_envelope, entity
コード例 #2
0
    def test_sensorvalue_serialization(self):
        '''on windows the deserialization seems to lose the fractions of seconds
        so this test is only for seconds'''
        sch = SensorValueSchema()
        sensorvalue = SensorValue('testid', '99.9', 'temperature')
        sensorvalue.sensor = Sensor('testid', 'temperature', 'controller')
        sensortime = sensorvalue.sensortime
        jsensor = sch.dumps(sensorvalue).data

        #rehydrate sensor
        resensor = SensorValueSchema().loads(jsensor).data
        self.assertTrue(isinstance(resensor, SensorValue))
        self.assertTrue(resensor.sensortime.day == sensortime.day)
        self.assertTrue(resensor.sensortime.hour == sensortime.hour)
        self.assertTrue(resensor.sensortime.minute == sensortime.minute)
        self.assertTrue(resensor.sensortime.second == sensortime.second)
        self.assertTrue(isinstance(resensor.sensor, Sensor))
        self.assertTrue(resensor.sensorid == resensor.sensor.sensorid)
コード例 #3
0
ファイル: fcmapp.py プロジェクト: gitter-badger/fullcycle
 def sendsensor(self, reading):
     message = self.createmessageenvelope()
     sensorjson = message.jsonserialize(SensorValueSchema(), reading)
     self.sendqueueitem(
         QueueEntry(
             QueueName.Q_SENSOR,
             self.serializemessageenvelope(
                 message.make_any('sensorvalue', sensorjson)),
             QueueType.broadcast))
コード例 #4
0
 def store_picture_cache(self, file_name):
     if os.path.isfile(file_name):
         with open(file_name, 'rb') as photofile:
             picdata = photofile.read()
         reading = SensorValue('fullcyclecamera', base64.b64encode(picdata), 'camera')
         #reading.sensor = self.sensor
         #self.sendsensor(reading)
         message = self.createmessageenvelope()
         sensorjson = message.jsonserialize(SensorValueSchema(), reading)
         self.tryputcache(CacheKeys.camera, sensorjson)
コード例 #5
0
 def addknownsensor(self, sensorvalue):
     val = self.jsonserialize(SensorValueSchema(), sensorvalue)
     self.__cache.putinhashset(CacheKeys.knownsensors, sensorvalue.sensorid, val)
コード例 #6
0
 def knownsensors(self):
     dknownsensors = self.__cache.gethashset(CacheKeys.knownsensors)
     if dknownsensors is not None and dknownsensors:
         return self.deserializelist_withschema(SensorValueSchema(), list(dknownsensors.values()))
     return None