Exemplo n.º 1
0
def exec_schedule(name, entry, args):
  if "inactive" in args:
    return
  # Call function
  if "entity" in args["kwargs"]:
    dispatch_worker(name, {"name": name, "id": conf.objects[name]["id"], "type": "attr", "function": args["callback"], "attribute": args["kwargs"]["attribute"], "entity": args["kwargs"]["entity"], "new_state": args["kwargs"]["new_state"], "old_state": args["kwargs"]["old_state"], "kwargs": args["kwargs"]})
  else:
    dispatch_worker(name, {"name": name, "id": conf.objects[name]["id"], "type": "timer", "function": args["callback"], "kwargs": args["kwargs"], })
  # If it is a repeating entry, rewrite with new timestamp
  if args["repeat"]:    
    if args["type"] == "next_rising" or args["type"] == "next_setting":
      # Its sunrise or sunset - if the offset is negative we won't know the next rise or set time yet so mark as inactive
      # So we can adjust with a scan at sun rise/set
      if args["offset"] < 0:
        args["inactive"] = 1
      else:
        # We have a valid time for the next sunrise/set so use it
        c_offset = ha.get_offset(args)
        args["timestamp"] = ha.calc_sun(args["type"]) + c_offset
        args["offset"] = c_offset
    else:
      # Not sunrise or sunset so just increment the timestamp with the repeat interval
      args["basetime"] += args["interval"]
      args["timestamp"] = args["basetime"] + ha.get_offset(args)
  else: # Otherwise just delete
    del conf.schedule[name][entry]
Exemplo n.º 2
0
def process_sun(action):
  ha.log(conf.logger, "DEBUG", "Process sun: {}, next sunrise: {}, next sunset: {}".format(action, conf.sun["next_rising"], conf.sun["next_setting"]))
  for name in conf.schedule.keys():
    for entry in sorted(conf.schedule[name].keys(), key=lambda uuid: conf.schedule[name][uuid]["timestamp"]):
      schedule = conf.schedule[name][entry]
      if schedule["type"] == action and "inactive" in schedule:
        del schedule["inactive"]
        c_offset = ha.get_offset(schedule)
        schedule["timestamp"] = ha.calc_sun(action) + c_offset
        schedule["offset"] = c_offset
Exemplo n.º 3
0
def process_sun(action):
    conf.logger.debug(
        "Process sun: {}, next sunrise: {}, next sunset: {}".format(
            action, conf.sun["next_rising"], conf.sun["next_setting"]))
    for name in conf.schedule.keys():
        for entry in sorted(
                conf.schedule[name].keys(),
                key=lambda uuid: conf.schedule[name][uuid]["timestamp"]):
            schedule = conf.schedule[name][entry]
            if schedule["type"] == action and "inactive" in schedule:
                del schedule["inactive"]
                schedule["timestamp"] = ha.calc_sun(action, schedule["time"])
Exemplo n.º 4
0
 def _schedule_sun(self, name, type_, callback, **kwargs):
     event = ha.calc_sun(type_)
     handle = ha.insert_schedule(
         name, event, callback, True, type_, **kwargs
     )
     return handle
Exemplo n.º 5
0
 def _schedule_sun(self, name, type, offset, callback, **kwargs):
     event = ha.calc_sun(type, offset)
     handle = self._insert_schedule(name, event, callback, True, offset,
                                    type, **kwargs)