mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2026-05-12 06:35:35 +02:00
refactor(pandabox): adapt block_name_mapping and improve docstrings
This commit is contained in:
@@ -175,7 +175,17 @@ class DataCallback(TypedDict):
|
||||
|
||||
|
||||
class PandaBoxDataConnection:
|
||||
"""Context Manager to conveniently manage the connection to the PandaBox data streams."""
|
||||
"""
|
||||
Context Manager to conveniently manage the connection to the PandaBox data streams.
|
||||
|
||||
Args:
|
||||
host (str): The hostname of the PandaBox to connect to.
|
||||
scaled Optional(bool): Whether to request scaled data from the PandaBox. Scaled is recommended
|
||||
default is this is how data is also presented in the PandaBox UI or received
|
||||
from the CLI tool. Defaults to True.
|
||||
socket_timeout Optional(float): Timeout of the socket if no new data is received. Important
|
||||
to be able to unblock and interrupt the data connection to the Pandabox.
|
||||
"""
|
||||
|
||||
def __init__(self, host: str, scaled: bool = True, socket_timeout: float = 0.1):
|
||||
self.host = host
|
||||
@@ -755,7 +765,7 @@ class PandaBox(PSIDeviceBase):
|
||||
# Python attribute names, but also to match the renamed signals provided by the signal_alias mapping.
|
||||
# The mapping is done in two steps:
|
||||
# I. Remove dots '.' from Pandablock keys as they are not valid for Python attribute names
|
||||
keys = [block_name_mapping(key) for key in keys]
|
||||
keys = block_name_mapping(keys)
|
||||
# Map keys if mapping is provided. We also need to translate all keys received from the
|
||||
mapped_key = [self.signal_alias.get(key, key) for key in keys]
|
||||
for k in mapped_key:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Module containing utility functions for the PandaBox device."""
|
||||
|
||||
import keyword
|
||||
from collections.abc import Iterable
|
||||
|
||||
PANDA_AVAIL_PCAP_BLOCKS = [
|
||||
"INENC1.VAL",
|
||||
@@ -51,9 +52,13 @@ def is_valid_attribute_name(name: str) -> bool:
|
||||
return name.isidentifier() and not keyword.iskeyword(name)
|
||||
|
||||
|
||||
def block_name_mapping(block_name: str) -> str:
|
||||
def block_name_mapping(block_name: str | Iterable[str]) -> str | list[str]:
|
||||
"""Map block names to a format suitable for use as attribute names."""
|
||||
return block_name.replace(".", "_")
|
||||
if isinstance(block_name, str):
|
||||
return block_name.replace(".", "_")
|
||||
if isinstance(block_name, Iterable):
|
||||
return [name.replace(".", "_") for name in block_name]
|
||||
raise TypeError(f"Unsupported type for block_name: {type(block_name)!r}")
|
||||
|
||||
|
||||
def get_pcap_capture_fields():
|
||||
|
||||
Reference in New Issue
Block a user