当前位置: 首页>>代码示例>>Python>>正文


Python DataAccess.getSensor方法代码示例

本文整理汇总了Python中Data.dataAccess.DataAccess.getSensor方法的典型用法代码示例。如果您正苦于以下问题:Python DataAccess.getSensor方法的具体用法?Python DataAccess.getSensor怎么用?Python DataAccess.getSensor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Data.dataAccess.DataAccess的用法示例。


在下文中一共展示了DataAccess.getSensor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SensorLog

# 需要导入模块: from Data.dataAccess import DataAccess [as 别名]
# 或者: from Data.dataAccess.DataAccess import getSensor [as 别名]
class SensorLog(PollingProcessor):
    """ Handles updating sensors of all types to the database """
    def __init__ (self, channels, name=''):
        super(SensorLog, self).__init__()
        self._dao = DataAccess().sensors
        self._channels = channels
        self._logCache = {}
        self._name = name
                
    def start(self):
        """ Begin asynchronously updating changes in sensors """
        if self._name != '':
            print "Started updating database for %s sensor changes" % (self._name)
        else:
            print "Started updating database for [unknown] sensor changes"
        self._addPollingProcessor('sensorHistory', self.checkUpdateSensors, (self._channels,), 0.01)

    def stop(self):
        """ Stop updating the sensor table """
        if self._name != '':
            print "Stopped updating database for %s sensor changes" % (self._name)
        else:
            print "Stopped updating database for [unknown] sensor changes"

        self._removePollingProcessor('sensorHistory')

    def checkUpdateSensors(self, channels):
        """ Check the specified channels and update the database whenever changes are detected to the 'value' or 'status'"""
        for uuid, sensor in channels.items():
            if not self._logCache.has_key(uuid):
                current = self._dao.getSensor(sensor['id'])
                self._logCache[uuid] = { 'value': current['value'], 'status': current['status']}

            status = str(sensor['status']).capitalize()
            if self._logCache[uuid]['status'] != status or self._logCache[uuid]['value'] != sensor['value']:
                val = sensor['value'] if len(sensor['value']) > 1 else sensor['value'][0]
                timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                success = self._dao.saveSensorLog(
                                                  sensor['id'],
                                                  val,
                                                  status,
                                                  timestamp,
                                                  sensor['room'],
                                                  sensor['channel'])
                if success:
                    print "%(time)s: Updated sensor log for %(id)s to %(status)s (%(value)s)" % { 
                                                                           'time':timestamp,
                                                                           'id':sensor['channel'],
                                                                           'status': status,
                                                                           'value': val,
                                                                           }
                    self._logCache[uuid]['value'] = sensor['value']
                    self._logCache[uuid]['status'] = status
开发者ID:uh-adapsys,项目名称:UHCore,代码行数:55,代码来源:history.py

示例2: SensorLog

# 需要导入模块: from Data.dataAccess import DataAccess [as 别名]
# 或者: from Data.dataAccess.DataAccess import getSensor [as 别名]
class SensorLog(PollingProcessor):    
    def __init__ (self, channels, name=''):
        super(SensorLog, self).__init__()
        self._dao = DataAccess().sensors
        self._channels = channels
        self._logCache = {}
        self._name = name
                
    def start(self):
        if self._name != '':
            print "Started updating database for %s sensor changes" % (self._name)
        else:
            print "Started updating database for [unknown] sensor changes"
        self._addPollingProcessor('sensorHistory', self.checkUpdateSensors, (self._channels,), 0.01)

    def stop(self):
        if self._name != '':
            print "Stopped updating database for %s sensor changes" % (self._name)
        else:
            print "Stopped updating database for [unknown] sensor changes"

        self._removePollingProcessor('sensorHistory')

    def checkUpdateSensors(self, channels):
        for uuid, sensor in channels.items():
            if not self._logCache.has_key(uuid):
                current = self._dao.getSensor(sensor['id'])
                self._logCache[uuid] = { 'value': current['value'], 'status': current['status']}

            status = str(sensor['status']).capitalize()
            if self._logCache[uuid]['status'] != status:
                timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                success = self._dao.saveSensorLog(
                                                  sensor['id'],
                                                  sensor['value'],
                                                  status,
                                                  timestamp,
                                                  sensor['room'],
                                                  sensor['channel'])
                if success:
                    print "Updated sensor log for %(id)s to %(status)s" % { 
                                                                           'id':sensor['channel'],
                                                                           'status': status
                                                                           }
                    self._logCache[uuid]['value'] = sensor['value']
                    self._logCache[uuid]['status'] = status
开发者ID:iduque,项目名称:UHCore,代码行数:48,代码来源:history.py

示例3: SensorLog

# 需要导入模块: from Data.dataAccess import DataAccess [as 别名]
# 或者: from Data.dataAccess.DataAccess import getSensor [as 别名]
class SensorLog(PollingProcessor):    
    def __init__ (self, channels, name=''):
        super(SensorLog, self).__init__()
        self._dao = DataAccess().sensors
        self._channels = channels
        self._logCache = {}
        self._name = name
                
    def start(self):
        if self._name != '':
            print "Started polling sensor changes for %s" % (self._name)
        else:
            print "Started polling sensor changes"
        self._addPollingProcessor('sensorHistory', self.checkUpdateSensors, (self._channels, ), 0.01)

    def stop(self):
        if self._name != '':
            print "Stopped polling sensor changes for %s" % (self._name)
        else:
            print "Stopped polling sensor changes"

        self._removePollingProcessor('sensorHistory')

    def checkUpdateSensors(self, channels):
        for k in channels.keys():
            if not self._logCache.has_key(k):
                current = self._dao.getSensor(channels[k]['id'])
                self._logCache.setdefault(k, { 'value': current['value'], 'status': current['status']})
            if self._logCache[k]['status'] != channels[k]['status']:
                timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                success = self._dao.saveSensorLog(
                                                  channels[k]['id'], 
                                                  channels[k]['value'], 
                                                  channels[k]['status'],
                                                  timestamp,
                                                  channels[k]['room'],
                                                  channels[k]['channel'])
                if success:
                    print "Updated sensor log for %(id)s to %(status)s" % { 
                                                                           'id':channels[k]['channel'], 
                                                                           'status': channels[k]['status']
                                                                           }
                    self._logCache[k]['value'] = channels[k]['value']
                    self._logCache[k]['status'] = channels[k]['status']
开发者ID:ninghang,项目名称:accompany,代码行数:46,代码来源:history.py


注:本文中的Data.dataAccess.DataAccess.getSensor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。