postlund/pyatv

Add ability to close or force close applications

DennisFury opened this issue · 1 comments

What feature would you like?

It would be great if I could close an application / or force close Apple TV applications. or even restart the unit through atvremote.

Describe the solution you'd like

The ability to force close an application would solve a problem for me. I run tons of home automations (dozen +) around the PlexAPI. Sometimes, play lists / play queues fail to play with a spinning wheel of death. Usually happens when my NAS doesn't spin up quick enough. The solution is always to force close Plex, reopen it, and attempt to play again. I solve this currently in a very harsh fashion-- if my requested content isn't playing ~15 seconds after it's supposed to play, I turn off the power to the smart switch for the apple TV, turn it back on, then it reattempts. I'm afraid I'm shortening the life of my Apple TVs by doing this 2-3 times a week. If I could simply force close the Plex app through scripting (hello atvremote), then I wouldn't have to ungracefully power off my Apple TVs.

Any other information to share?

Nothing, love this project!

Actually never mind, got a work-around now that I'm forced to think about it...

def atv_command(ip_address, room, protocol, command):
    return os.popen(f"atvremote -s {ip_address} --{protocol}-credentials `cat ~/Scripts/{protocol}_credentials_{room}` {command}").read()

atv_command('10.11.11.26', 'lr', 'airplay', "home home")
time.sleep(1)
atv_command('10.11.11.26', 'lr', 'airplay', "up up home")