Esempio n. 1
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)
Esempio n. 2
0
 def init_sensors(self):
     self.sensor = Sensor('controller', 'DHT22', 'controller')
Esempio n. 3
0
 def make_sensor(self, data):
     '''reconstitute sensor'''
     entity = Sensor(sensorid=data['sensorid'],
                     sensortype=data['sensortype'],
                     location=data['location'])
     return entity
Esempio n. 4
0
 def make_sensor(self, data):
     '''reconstitute sensor'''
     return Sensor(**data)
Esempio n. 5
0
 def __init__(self, config, cache):
     super().__init__(config, cache)
     self.sensor = Sensor('controller', 'DHT22', 'controller')