toggle_device_power
Control power for Bond Bridge smart home devices by toggling them on or off using their device identifier.
Instructions
Toggle power state of a Bond device (on/off).
Args: device_id: The Bond device identifier
Returns: Result of the toggle operation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | Yes |
Implementation Reference
- src/bond_mcp/server.py:121-153 (handler)The @mcp.tool()-decorated async function that implements the toggle_device_power tool logic: retrieves current device state, toggles power by calling turn_on or turn_off on the BondClient, and returns the result or error.@mcp.tool() async def toggle_device_power(device_id: str) -> Dict[str, Any]: """Toggle power state of a Bond device (on/off). Args: device_id: The Bond device identifier Returns: Result of the toggle operation. """ try: async with await get_bond_client() as client: # Get current state to determine action current_state = await client.get_device_state(device_id) power = current_state.get("power", 0) if power == 1: result = await client.turn_off(device_id) action = "turned off" else: result = await client.turn_on(device_id) action = "turned on" return { "device_id": device_id, "action": action, "result": result } except BondAPIError as e: return {"error": f"Failed to toggle device power: {str(e)}"} except Exception as e: logger.error(f"Unexpected error toggling device power: {e}") return {"error": f"Unexpected error: {str(e)}"}
- src/bond_mcp/server.py:121-121 (registration)The @mcp.tool() decorator registers the toggle_device_power function as an MCP tool.@mcp.tool()