def main(): config = configparser.ConfigParser() # does not throw an error, just returns the empty set if the file doesn't exist config.read(CONFIG.BASEPATH+'/config/iGrill_config.ini') loglevel = config.get("Logging", "LogLevel", fallback="Error") logfile = config.get("Logging", "LogFile", fallback="") parser = argparse.ArgumentParser( description='Sets the LEDs on the SSR control board') parser.add_argument( '-l', '--log-level', action='store', dest='log_level', default=loglevel, help='Set log level, default: \'' + loglevel + '\'') parser.add_argument( '-d', '--log-destination', action='store', dest='log_destination', default=logfile, help='Set log destination (file), default: \'' + logfile + '\'') parser.add_argument( '--low_battery', action='store_true', dest='low_battery', help='Turns on the low battery LED') parser.add_argument( '--done', action='store_true', dest='done', help='Turns on the smoking complete LED') parser.add_argument( '--exit', dest='shutdown', help='Tells the daemon to shutdown', action='store_true') options = parser.parse_args() SetupLog(options.log_level, options.log_destination) buzzObj = Proxy(("PYRO:{}@{}:{}").format( BUZZ.DAEMON.PYRO_OBJECT_ID, BUZZ.DAEMON.PYRO_HOST, BUZZ.DAEMON.PYRO_PORT)) if(options.done): buzzObj.Done() elif(options.low_battery): buzzObj.LowBattery() else: buzzObj.Stop() if(options.shutdown): buzzObj.Exit()
def Exit(self): with self.m_lock: self.m_active = False self.m_threadCondition.acquire() self.m_threadCondition.notify() self.m_threadCondition.release() self.m_thread.join() kasaObj = Proxy(("PYRO:{}@{}:{}").format(KASA.DAEMON.PYRO_OBJECT_ID, KASA.DAEMON.PYRO_HOST, KASA.DAEMON.PYRO_PORT)) kasaObj.TurnPlugOff() kasaObj.Exit() logging.debug("Closing socket") self.m_daemon.shutdown()
options = parser.parse_args() SetupLog(options.log_level, options.log_destination) if(0 < len(vars(options))): if(options.hot and options.cold): print("Cannot be too hot and too cold at the same time") sys.exit(1) ssrcObj = Proxy(("PYRO:{}@{}:{}").format( SSRC.DAEMON.PYRO_OBJECT_ID, SSRC.DAEMON.PYRO_HOST, SSRC.DAEMON.PYRO_PORT)) try: if(options.shutdown): ssrcObj.Exit() elif(options.status): print("{:.2f}".format(ssrcObj.Status())) else: if(options.in_band): if(options.hot): ssrcObj.Adjust(SSRC.TemperatureState.WARM) logging.debug( "Adjust down 1% to {:.2f}%".format(ssrcObj.Status())) elif(options.cold): ssrcObj.Adjust(SSRC.TemperatureState.COOL) logging.debug( "Adjust up 0.25% to {:.2f}%".format(ssrcObj.Status())) else: ssrcObj.Adjust(SSRC.TemperatureState.PERFECT) logging.debug(
options = parser.parse_args() SetupLog(options.log_level, options.log_destination) if (0 < len(vars(options))): if (options.turn_on and options.turn_off): print("Cannot turn on and off at the same time") sys.exit(1) kasaObj = Proxy( ("PYRO:{}@{}:{}").format(KASA.DAEMON.PYRO_OBJECT_ID, KASA.DAEMON.PYRO_HOST, KASA.DAEMON.PYRO_PORT)) try: if (options.turn_on): kasaObj.TurnPlugOn() if (options.turn_off): kasaObj.TurnPlugOff() if (options.status): if (kasaObj.GetActive()): print("on") else: print("off") if (options.shutdown): kasaObj.Exit() except: logging.error( "Exception while attempting to contact Kasa - may be a temporary issue" ) finally: # Failure to communicate can cause an exception sys.exit(0)