Skip to content

Commit

Permalink
Merge pull request #180 from loopj/iterate-over-client
Browse files Browse the repository at this point in the history
Add support for iterating over every object held by the client
  • Loading branch information
loopj authored Jan 26, 2025
2 parents 866c4ea + 4342dd3 commit d561a81
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/aiovantage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__all__ = ["Vantage", "VantageEvent"]

import asyncio
from collections.abc import Callable
from collections.abc import Callable, Iterator
from ssl import SSLContext
from types import TracebackType
from typing import Any, TypeVar, cast
Expand Down Expand Up @@ -117,6 +117,11 @@ def __contains__(self, vid: int) -> bool:
"""Is the given Vantage ID known by any controller."""
return any(vid in controller for controller in self._controllers)

def __iter__(self) -> Iterator[SystemObject]:
"""Iterate over all objects known by the controllers."""
for controller in self._controllers:
yield from controller

async def __aenter__(self) -> Self:
"""Return context manager."""
return self
Expand Down

0 comments on commit d561a81

Please sign in to comment.