本文整理汇总了Python中scheduler.Scheduler.now方法的典型用法代码示例。如果您正苦于以下问题:Python Scheduler.now方法的具体用法?Python Scheduler.now怎么用?Python Scheduler.now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scheduler.Scheduler
的用法示例。
在下文中一共展示了Scheduler.now方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AgoScheduler
# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import now [as 别名]
class AgoScheduler(agoclient.AgoApp):
def __init__(self):
agoclient.AgoApp.__init__(self)
self.weekdayno = None
self.weekday = None
self.nexttime = None
self.next_item = None
self.groups = None
self.scheduler = None
self.scenario_controllerUUID = None
self.mapfile = None
self.print_schedule = False
def event_handler(self, subject, content):
"""event handler - Processes incoming events and looks if they are of a relevant kind
- For now, it's only time event that are of interest
"""
self.log.trace("event_handler start")
if "event.environment.timechanged" in subject:
self.log.trace("subject=%s content=%s", subject, content)
js = json.loads(str(content).replace("u\'", '\"').replace("\'", '\"')) # TODO: check if replacement is necessary
t_now = self.scheduler.now()
self.log.trace("now={} - waiting for {}".format(t_now, self.nexttime))
if self.nexttime is not None and t_now == self.nexttime:
while True: # Loop through all items with same time
self.log.debug("Action to be triggered: {}".format(self.next_item))
try:
self.send_message(self.next_item)
except NameError as e:
self.log.error("Oops, could not send message. Msg={}".format(e))
self.next_item = self.scheduler.get_next()
if self.next_item is None:
self.nexttime = None
break
if t_now != self.next_item["time"]:
self.nexttime = self.next_item["time"]
break
if self.nexttime is not None:
self.log.debug("Next item scheduled for {}".format(self.nexttime))
else:
self.log.debug("No more scheduled items for today")
if self.weekdayno != int(js["weekday"]):
# TODO: Check config if a new schedule file is to be loaded
self.weekdayno = int(js["weekday"])
self.new_day(self.weekdayno)
self.next_item = self.scheduler.get_first("00:00")
if self.next_item is not None:
self.nexttime = self.next_item["time"]
else:
self.nexttime = None
self.log.debug("First item scheduled for {}".format(self.nexttime))
# TODO: Event handler for "reload" event
def device_msg(self, uuid, action, level=None):
content = {"uuid": uuid, # TODO: Check unicode encoded strings
"action": action}
if action == "setlevel":
content["level"] = level
elif action == "fade":
pass
if action in {"on", "off", "setlevel"}:
msg = "event.device.statechanged"
self.log.debug("About to set device content={}".format(content))
self.connection.send_message(msg, content)
def send_message(self, item):
self.log.debug(("In send_message. item={}".format(item)))
if item["device"] is not None:
if item["action"] in {"on", "off"}:
self.device_msg(item["device"], item["action"])
elif item["action"] in {"setlevel"}:
self.device_msg(item["device"], item["action"], item["level"])
# todo: aDD ACTION SPECIFIC FIELDS
if item["scenario"] is not None:
content = {"uuid": item["scenario"],
"command": "run"}
self.log.debug("About to execute scenario content={}".format(content))
self.connection.send_message(None, content)
if item["group"] is not None:
self.log.info(("About to send message to device group {}".format(item["group"])))
grp = self.groups.find(item["group"])
if grp is not None:
for dev in grp.devices:
if dev is not None:
if item["action"] in {"on", "off"}:
self.device_msg(dev, item["action"])
elif item["action"] in {"setlevel"}:
self.device_msg(dev, item["action"], item["level"])
def get_scenario_controller_uuid(self):
#.........这里部分代码省略.........