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
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)
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))
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)
def addknownsensor(self, sensorvalue): val = self.jsonserialize(SensorValueSchema(), sensorvalue) self.__cache.putinhashset(CacheKeys.knownsensors, sensorvalue.sensorid, val)
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