def _get_all_terminals(device):
    """Gets all terminals, including those nested within child devices."""
    terms = device.terminals
    if hasattr(device, 'internal_terminal'):
        terms += [device.internal_terminal]
    if hasattr(device, 'devices'):
        terms += [t for d in device.devices for t in _get_all_terminals(d)]
    return terms