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.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)