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


Python Status.analog1方法代码示例

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


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

示例1: get

# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import analog1 [as 别名]
  def get(self):

    try:
      dev_id = self.request.get('id')
      uptime = int(self.request.get('uptime'))
      digital1 = int(self.request.get('digital1'))
      digital2 = int(self.request.get('digital2'))
      analog1 = float(self.request.get('analog1'))

    except: 
      logging.info('Input error')
      self.response.out.write('<p>Input error</p>')
      return 

    device = Device.get_by_key_name(dev_id)
    if device:
#      logging.info('Update existing device')
      device.uptime = uptime

      # update state
      current_state = device.state
      if current_state == "Unknown" or current_state == "Available":
        if analog1 < 5.0:
          device.state = "Busy"

      elif current_state == "Busy":
        if analog1 >= 5.0:
          device.state = "Ready"

      elif current_state == "Ready":
        device.state = "Available"

      device.put()

      # send notification to subscribers who's trigger state is the current state
      subscriber_list = device.subscriber_set.filter('trigger_state =', device.state)
      subscriber_email_list = list()
      for subscriber in subscriber_list:
        subscriber_email_list.append(subscriber.email)
        # instead of deleting the subscriber, clear the trigger state
        # so that a record of the subscriber is kept but no further email
        # is sent
        subscriber.trigger_state = "" 
        subscriber.put()

      if len(subscriber_email_list) > 0:
        message = mail.EmailMessage(
          sender='StatusBot <[email protected]>',
          to=subscriber_email_list,
          subject='StatusBot #' + device.key().name() + ' Update!',
          body="State has changed to " + device.state)
        message.send()

    else:
      logging.info('Update new device')
      device = Device(key_name=dev_id, state="Unknown")
      device.uptime = uptime
      device.put()

    # save device status
    status = Status(device=device)
    status.digital1 = digital1
    status.digital2 = digital2
    status.analog1 = analog1
    status.put()
    
    self.response.out.write('<p>OK</p>')
开发者ID:SAEAlbert,项目名称:StatusBot.net,代码行数:69,代码来源:main.py


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