toggle_device_power
Control power states for smart home devices by turning them on or off using device identifiers. This tool manages Bond Bridge-connected devices through toggle commands.
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 async handler function decorated with @mcp.tool(), which registers and implements the toggle_device_power tool. It fetches the current device state, determines if it's on or off, calls the appropriate BondClient method (turn_on or turn_off), and returns the action performed and result.@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)}"}