本文整理汇总了Python中models.Status.digital1方法的典型用法代码示例。如果您正苦于以下问题:Python Status.digital1方法的具体用法?Python Status.digital1怎么用?Python Status.digital1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Status
的用法示例。
在下文中一共展示了Status.digital1方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import digital1 [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>')