Exemple #1
0
    def connect(self):

        if not self.is_running():
            self.start()
        RxvLogger.debug("TV connect ip:" + self.ip)
        for i in range(0, 10):
            try:
                lg = WebOSClient(self.ip)
                lg.connect()
            except Exception as e:
                RxvLogger.error("Unable connect TV, retry e: " + str(e))
                time.sleep(3)
            else:
                break
        try:
            for status in lg.register(self.store):
                if status == WebOSClient.PROMPTED:
                    RxvLogger.log("Please accept the connect on the TV!")
                elif status == WebOSClient.REGISTERED:
                    RxvLogger.log("Registration successful!")
                    lg_sys = SystemControl(lg)
                    lg_sys.notify("RxvLG: Registration successful!")
            self.save_store()
            return lg
        except Exception as e:
            RxvLogger.error("Registration failed exiting!")
            RxvLogger.debug("Exception" + str(e))
Exemple #2
0
 def start(self):
     RxvLogger.log("TV power on")
     trying = 0
     while trying < 10:
         self.run_os_command(
             ['/usr/bin/kodi-send', '-a', 'CECActivateSource'])
         time.sleep(2)
         if self.is_running():
             trying = 11
         elif trying > 10:
             RxvLogger.error("Could not turn on TV")
             return
         else:
             RxvLogger.debug("Retrying connect TV")
             time.sleep(1)
     time.sleep(30)
Exemple #3
0
    def run_os_command(self, args):
        try:
            # stdout = subprocess.PIPE lets you redirect the output
            RxvLogger.debug(' '.join(args))
            res = subprocess.Popen(args, stdout=subprocess.PIPE)
        except OSError:
            RxvLogger.error("error: popen")
            exit(
                -1
            )  # if the subprocess call failed, there's not much point in continuing

        res.wait(
        )  # wait for process to finish; this also sets the returncode variable inside 'res'
        if res.returncode != 0:
            RxvLogger.debug("  os.wait:exit status != 0\n")
        else:
            RxvLogger.debug("os.wait:({},{})".format(res.pid, res.returncode))

            # access the output from stdout
            result = res.stdout.read()
            RxvLogger.debug("after read: {}".format(result))

        return res.returncode