def main(): try: CONF(project='myhvac_service') except cfg.RequiredOptError as e: print '\n\n********************* WOW SOMETHING WENT WRONG!!!! **************************\n' print e print '\n*****************************************************************************\n\n' print 'Configuration Help and Usage:' CONF.print_help() raise SystemExit(1) log.init_log() display.init_display() LOG.info('Starting up system... pid: %s', os.getpid()) display.write('Starting up system..') db.init_db() hvac.init_gpio() prog_man = pm.ProgramManager() try: threads.append(hub.spawn(wsgi.run)) threads.append(hub.spawn(prog_man.start)) # Keep main thread alive to capture kill events while True: hub.sleep(.1) except (KeyboardInterrupt, SystemExit): LOG.error('Caught KeyboardInterrupt, initiate shutdown') finally: shutdown(prog_man)
def close(self): LOG.info('Stopping Program Manager') self.is_active = False while self.is_running: hub.sleep(1) current_state, _ = hvac.get_system_state() if current_state != states.OFF: hvac.set_system_state(states.OFF, current_state)
def start(self): LOG.info('Starting Program Manager') LOG.debug('Interval sleep time: %s (seconds)', CONF.program_manager.sleep_seconds) self.is_active = True self.is_running = True next_run = datetime.min while self.is_active: if datetime.now() > next_run: self.run() next_run = datetime.now() + timedelta( seconds=CONF.program_manager.sleep_seconds) hub.sleep(1) self.is_running = False