diff --git a/custom_components/easy_computer_manage/services.yaml b/custom_components/easy_computer_manage/services.yaml index d435823..cd7d372 100644 --- a/custom_components/easy_computer_manage/services.yaml +++ b/custom_components/easy_computer_manage/services.yaml @@ -57,12 +57,17 @@ change_monitors_config: name: Change monitors config description: Change monitors config. fields: + entity_id: + name: Entity ID + description: Entity ID of the device to change monitors config. + required: true + selector: + entity: + integration: easy_computer_manage + domain: switch monitors_config: name: Monitors config description: Monitors config. required: true selector: - text: - target: - device: - integration: easy_computer_manage \ No newline at end of file + object: \ No newline at end of file diff --git a/custom_components/easy_computer_manage/switch.py b/custom_components/easy_computer_manage/switch.py index 1aa7af1..398ae08 100644 --- a/custom_components/easy_computer_manage/switch.py +++ b/custom_components/easy_computer_manage/switch.py @@ -22,7 +22,7 @@ from homeassistant.const import ( CONF_NAME, CONF_PASSWORD, CONF_PORT, - CONF_USERNAME, + CONF_USERNAME, CONF_ENTITY_ID, ) from homeassistant.core import HomeAssistant from homeassistant.helpers import ( @@ -58,6 +58,12 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( vol.Optional(CONF_PORT, default=22): cv.string, } ) +SERVICE_CHANGE_MONITORS_CONFIG_SCHEMA = vol.Schema( + { + vol.Required(CONF_ENTITY_ID): cv.entity_id, + vol.Required("monitors_config"): dict, + } +) async def async_setup_entry( @@ -121,7 +127,7 @@ async def async_setup_entry( ) platform.async_register_entity_service( SERVICE_CHANGE_MONITORS_CONFIG, - {}, + SERVICE_CHANGE_MONITORS_CONFIG_SCHEMA, SERVICE_CHANGE_MONITORS_CONFIG, ) @@ -255,9 +261,10 @@ class ComputerSwitch(SwitchEntity): else: utils.restart_system(self._connection) - def change_monitors_config(self, yaml_config: str) -> None: + def change_monitors_config(self, **kwargs) -> None: """Change the monitors configuration using a YAML config file.""" - utils.change_monitors_config(self._connection, yaml_config) + if kwargs["monitors_config"] is not None: + utils.change_monitors_config(self._connection, kwargs["monitors_config"]) def update(self) -> None: """Ping the computer to see if it is online and update the state.""" diff --git a/custom_components/easy_computer_manage/utils.py b/custom_components/easy_computer_manage/utils.py index 2d716fa..9182cec 100644 --- a/custom_components/easy_computer_manage/utils.py +++ b/custom_components/easy_computer_manage/utils.py @@ -206,7 +206,7 @@ def restart_to_windows_from_linux(connection: Connection): connection.host) -def change_monitors_config(connection: Connection, monitors_config: str): +def change_monitors_config(connection: Connection, monitors_config: dict): """From a YAML config, changes the monitors configuration on the host, only works on Linux and Gnome (for now).""" # TODO: Add support for Windows