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


Python StateResolver.isSensorOn方法代码示例

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


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

示例1: States

# 需要导入模块: from Data.stateResolver import StateResolver [as 别名]
# 或者: from Data.stateResolver.StateResolver import isSensorOn [as 别名]
class States(object):
    def __init__(self):
        self._dao = Sensors()
        self._sr = StateResolver()
    
    exposed = True
    
    def GET(self, *args, **kwargs):
        
        sensors = self._dao.findSensors()
        sensors = sorted(sensors, key = itemgetter('locationName', 'ChannelDescriptor'))
        
        elements = []
        for sensor in sensors:
            elements.append(
                            {
                             'color': self.getBackgroundColor(sensor),
                             'room': '%(loc)s: %(sen)s' % { 'loc': sensor['locationName'], 'sen': sensor['name'] },
                             'channel': sensor['ChannelDescriptor'],
                             'value': sensor['value'],
                             'status': self._sr.getDisplayState(sensor)
                             })
        
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return json.dumps(elements)

    def getBackgroundColor(self, sensor):
        stype = sensor['sensorTypeName']
        if stype == 'CONTACT_REED':
            if float(sensor['value']) == 1:
                return '#FF0000'
            else:
                return '#00FF00' # closed door == green colour
        elif stype == 'CONTACT_PRESSUREMAT':
            if float(sensor['value']) == 1:
                return '#00FF00' # vacant chair == green colour
            else:
                return '#FF0000'
        elif stype == 'TEMPERATURE_MCP9700_HOT' or stype == 'TEMPERATURE_MCP9700_COLD':
            #return str((float(sensor['value']) - 0.5) * 100.0) + 'C'
            temp = float(sensor['value'])
            if temp < 0.0:
                r = 0
            elif temp > 50.0:
                r = 255
            else:
                r = int(temp * 5.1) # -0C..+50C -> 0..255
            g = 0
            b = 255 - r
            return '#%02X%02X%02X' % (r, g, b)
        elif stype == 'POWER_CONSUMPTION_MONITOR':
            if self._sr.isSensorOn(sensor):
                return '#FFFF00'
            else:
                return '#00FF00' # closed door == green colour
        else:
            return 'None'
开发者ID:ipa-rmb,项目名称:accompany,代码行数:59,代码来源:states.py


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