diff --git a/HOWTO.md b/HOWTO.md index 1b6af85..6c458e0 100644 --- a/HOWTO.md +++ b/HOWTO.md @@ -85,6 +85,10 @@ Restart the computer. Change monitors config. +### Target + +- **Device Integration:** easy_computer_manage + ### Fields - `monitors_config` @@ -103,11 +107,27 @@ Change monitors config. transform: normal scale: 2 ``` - -- `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. \ No newline at end of file diff --git a/custom_components/easy_computer_manager/const.py b/custom_components/easy_computer_manager/const.py index 0d0b943..5390cc2 100644 --- a/custom_components/easy_computer_manager/const.py +++ b/custom_components/easy_computer_manager/const.py @@ -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" diff --git a/custom_components/easy_computer_manager/services.yaml b/custom_components/easy_computer_manager/services.yaml index e957dfe..d3bb87a 100644 --- a/custom_components/easy_computer_manager/services.yaml +++ b/custom_components/easy_computer_manager/services.yaml @@ -74,4 +74,26 @@ change_monitors_config: transform: normal scale: 2 selector: - object: \ No newline at end of file + 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 \ No newline at end of file diff --git a/custom_components/easy_computer_manager/switch.py b/custom_components/easy_computer_manager/switch.py index d5a1972..8ded868 100644 --- a/custom_components/easy_computer_manager/switch.py +++ b/custom_components/easy_computer_manager/switch.py @@ -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( - 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, - ) - platform.async_register_entity_service( - SERVICE_RESTART_COMPUTER, - {}, - SERVICE_RESTART_COMPUTER, - ) + + services = [SERVICE_RESTART_TO_WINDOWS_FROM_LINUX, + SERVICE_RESTART_TO_LINUX_FROM_WINDOWS, + SERVICE_PUT_COMPUTER_TO_SLEEP, + SERVICE_START_COMPUTER_TO_WINDOWS, + SERVICE_RESTART_COMPUTER] + + for service in services: + platform.async_register_entity_service( + service, + {}, + 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 = [ diff --git a/custom_components/easy_computer_manager/utils.py b/custom_components/easy_computer_manager/utils.py index 7499d18..4278a77 100644 --- a/custom_components/easy_computer_manager/utils.py +++ b/custom_components/easy_computer_manager/utils.py @@ -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}.")