|
| 1 | +import attr |
| 2 | + |
| 3 | +from ..factory import target_factory |
| 4 | +from .common import Resource |
| 5 | + |
| 6 | + |
| 7 | +@target_factory.reg_resource |
| 8 | +@attr.s(eq=False) |
| 9 | +class LAASerialPort(Resource): |
| 10 | + """This resource describes a serial port on a DUT connected via LAA. |
| 11 | +
|
| 12 | + Args: |
| 13 | + laa_identity (str): LAA identity for connection |
| 14 | + serial_name (str): name of the serial port on the LAA""" |
| 15 | + laa_identity = attr.ib(validator=attr.validators.instance_of(str)) |
| 16 | + serial_name = attr.ib(validator=attr.validators.instance_of(str)) |
| 17 | + |
| 18 | + |
| 19 | +@target_factory.reg_resource |
| 20 | +@attr.s(eq=False) |
| 21 | +class LAAPowerPort(Resource): |
| 22 | + """This resource describes a power port on a DUT connected via LAA. |
| 23 | +
|
| 24 | + Args: |
| 25 | + laa_identity (str): LAA identity for connection |
| 26 | + power_on (list): sequence of (vbus, state) tuples for power on |
| 27 | + power_off (list): sequence of (vbus, state) tuples for power off |
| 28 | + power_cycle (list): optional sequence for power cycle""" |
| 29 | + laa_identity = attr.ib(validator=attr.validators.instance_of(str)) |
| 30 | + power_on = attr.ib(validator=attr.validators.instance_of(list)) |
| 31 | + power_off = attr.ib(validator=attr.validators.instance_of(list)) |
| 32 | + power_cycle = attr.ib( |
| 33 | + default=None, |
| 34 | + validator=attr.validators.optional(attr.validators.instance_of(list)), |
| 35 | + ) |
| 36 | + def __attrs_post_init__(self): |
| 37 | + super().__attrs_post_init__() |
| 38 | + for name in ("power_on", "power_off"): |
| 39 | + self._check_power_sequence(name, getattr(self, name)) |
| 40 | + if self.power_cycle is not None: |
| 41 | + self._check_power_sequence("power_cycle", self.power_cycle) |
| 42 | + |
| 43 | + @staticmethod |
| 44 | + def _check_power_sequence(name, seq): |
| 45 | + for i, entry in enumerate(seq): |
| 46 | + if not isinstance(entry, (list, tuple)) or len(entry) != 2: |
| 47 | + raise ValueError( |
| 48 | + f"{name}[{i}] must be [vbus, state], got {entry!r}" |
| 49 | + ) |
| 50 | + if not isinstance(entry[0], str) or not isinstance(entry[1], str): |
| 51 | + raise ValueError( |
| 52 | + f"{name}[{i}] must be [str, str], got {entry!r}" |
| 53 | + ) |
| 54 | + |
| 55 | + |
| 56 | +@target_factory.reg_resource |
| 57 | +@attr.s(eq=False) |
| 58 | +class LAAUSBGadgetMassStorage(Resource): |
| 59 | + """This resource describes a USB gadget mass storage device on a LAA. |
| 60 | +
|
| 61 | + Args: |
| 62 | + laa_identity (str): LAA identity for connection |
| 63 | + image (str): mass storage image filename""" |
| 64 | + laa_identity = attr.ib(validator=attr.validators.instance_of(str)) |
| 65 | + image = attr.ib(validator=attr.validators.instance_of(str)) |
| 66 | + |
| 67 | + |
| 68 | +@target_factory.reg_resource |
| 69 | +@attr.s(eq=False) |
| 70 | +class LAAUSBPort(Resource): |
| 71 | + """This resource describes USB ports on a DUT connected via LAA. |
| 72 | +
|
| 73 | + Args: |
| 74 | + laa_identity (str): LAA identity for connection |
| 75 | + usb_ports (list): list of USB port numbers to control""" |
| 76 | + laa_identity = attr.ib(validator=attr.validators.instance_of(str)) |
| 77 | + usb_ports = attr.ib(validator=attr.validators.instance_of(list)) |
| 78 | + |
| 79 | + |
| 80 | +@target_factory.reg_resource |
| 81 | +@attr.s(eq=False) |
| 82 | +class LAAButtonPort(Resource): |
| 83 | + """This resource describes virtual buttons on a DUT connected via LAA. |
| 84 | +
|
| 85 | + Args: |
| 86 | + laa_identity (str): LAA identity for connection |
| 87 | + buttons (list): list of button names available""" |
| 88 | + laa_identity = attr.ib(validator=attr.validators.instance_of(str)) |
| 89 | + buttons = attr.ib(validator=attr.validators.instance_of(list)) |
| 90 | + |
| 91 | + |
| 92 | +@target_factory.reg_resource |
| 93 | +@attr.s(eq=False) |
| 94 | +class LAALed(Resource): |
| 95 | + """This resource describes a LED on a DUT connected via LAA. |
| 96 | +
|
| 97 | + Args: |
| 98 | + laa_identity (str): LAA identity for connection""" |
| 99 | + laa_identity = attr.ib(validator=attr.validators.instance_of(str)) |
| 100 | + |
| 101 | + |
| 102 | +@target_factory.reg_resource |
| 103 | +@attr.s(eq=False) |
| 104 | +class LAATempSensor(Resource): |
| 105 | + """This resource describes a temperature sensor on a DUT connected via LAA. |
| 106 | +
|
| 107 | + Args: |
| 108 | + laa_identity (str): LAA identity for connection""" |
| 109 | + laa_identity = attr.ib(validator=attr.validators.instance_of(str)) |
| 110 | + |
| 111 | + |
| 112 | +@target_factory.reg_resource |
| 113 | +@attr.s(eq=False) |
| 114 | +class LAAWattMeter(Resource): |
| 115 | + """This resource describes a power meter on a DUT connected via LAA. |
| 116 | +
|
| 117 | + Args: |
| 118 | + laa_identity (str): LAA identity for connection""" |
| 119 | + laa_identity = attr.ib(validator=attr.validators.instance_of(str)) |
| 120 | + |
| 121 | + |
| 122 | +@target_factory.reg_resource |
| 123 | +@attr.s(eq=False) |
| 124 | +class LAAProvider(Resource): |
| 125 | + """This resource describes file storage on an LAA for TFTP provisioning. |
| 126 | +
|
| 127 | + Args: |
| 128 | + laa_identity (str): LAA identity for connection""" |
| 129 | + laa_identity = attr.ib(validator=attr.validators.instance_of(str)) |
| 130 | + |
| 131 | + |
0 commit comments