def is_connected_to_powered(self, visited=()):
    if self in visited:
        return False
visited = set(visited)
visited.add(self)
for neighbor in self.neighbors:
    pass
How to recursively check for attributes in an object?