-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathharp.j2
More file actions
65 lines (49 loc) · 2.2 KB
/
harp.j2
File metadata and controls
65 lines (49 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Auto-generated code. Do not edit manually.
from typing import TYPE_CHECKING, Annotated, List, Literal, Optional, Union
from pydantic import BaseModel, Field, field_validator
from typing_extensions import TypeAliasType
from ._base import Device
class _HarpDeviceBase(Device):
who_am_i: Optional[int] = Field(default=None, le=9999, ge=0, description="Device WhoAmI")
serial_number: Optional[str] = Field(default=None, description="Device serial number")
port_name: str = Field(..., description="Device port name")
class HarpDeviceGeneric(_HarpDeviceBase):
device_type: Literal["Generic"] = "Generic"
class ConnectedClockOutput(BaseModel):
target_device: Optional[str] = Field(
default=None, description="Optional device name to provide user additional information"
)
output_channel: int = Field(..., ge=0, description="Output channel")
def _assert_unique_output_channels(outputs: List[ConnectedClockOutput]) -> List[ConnectedClockOutput]:
channels = set([ch.output_channel for ch in outputs])
if len(channels) != len(outputs):
raise ValueError("Output channels must be unique")
return outputs
{% for board in boards %}
class Harp{{ board.class_name }}(_HarpDeviceBase):
device_type: Literal["{{ board.name }}"] = "{{ board.name }}"
who_am_i: Literal[{{ board.whoami }}] = {{ board.whoami }}
{% if board.is_clock %}connected_clock_outputs: List[ConnectedClockOutput] = Field(default=[], description="Connected clock outputs"){% endif %}
{% if board.is_clock %}
@field_validator("connected_clock_outputs")
@classmethod
def validate_connected_clock_outputs(cls, v: List[ConnectedClockOutput]) -> List[ConnectedClockOutput]:
return _assert_unique_output_channels(v)
{% endif %}{% endfor %}
_HarpDevice = Union[
HarpDeviceGeneric,{% for board in boards %}
Harp{{ board.class_name }},{% endfor %}
]
if TYPE_CHECKING:
HarpDevice = _HarpDevice
else:
HarpDevice = TypeAliasType(
"HarpDevice",
Annotated[_HarpDevice, Field(discriminator="device_type")],
)
__all__ = [
"ConnectedClockOutput",
"HarpDeviceGeneric",{% for board in boards %}
"Harp{{ board.class_name }}",{% endfor %}
"HarpDevice",
]