postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
827 stars 87 forks source link

Add ability to close or force close applications #2349

Open DennisFury opened 3 months ago

DennisFury commented 3 months ago

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!

DennisFury commented 3 months ago

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