added steam big picture service

This commit is contained in:
Mathieu Broillet 2023-12-30 15:32:31 +01:00
parent b010429981
commit 9a23a6712a
Signed by: mathieu
GPG Key ID: C0E9E0E95AF03319
5 changed files with 113 additions and 33 deletions

View File

@ -85,6 +85,10 @@ Restart the computer.
Change monitors config.
### Target
- **Device Integration:** easy_computer_manage
### Fields
- `monitors_config`
@ -105,9 +109,25 @@ Change monitors config.
```
- `entity_id`
- **Name:** Entity ID
- **Description:** Entity ID of the device to change the monitors config.
## `steam_big_picture`
### Description
Start/stop Steam in Big Picture mode or go back to Steam desktop UI.
### Target
- **Device Integration:** easy_computer_manage
### Fields
- `action`
- **Name:** Action
- **Description:** Action to perform.
- **Required:** true
- **Example:** "switch.my_computer"
- **Device Integration:** easy_computer_manage
- **Selector:** select
- **Options:**
- **start**: Start Steam in Big Picture mode.
- **stop**: Stop Steam in Big Picture mode.
- **exit**: Go back to Steam desktop UI.

View File

@ -8,3 +8,4 @@ SERVICE_PUT_COMPUTER_TO_SLEEP = "put_computer_to_sleep"
SERVICE_START_COMPUTER_TO_WINDOWS = "start_computer_to_windows"
SERVICE_RESTART_COMPUTER = "restart_computer"
SERVICE_CHANGE_MONITORS_CONFIG = "change_monitors_config"
SERVICE_STEAM_BIG_PICTURE = "steam_big_picture"

View File

@ -75,3 +75,25 @@ change_monitors_config:
scale: 2
selector:
object:
steam_big_picture:
name: Start/stop Steam Big Picture
description: Start/stop Steam Big Picture.
target:
entity:
integration: easy_computer_manager
domain: switch
fields:
action:
name: Action
description: Choose whether to start/stop Steam Big Picture or go back to the desktop Steam UI.
required: true
example: "start"
selector:
select:
options:
- label: Start
value: start
- label: Stop
value: stop
- label: Exit and go back to the desktop Steam UI
value: exit

View File

@ -37,7 +37,7 @@ from paramiko.ssh_exception import AuthenticationException
from . import utils
from .const import SERVICE_RESTART_TO_WINDOWS_FROM_LINUX, SERVICE_PUT_COMPUTER_TO_SLEEP, \
SERVICE_START_COMPUTER_TO_WINDOWS, SERVICE_RESTART_COMPUTER, SERVICE_RESTART_TO_LINUX_FROM_WINDOWS, \
SERVICE_CHANGE_MONITORS_CONFIG
SERVICE_CHANGE_MONITORS_CONFIG, SERVICE_STEAM_BIG_PICTURE
_LOGGER = logging.getLogger(__name__)
@ -95,31 +95,20 @@ async def async_setup_entry(
)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_RESTART_TO_WINDOWS_FROM_LINUX,
{},
SERVICE_RESTART_TO_WINDOWS_FROM_LINUX,
)
platform.async_register_entity_service(
services = [SERVICE_RESTART_TO_WINDOWS_FROM_LINUX,
SERVICE_RESTART_TO_LINUX_FROM_WINDOWS,
{},
SERVICE_RESTART_TO_LINUX_FROM_WINDOWS,
)
platform.async_register_entity_service(
SERVICE_PUT_COMPUTER_TO_SLEEP,
{},
SERVICE_PUT_COMPUTER_TO_SLEEP,
)
platform.async_register_entity_service(
SERVICE_START_COMPUTER_TO_WINDOWS,
{},
SERVICE_START_COMPUTER_TO_WINDOWS,
)
SERVICE_RESTART_COMPUTER]
for service in services:
platform.async_register_entity_service(
SERVICE_RESTART_COMPUTER,
service,
{},
SERVICE_RESTART_COMPUTER,
service,
)
platform.async_register_entity_service(
SERVICE_CHANGE_MONITORS_CONFIG,
make_entity_service_schema(
@ -127,6 +116,13 @@ async def async_setup_entry(
),
SERVICE_CHANGE_MONITORS_CONFIG,
)
platform.async_register_entity_service(
SERVICE_STEAM_BIG_PICTURE,
make_entity_service_schema(
{vol.Required("action"): str}
),
SERVICE_STEAM_BIG_PICTURE,
)
class ComputerSwitch(SwitchEntity):
@ -265,6 +261,14 @@ class ComputerSwitch(SwitchEntity):
else:
raise HomeAssistantError("The monitors config is empty.")
def steam_big_picture(self, action: str) -> None:
"""Controls Steam Big Picture mode."""
if action is not None:
utils.steam_big_picture(self._connection, action)
else:
raise HomeAssistantError("You must specify an action.")
def update(self) -> None:
"""Ping the computer to see if it is online and update the state."""
ping_cmd = [

View File

@ -317,3 +317,36 @@ def parse_gnome_monitor_config(output):
monitors.append(current_monitor)
return monitors
def steam_big_picture(connection: Connection, action: str):
"""Controls Steam in Big Picture mode on the host."""
_LOGGER.debug(f"Running Steam Big Picture action {action} on system running at {connection.host}.")
result = None
match action:
case "start":
if is_unix_system(connection):
result = connection.run("export WAYLAND_DISPLAY=wayland-0; export DISPLAY=:0; steam -bigpicture &")
else:
result = connection.run("start steam://open/bigpicture")
case "stop":
if is_unix_system(connection):
result = connection.run("export WAYLAND_DISPLAY=wayland-0; export DISPLAY=:0; steam -shutdown &")
else:
# TODO: check for different Steam install paths
result = connection.run("C:\\Program Files (x86)\\Steam\\steam.exe -shutdown")
case "exit":
if is_unix_system(connection):
# TODO: find a way to exit Steam Big Picture
pass
else:
# TODO: need to test (thx @MasterHidra https://www.reddit.com/r/Steam/comments/5c9l20/comment/k5fmb3k)
result = connection.run("nircmd win close title \"Steam Big Picture Mode\"")
case _:
raise HomeAssistantError(
f"Invalid action {action} for Steam Big Picture on system running at {connection.host}.")
if result is None or result.return_code != 0:
raise HomeAssistantError(f"Could not {action} Steam Big Picture on system running at {connection.host}.")