Skip to content

SwitchResource

SwitchResource

Multi-port KVM switch and EDID management for PiKVM.

Source code in src/aiopikvm/resources/switch.py
class SwitchResource(BaseResource):
    """Multi-port KVM switch and EDID management for PiKVM."""

    async def get_state(self) -> SwitchState:
        """Get the current switch state.

        Returns:
            Current switch state with active port and port list.
        """
        result = await self._get("/api/switch")
        return SwitchState.model_validate(result)

    async def set_active(self, port: str) -> None:
        """Set the active port.

        Args:
            port: Port identifier to activate.
        """
        await self._post("/api/switch/set_active", params={"port": port})

    async def get_edids(self) -> list[EDID]:
        """Get all EDID profiles.

        Returns:
            List of available EDID profiles.
        """
        result = await self._get("/api/switch/edids")
        return [EDID.model_validate(e) for e in result.get("edids", [])]

    async def create_edid(
        self, edid_id: str, data: str, *, description: str = ""
    ) -> None:
        """Create a new EDID profile.

        Args:
            edid_id: EDID profile identifier.
            data: Raw EDID data as hex string.
            description: Optional human-readable description.
        """
        body: dict[str, str] = {"id": edid_id, "data": data}
        if description:
            body["description"] = description
        await self._post("/api/switch/edids/create", json=body)

    async def change_edid(self, port: str, edid_id: str) -> None:
        """Change the EDID profile for a port.

        Args:
            port: Port identifier.
            edid_id: EDID profile identifier to assign.
        """
        await self._post(
            "/api/switch/edids/change",
            params={"port": port, "edid_id": edid_id},
        )

    async def remove_edid(self, edid_id: str) -> None:
        """Remove an EDID profile.

        Args:
            edid_id: EDID profile identifier to remove.
        """
        await self._post("/api/switch/edids/remove", params={"edid_id": edid_id})

get_state() async

Get the current switch state.

Returns:

Type Description
SwitchState

Current switch state with active port and port list.

Source code in src/aiopikvm/resources/switch.py
async def get_state(self) -> SwitchState:
    """Get the current switch state.

    Returns:
        Current switch state with active port and port list.
    """
    result = await self._get("/api/switch")
    return SwitchState.model_validate(result)

set_active(port) async

Set the active port.

Parameters:

Name Type Description Default
port str

Port identifier to activate.

required
Source code in src/aiopikvm/resources/switch.py
async def set_active(self, port: str) -> None:
    """Set the active port.

    Args:
        port: Port identifier to activate.
    """
    await self._post("/api/switch/set_active", params={"port": port})

get_edids() async

Get all EDID profiles.

Returns:

Type Description
list[EDID]

List of available EDID profiles.

Source code in src/aiopikvm/resources/switch.py
async def get_edids(self) -> list[EDID]:
    """Get all EDID profiles.

    Returns:
        List of available EDID profiles.
    """
    result = await self._get("/api/switch/edids")
    return [EDID.model_validate(e) for e in result.get("edids", [])]

create_edid(edid_id, data, *, description='') async

Create a new EDID profile.

Parameters:

Name Type Description Default
edid_id str

EDID profile identifier.

required
data str

Raw EDID data as hex string.

required
description str

Optional human-readable description.

''
Source code in src/aiopikvm/resources/switch.py
async def create_edid(
    self, edid_id: str, data: str, *, description: str = ""
) -> None:
    """Create a new EDID profile.

    Args:
        edid_id: EDID profile identifier.
        data: Raw EDID data as hex string.
        description: Optional human-readable description.
    """
    body: dict[str, str] = {"id": edid_id, "data": data}
    if description:
        body["description"] = description
    await self._post("/api/switch/edids/create", json=body)

change_edid(port, edid_id) async

Change the EDID profile for a port.

Parameters:

Name Type Description Default
port str

Port identifier.

required
edid_id str

EDID profile identifier to assign.

required
Source code in src/aiopikvm/resources/switch.py
async def change_edid(self, port: str, edid_id: str) -> None:
    """Change the EDID profile for a port.

    Args:
        port: Port identifier.
        edid_id: EDID profile identifier to assign.
    """
    await self._post(
        "/api/switch/edids/change",
        params={"port": port, "edid_id": edid_id},
    )

remove_edid(edid_id) async

Remove an EDID profile.

Parameters:

Name Type Description Default
edid_id str

EDID profile identifier to remove.

required
Source code in src/aiopikvm/resources/switch.py
async def remove_edid(self, edid_id: str) -> None:
    """Remove an EDID profile.

    Args:
        edid_id: EDID profile identifier to remove.
    """
    await self._post("/api/switch/edids/remove", params={"edid_id": edid_id})