fixed not being able to pass data trough service data

This commit is contained in:
Mathieu Broillet 2023-12-28 23:44:55 +01:00
parent 55083f4bd8
commit 99ca6d9d0d
Signed by: mathieu
GPG Key ID: C0E9E0E95AF03319
3 changed files with 21 additions and 9 deletions

View File

@ -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
object:

View File

@ -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."""

View File

@ -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