plesty.lib.sim.demo_device
A complete, hardware-free device module — the standard, made executable.
Every test that needs a device used to hand-write one. plesty-lib’s pipeline
tests had _MockDevice, plesty-sdk’s scaffold tests had _DocDevice, and
each hub module has its own. Four fakes, each a partial reading of the
standard, each drifting: a duck-typed stand-in passes whatever it was written
against, so a gate can be green here and the real thing fail on a device that
merely registers its parameters differently.
DemoDevice replaces them. It is a real
BaseDeviceSyncModel subclass
exercising the parts of the standard that are actually easy to get wrong:
a grouped parameter, so
get_config_list()answersMOTOR.positionwhile the group is namedmotor— the command-prefix against group-name mismatch three modules hit independentlyevery declarable type, so a mock generator that mishandles one is caught
read-only, write-only and read-write access modes
a parameter constrained by
options, and one bymin_value/max_valuean operation with inputs and outputs, and one with neither
It is hardware-free the way the standard says a device should be:
address="mock" selects an in-memory store, and any other address refuses
to connect, exactly as a real module does when the instrument is absent. That
convention is what plesty init mock-test probes for, so a module author
reading this file is reading the thing the tooling expects.
Because it is a real device, the mock pipeline can be run against it — and is, in this package’s own test suite. The gates then have a subject that must keep passing, which is what makes a change to them detectable.
Usage:
from plesty.lib.sim.demo_device import DemoDevice
from plesty.lib.test.device_pipeline import DevicePipeline
DevicePipeline(DemoDevice, address="mock").run_mock_pipeline()
Attributes
Classes
A device that declares one of everything and needs no instrument. |
Module Contents
- plesty.lib.sim.demo_device.MOCK_ADDRESS = 'mock'
- class plesty.lib.sim.demo_device.DemoDevice(address: str = MOCK_ADDRESS, device_id: str | None = None, **kwargs: Any)
Bases:
plesty.lib.device.base_device_sync.BaseDeviceSyncModelA device that declares one of everything and needs no instrument.
- Parameters:
address (str) –
"mock"for the in-memory store. Any other value is taken to be a real instrument and refuses to connect, which is what a module does when the hardware is not there.device_id (str | None) – Identifier, generated when omitted so repeated construction does not collide on the resource registry — the gates construct the device several times over.
**kwargs (Any) – Forwarded to the base device.
Register the parameters and operations, and prepare the store.
- address = 'mock'
- _connected = False
- _store: dict[str, Any]
- _register_parameters() None
Register one parameter of each kind the standard allows.
- Return type:
None
- _register_operations() None
Register an operation with parameters, and one without.
- Return type:
None
- _solve_operation(request: dict[str, Any]) dict[str, Any]
Execute one operation against the in-memory store.
Every value returned here is a JSON primitive. That is the point, not a simplification: the 2026-08-04 round lost a server to an ndarray return value that could not be serialized, so a demo device returning anything the protocol cannot carry would teach the defect.
- Parameters:
request (dict[str, Any]) –
{"op": name, "params": {...}, "func_meta": ...}, the shapeFunctionSystemsends.- Returns:
The operation’s declared outputs.
- Raises:
KeyError – If the operation is not registered.
- Return type:
dict[str, Any]
- init(main: Any = None) None
Prepare the device. Nothing to open for the in-memory store.
- Parameters:
main (Any) – Unused; accepted for interface compatibility.
- Return type:
None
- connect() bool
Connect, or refuse when pointed at an instrument that is not there.
- Returns:
Trueonce connected.- Raises:
ConnectionError – If address is not
MOCK_ADDRESS.- Return type:
bool
- disconnect() None
Disconnect and drop the stored state.
- Return type:
None
- check_operatability() bool
Return whether the device is connected.
- Returns:
Truewhen connected.- Return type:
bool
- check_errors() list[str]
Return the device’s error queue.
- Returns:
An empty list; the demo device has no fault to report.
- Return type:
list[str]
- identity() str
Return the identification string.
- Returns:
A vendor, model, serial and firmware string, as
*IDN?answers.- Return type:
str
- _write_(key: str, value: Any, **kwargs: Any) bool
Store a value.
- Parameters:
key (str) – Runtime parameter key.
value (Any) – Value to store.
**kwargs (Any) – Unused.
- Returns:
True.- Return type:
bool
- _query_(key: str, **kwargs: Any) Any
Return a stored value, or the parameter’s default.
- Parameters:
key (str) – Runtime parameter key.
**kwargs (Any) – Unused.
- Returns:
The stored value, or the declared default.
- Return type:
Any
- plesty.lib.sim.demo_device.DocDevice