record_sensor.py 564 B

123456789101112131415161718192021
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter service
  5. name:record_sensor.py 处理传感器数据
  6. author:rabin
  7. key:sensor/type/gateway/device
  8. """
  9. import time
  10. import json
  11. from demeter.core import *
  12. class Record_sensor(object):
  13. def handle(self, record, config, value):
  14. self.record = record
  15. model = Demeter.model('device_type')
  16. model.key = config['type']
  17. device_type = model.select(type='fetchone')
  18. if device_type:
  19. name = device_type['name'] + '#' + str(config['child'])
  20. self.record.save(config, value, name, device_type)