Skip to content

feat: Add pin enumeration utilities (list_pins, show_pins) (#179)#181

Open
shanemmattner wants to merge 1 commit intomainfrom
feat/179-pin-enumeration-utilities
Open

feat: Add pin enumeration utilities (list_pins, show_pins) (#179)#181
shanemmattner wants to merge 1 commit intomainfrom
feat/179-pin-enumeration-utilities

Conversation

@shanemmattner
Copy link
Copy Markdown
Contributor

Summary

Adds pin enumeration utilities to make pin discovery easy for users. Users no longer need to know component pins in advance - they can simply call list_pins() or show_pins() to discover them.

Changes

  • ✅ Added list_pins() method to Component class - returns List[Dict[str, Any]]
  • ✅ Added show_pins() method to Component class - prints formatted table
  • ✅ Added list_pins() method to ComponentProxy class
  • ✅ Added show_pins() method to ComponentProxy class
  • ✅ Added comprehensive test suite (19 tests) in test_pin_utilities.py
  • ✅ All tests passing (19/19)

Example Usage

Programmatic Pin Discovery

import kicad_sch_api as ksa

sch = ksa.create_schematic("Test")
esp32 = sch.components.add('RF_Module:ESP32-WROOM-32', 'U1', 'ESP32')

# List pins programmatically
pins = esp32.list_pins()
print(f"ESP32 has {len(pins)} pins")

for pin in pins:
    print(f"Pin {pin['number']}: {pin['name']} ({pin['type']})")
    
# Filter for power pins
power_pins = [p for p in pins if 'POWER' in p['type']]

Interactive Pin Display

# Display formatted table
esp32.show_pins()

# Output:
# Pins for U1 (RF_Module:ESP32-WROOM-32):
# Pin#   Name                 Type
# ----------------------------------------
# 1      GND                  POWER_IN
# 2      3V3                  POWER_IN
# 3      EN                   INPUT
# ...

Testing

uv run pytest tests/unit/test_pin_utilities.py -v
# 19 passed in 0.35s

Benefits

  • ✅ No need to know pins in advance
  • ✅ Easy discovery in interactive sessions (Jupyter, REPL)
  • ✅ Programmatic pin filtering and processing
  • ✅ Helps write design checkers and validators
  • ✅ Better developer experience

Related Issues

Next Steps

Future phases (#179):

  • Phase 2: Library inspection before placing components
  • Phase 3: Search functionality
  • Phase 4: Rich display for Jupyter notebooks

🤖 Generated with Claude Code

Add list_pins() and show_pins() methods to make pin discovery easy
for users. Users can now enumerate component pins without needing
to know them in advance.

Changes:
- Added list_pins() method to Component class (returns List[Dict])
- Added show_pins() method to Component class (prints formatted table)
- Added list_pins() method to ComponentProxy class
- Added show_pins() method to ComponentProxy class
- Added comprehensive test suite (19 tests) in test_pin_utilities.py
- All tests passing

Example usage:
```python
# List pins programmatically
pins = comp.list_pins()
for pin in pins:
    print(f"Pin {pin['number']}: {pin['name']} ({pin['type']})")

# Display formatted table
comp.show_pins()
```

Implements #179 Phase 1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant