-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from bluesky/add_children_property_to_device
Add children() for Device and DeviceVector
- Loading branch information
Showing
4 changed files
with
36 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
"""Dictionary which can contain mappings between integers and devices.""" | ||
|
||
from typing import Dict, TypeVar | ||
from typing import Dict, Generator, Tuple, TypeVar | ||
|
||
from ..utils import wait_for_connection | ||
from .device import Device | ||
|
||
VT = TypeVar("VT", bound=Device) | ||
|
||
|
||
class DeviceVector(Dict[int, VT], Device): | ||
def set_name(self, parent_name: str): | ||
self._name = parent_name | ||
for name, device in self.items(): | ||
device.set_name(f"{parent_name}-{name}") | ||
device.parent = self | ||
|
||
async def connect(self, sim: bool = False): | ||
coros = {str(k): d.connect(sim) for k, d in self.items()} | ||
await wait_for_connection(**coros) | ||
def children(self) -> Generator[Tuple[str, Device], None, None]: | ||
for attr_name, attr in self.items(): | ||
if isinstance(attr, Device): | ||
yield str(attr_name), attr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters