def main():
    # Locate the roku device
    printing("Finding roku device ...")
    rokus = Roku.discover()
    printing("Done finding roku device ...")

    # IF no devices found ...
    if len(rokus) == 0:
        print("No rokus found")
        sys.exit(-1)
    # Otherwise, get the ip and port of the device
    else:
        roku_ip_address = rokus[0].host
        roku_port = rokus[0].port

    # Setup API object to make requests to the roku device
    print("Connecting ...")
    roku = Roku(host=roku_ip_address, port=roku_port)
    print("Done connecting ...")

    # Find youtube app
    print("Finding youtube app ...")
    youtube_app = [a for a in roku.apps if 'youtube' in a.name.lower()][0]
    print("Done finding youtube app ...")

    # Wait for the app to start
    print("Starting youtube app ...")
    APP_LAUNCH_TIMEOUT = 15
    youtube_app.launch()
    time.sleep(APP_LAUNCH_TIMEOUT)
    print("Done starting youtube app ...")

    # Series of remote clicks to get to youtube Watch Later playlist
    # TODO: sleeps may not be needed
    roku.left()
    time.sleep(1)
    roku.left()
    time.sleep(1)
    roku.down()
    time.sleep(1)
    roku.down()
    time.sleep(1)
    roku.right()
    time.sleep(1)
    roku.down()
    time.sleep(1)
    roku.down()
    time.sleep(1)
    roku.right()
    time.sleep(1)
    roku.select()
Example #2
0
    def set_power_state(self, power):
        if self.device_type in [self.PLUG, self.BULB]:
            device = (SmartPlug(self.ip) if self.device_type in [self.PLUG]
                      else SmartBulb(self.ip))

            if power:
                asyncio.run(device.turn_on())
            else:
                asyncio.run(device.turn_off())

            asyncio.run(device.update())

        elif self.device_type in [self.PI, self.LINUX]:
            stdin = b''
            stdout = b''
            stderr = b''
            if not power:
                client = SSHClient()
                client.set_missing_host_key_policy(AutoAddPolicy())
                client.connect(self.ip,
                               port=22,
                               username=self.username,
                               password=self.password)
                stdin_model, stdout_model, stderr_model = client.exec_command(
                    'sudo -S shutdown -h now')
                stdin_model.write('%s\n' % self.password)
                stderr_model.flush()
                # print the results

                if stdin_model.readable():
                    stdin = stdin_model.read()
                if stdout_model.readable():
                    stdout = stdout_model.read()
                if stderr_model.readable():
                    stderr = stderr_model.read()

                client.close()

                return (stdin, stdout, stderr)

        elif self.device_type in [self.ROKU]:
            roku = Roku(self.ip)
            roku.select()
        return (None, None, None)
Example #3
0
import  time


roku = Roku('192.168.1.107')

app = next((a for a in roku.apps if 'plex' in a.name.lower()), None)
if app:
    app.launch()
    time.sleep(20)
    for i in range(100):
        roku.volume_down()
    for i in range(14):
        roku.volume_up()
    roku.down()
    time.sleep(2)
    roku.select()
    time.sleep(2)
    roku.up()
    time.sleep(1)
    roku.up()
    time.sleep(1)
    roku.right()
    time.sleep(1)
    roku.right()
    time.sleep(1)
    roku.select()
    time.sleep(1)
    roku.down()
    time.sleep(1)
    roku.select()
    time.sleep(1)
Example #4
0
from roku import Roku
import time

r = Roku('192.168.1.103')

r.home()
time.sleep(2)
ps_vue = r[93374]
ps_vue.launch()
time.sleep(7)
r.down()
r.select()
time.sleep(8)
r.down()
r.down()
r.down()
r.down()
time.sleep(4)
r.select()
time.sleep(3)
r.select()
Example #5
0
from roku import Roku
rokuls = Roku.discover(timeout=10);
print(rokuls);
ip =  input('IP: ');
roku = Roku(ip);

while True:
	remoteinput = input('Remote Input (i.e. down, up, left, right, back, home, ok): ');

	if remoteinput == 'down':
		roku.down();
	elif remoteinput == 'up':
		roku.up();
	elif remoteinput == 'left':
		roku.left();
	elif remoteinput == 'right':
		roku.right();
	elif remoteinput == 'back':
		roku.back();
	elif remoteinput == 'home':
		roku.home();
	elif remoteinput == 'ok':
		roku.select();
	else:
		print('Not a valid command.');

Example #6
0
def roku_command(remote_command):
    delay = 1

    #connect to roku
    #enter your rokus ip address to test
    roku = Roku('192.168.0.110')

    #remote command is place holder for list of commands from remote to dashboard
    #remote_command=['triangle']

    #if circle shape is registered on remote than launch the most recent episode of a users favorite show.
    #In this case Silicon Valley.
    for i in remote_command:
        if i == 'circle':

            for light in lights:
                light.brightness = 254
                light.xy = [.1, .1]

            hbo = roku["HBO GO"]
            hbo.launch()

            sleep(6 * delay)

            roku.down()
            sleep(delay)

            roku.right()
            sleep(delay)

            roku.right()
            sleep(delay)

            roku.select()
            sleep(3 * delay)

            roku.select()
            sleep(2 * delay)

            roku.select()
            sleep(delay)
            #            roku.up()
            #            sleep(delay)

            #            roku.left()
            #            sleep(delay)

            #            roku.down()
            #            sleep(delay)

            #            roku.left()
            #            sleep(delay)

            #            roku.select()
            #            sleep(2*delay)

            #            roku.right()
            #            sleep(delay)

            #            roku.select()
            #            sleep(2*delay)

            #            roku.select()
            #            sleep(2*delay)

            for light in lights:
                light.brightness = 100

        if i == "left_swipe":
            #move cursor left
            roku.left()

        if i == "up_swipe":
            roku.up()

        if i == "down_swipe":
            roku.down()

        if i == "right_swipe":
            #move curser right
            roku.right()

        if i == "triangle":
            print "test"
            b.set_light([2, 3], 'on', True)

            # Prints if light 1 is on or not
            b.get_light(2, 'on')

            # Set brightness of lamp 1 to max
            b.set_light(2, 'bri', 254)

            # Set brightness of lamp 2 to 50%
            b.set_light(3, 'bri', 254)

            for light in lights:
                light.brightness = 254
                light.xy = [.9, .7]
        #enter search commands
            roku.search()

        if i == "square":
            roku.info()

        if i == 'quad_diagonal_1':
            b.set_light(1, 'on', False)

    return True