Пример #1
0
def main():
    # Create NeoPixel object with appropriate configuration.
    strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP)
    # Intialize the library (must be called once before other functions).
    strip.begin()

    print ('Rainbow animations.')
#    rainbow(strip)
#    rainbowCycle(strip,5)
    while True:
        results = LGTVScan()
        if len(results) > 0:
            print("TV found")
            rainbow(strip)
#            rainbowCycle(strip)
            print (json.dumps({
	    "result": "ok",
	    "count": len(results),
	    "list": results
            }, sort_keys=True, indent=4))
        else:
            colorWipe(strip, Color(0,0,0))
            print("Tv Not found")
            print (json.dumps({
            "result": "failed",
	    "count": len(results)
            }, sort_keys=True, indent=4))
        print("Sleeping")
        time.sleep(10)
Пример #2
0
def LGparser(AlexaCommand):
    if len(AlexaCommand) < 1:
        usage("Too few arguments")
    elif AlexaCommand[0] == "scan":
        results = LGTVScan()
        if len(results) > 0:
            print(
                json.dumps(
                    {
                        "result": "ok",
                        "count": len(results),
                        "list": results
                    },
                    sort_keys=True,
                    indent=4))
        else:
            print(
                json.dumps({
                    "result": "failed",
                    "count": len(results)
                },
                           sort_keys=True,
                           indent=4))

    elif AlexaCommand[0] == "on":
        ws = LGTVClient()
        ws.on()

    elif AlexaCommand[0] == "auth":
        if len(AlexaCommand) < 2:
            usage("Hostname or IP is required for auth")

        if os.path.exists("lgtv.json"):
            os.remove("lgtv.json")

        ws = LGTVClient(AlexaCommand[1])
        ws.connect()
        ws.run_forever()
    else:
        try:
            ws = LGTVClient()
            try:
                if (AlexaCommand[0] == "setTVChannel"):
                    AlexaCommand[1] = searchTVchannels(AlexaCommand[1])
                elif (AlexaCommand[0] == "startApp"):
                    AlexaCommand[1] = searchApps(AlexaCommand[1])
                args = parseargs(AlexaCommand[0], AlexaCommand[1:])
            except Exception as e:
                usage(e.message)
            ws.connect()
            ws.exec_command(AlexaCommand[0], args)
            ws.run_forever()
        except KeyboardInterrupt:
            ws.close()
Пример #3
0
def main():
    if len(sys.argv) < 2:
        usage("Too few arguments")
    elif sys.argv[1] == "scan":
        results = LGTVScan()
        if len(results) > 0:
            print(
                json.dumps(
                    {
                        "result": "ok",
                        "count": len(results),
                        "list": results
                    },
                    sort_keys=True,
                    indent=4))
        else:
            print(
                json.dumps({
                    "result": "failed",
                    "count": len(results)
                },
                           sort_keys=True,
                           indent=4))
    elif sys.argv[1] == "on":
        ws = LGTVClient()
        ws.on()
    elif sys.argv[1] == "auth":
        if len(sys.argv) < 3:
            usage("Hostname or IP is required for auth")

        if os.path.exists(dirpath + ".lgtv.json"):
            os.remove(dirpath + ".lgtv.json")

        ws = LGTVClient(sys.argv[2])
        ws.connect()
        ws.run_forever()
    else:
        try:
            ws = LGTVClient()
            try:
                args = parseargs(sys.argv[1], sys.argv[2:])
            except Exception as e:
                usage(e.message)
            ws.connect()
            ws.exec_command(sys.argv[1], args)
            ws.run_forever()
        except KeyboardInterrupt:
            ws.close()
Пример #4
0
         usage("ffmpeg or base64 NOT found and required for {0}".format(
             sys.argv[1]))
     else:
         try:
             ws = LGTVClient()
             try:
                 args = parseargs(sys.argv[1], sys.argv[2:])
             except Exception as e:
                 usage(e.message)
             ws.connect()
             ws.exec_command(sys.argv[1], args)
             ws.run_forever()
         except KeyboardInterrupt:
             ws.close()
 elif sys.argv[1] == "scan":
     results = LGTVScan()
     if len(results) > 0:
         print(
             json.dumps({
                 "result": "ok",
                 "count": len(results),
                 "list": results
             }))
     else:
         print(json.dumps({"result": "failed", "count": len(results)}))
 elif sys.argv[1] == "on":
     ws = LGTVClient()
     ws.on()
 elif sys.argv[1] == "auth":
     if len(sys.argv) < 3:
         usage("Hostname or IP is required for auth")