Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support extensible enums #238

Closed
DiamondJoseph opened this issue Apr 18, 2024 · 1 comment · Fixed by #341
Closed

Support extensible enums #238

DiamondJoseph opened this issue Apr 18, 2024 · 1 comment · Fixed by #341
Assignees
Labels
bug Something isn't working enhancement New feature or request hackathon Good issues for the upcoming bluesky hackathon i22

Comments

@DiamondJoseph
Copy link
Contributor

For the Aravis detector, we need to support a dynamically extensible enumeration of values for some signals (e.g. the AravisTriggerSource, which we rely on the values Free_Run and Line_1 being present, but there may also be Line_2, Line_3...).

This may be accomplished by a new class of Signal that has a write_pv of type Enum and a read_pv of type str, which would require SignalBackend to take two generic arguments. The existing Signal implementations then have a single Generic bound which is passed into both generic bounds of the backend and the new implementation has bounds of [str, enum_class] for read, write respectively.

This ticket is necessary for #190

@DiamondJoseph DiamondJoseph added bug Something isn't working enhancement New feature or request i22 hackathon Good issues for the upcoming bluesky hackathon labels Apr 18, 2024
@DiamondJoseph DiamondJoseph self-assigned this Apr 18, 2024
@coretl
Copy link
Collaborator

coretl commented May 15, 2024

Discussed this with @evalott100 and she suggested:

@dataclass
class RuntimeEnumDataclass:
    choices: Sequence[str]
    @classmethod
    def __getitem__(cls, *items: str) -> "RuntimeEnum":
        return cls(items)

if TYPE_CHECKING:
    RuntimeEnum = Literal
else:
    RuntimeEnum = RuntimeEnumDataclass

# aravis_something.py
class AravisCamera(Device):
    def __init__(self, prefix):
        self.trigger_mode = epics_signal_rw(RuntimeEnum["Line1", "FixedRate"], prefix + "TriggerMode")
        ...

# _aioca.py
def make_converter(...):
    ...
    elif isinstance(datatype, RuntimeEnum):
        assert set(datatype.choices).issubset(pv_choices)
    ...

We were unable to come up with a better name than RuntimeEnum, but others may have better ideas...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request hackathon Good issues for the upcoming bluesky hackathon i22
Projects
None yet
3 participants