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