def schedule_job(function, name, hours=0, minutes=0):
 job = SCHED.get_job(name)
 if job:
  if ((hours == 0) and (minutes == 0)):
   SCHED.remove_job(name)
   logger.info('Removed background task: %s', name)
  elif (job.trigger.interval != datetime.timedelta(hours=hours, minutes=minutes)):
   SCHED.reschedule_job(name, trigger=IntervalTrigger(hours=hours, minutes=minutes))
   logger.info('Re-scheduled background task: %s', name)
 elif ((hours > 0) or (minutes > 0)):
  SCHED.add_job(function, id=name, trigger=IntervalTrigger(hours=hours, minutes=minutes))
  logger.info('Scheduled background task: %s', name)

def schedule_job ( function , name , hours = 0 , minutes = 0 ) : job = SCHED . get_job ( name ) if job : if ( ( hours == 0 ) and ( minutes == 0 ) ) : SCHED . remove_job ( name ) logger . info ( 'Removed background task: %s' , name ) elif ( job . trigger . interval != datetime . timedelta ( hours = hours , minutes = minutes ) ) : SCHED . reschedule_job ( name , trigger = IntervalTrigger ( hours = hours , minutes = minutes ) ) logger . info ( 'Re-scheduled background task: %s' , name ) elif ( ( hours > 0 ) or ( minutes > 0 ) ) : SCHED . add_job ( function , id = name , trigger = IntervalTrigger ( hours = hours , minutes = minutes ) ) logger . info ( 'Scheduled background task: %s' , name )
start scheduled job if starting or restarting headphones .