Skip to content

sim2bot.Robot.set_room_opening

Experimental API

This surface is still being validated and may change before the public beta.

set_room_opening(opening: str, fraction: float) -> None

Set the target opening fraction of a scene door or window.

Parameters:

  • opening (str) –

    Device ID returned by room_devices.

  • fraction (float) –

    0.0 closed through 1.0 fully open. Values are clamped.

Returns:

  • None

    The clamped target is sent asynchronously.

Raises:

  • TypeError

    If fraction cannot be converted to float.

  • ValueError

    If fraction is not a numeric value.

  • RuntimeError

    If the client is not connected.

  • ConnectionClosed

    If the WebSocket closes while sending the command.

  • OSError

    If the selected transport cannot send the command.

Warning

This API is experimental. Browser-side room actuation is currently under revision and may not reliably move every authored mechanism. Do not rely on it for automated tests until that work is completed.

Source code in sim2bot/client.py
def set_room_opening(self, opening: str, fraction: float) -> None:
    """Set the target opening fraction of a scene door or window.

    Args:
        opening: Device ID returned by
            [`room_devices`][sim2bot.client.Robot.room_devices].
        fraction: ``0.0`` closed through ``1.0`` fully open. Values are clamped.

    Returns:
        The clamped target is sent asynchronously.

    Raises:
        TypeError: If ``fraction`` cannot be converted to ``float``.
        ValueError: If ``fraction`` is not a numeric value.
        RuntimeError: If the client is not connected.
        ConnectionClosed: If the WebSocket closes while sending the command.
        OSError: If the selected transport cannot send the command.

    Warning:
        This API is experimental. Browser-side room actuation is currently
        under revision and may not reliably move every authored mechanism.
        Do not rely on it for automated tests until that work is completed.
    """
    value = max(0.0, min(1.0, float(fraction)))
    self._send(
        {
            "type": "room_opening",
            "opening": str(opening),
            "fraction": value,
        }
    )

Practical examples

Examples use objects discovered from the current scene rather than hard-coded robot metadata.

Request a fully open door

door = next(
    device for device in sim.room_devices()
    if device.kind == "door"
)
sim.set_room_opening(door.id, 1.0)

Request a partial opening

sim.set_room_opening(opening=device.id, fraction=0.4)

Guidance

Important behavior

This API is experimental and current browser-side room mechanisms may not move reliably.

Common error

Pass the discovered device ID, not its display name.


See also