Skip to content
Snippets Groups Projects
Commit 23e2d67e authored by Philipp Schmidt's avatar Philipp Schmidt Committed by sqsonc
Browse files

manager: Show tracked devices as a property

parent 22f5e9e1
No related branches found
No related tags found
1 merge request!12Snapshot: field test deployed version as of end of run 202201
...@@ -412,6 +412,12 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -412,6 +412,12 @@ class CalibrationManager(DeviceClientBase, Device):
self.state = State.CHANGING self.state = State.CHANGING
background(self._instantiate_pipeline()) background(self._instantiate_pipeline())
managedDevices = VectorString(
displayedName='Managed devices',
description='List of currently managed devices.',
defaultValue=[],
accessMode=AccessMode.READONLY)
@Slot( @Slot(
displayedName='Discover managed devices', displayedName='Discover managed devices',
description='', description='',
...@@ -428,7 +434,7 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -428,7 +434,7 @@ class CalibrationManager(DeviceClientBase, Device):
async def applyManagedValues(self): async def applyManagedValues(self):
background(self._apply_managed_values()) background(self._apply_managed_values())
managed = Node( managedKeys = Node(
ManagedKeysNode, ManagedKeysNode,
displayedName='Managed keys', displayedName='Managed keys',
description='Properties and slots managed on devices in the pipeline.') description='Properties and slots managed on devices in the pipeline.')
...@@ -464,6 +470,9 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -464,6 +470,9 @@ class CalibrationManager(DeviceClientBase, Device):
# in the same domain and having the specified class ID. # in the same domain and having the specified class ID.
self._correction_device_ids = set() self._correction_device_ids = set()
# Task object to update managed devices list.
self._managed_devices_updater = None
async def onInitialization(self): async def onInitialization(self):
self.state = State.INIT self.state = State.INIT
...@@ -482,6 +491,7 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -482,6 +491,7 @@ class CalibrationManager(DeviceClientBase, Device):
if info['type'] == 'device': if info['type'] == 'device':
self._check_new_device(instance_id, info['classId']) self._check_new_device(instance_id, info['classId'])
self._update_managed_devices()
@slot @slot
def slotInstanceGone(self, instance_id, info): def slotInstanceGone(self, instance_id, info):
...@@ -493,6 +503,7 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -493,6 +503,7 @@ class CalibrationManager(DeviceClientBase, Device):
self._daq_device_ids.discard(instance_id) self._daq_device_ids.discard(instance_id)
self._domain_device_ids.discard(instance_id) self._domain_device_ids.discard(instance_id)
self._correction_device_ids.discard(instance_id) self._correction_device_ids.discard(instance_id)
self._update_managed_devices()
async def _async_init(self): async def _async_init(self):
# Populate the device ID sets with what's out there right now. # Populate the device ID sets with what's out there right now.
...@@ -523,7 +534,10 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -523,7 +534,10 @@ class CalibrationManager(DeviceClientBase, Device):
elif device_id.startswith(self._device_id_root): elif device_id.startswith(self._device_id_root):
# This device lives under the same device ID root as this # This device lives under the same device ID root as this
# manager instance. # manager instance, but don't add yourself!
if device_id == self.deviceId:
return
self._domain_device_ids.add(device_id) self._domain_device_ids.add(device_id)
if class_id == self._correction_class_id: if class_id == self._correction_class_id:
...@@ -551,6 +565,8 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -551,6 +565,8 @@ class CalibrationManager(DeviceClientBase, Device):
for device_id in devices: for device_id in devices:
self._check_new_device(device_id, devices[device_id, 'classId']) self._check_new_device(device_id, devices[device_id, 'classId'])
self._update_managed_devices(True)
async def _discover_managed_devices(self): async def _discover_managed_devices(self):
self._daq_device_ids.clear() self._daq_device_ids.clear()
self._domain_device_ids.clear() self._domain_device_ids.clear()
...@@ -560,6 +576,25 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -560,6 +576,25 @@ class CalibrationManager(DeviceClientBase, Device):
self.state = State.ACTIVE self.state = State.ACTIVE
async def _delayed_managed_devices_update(self):
await sleep(1.0) # Throttle updates to at most once a second.
self.managedDevices = sorted(
self._domain_device_ids | self._daq_device_ids)
self._managed_devices_updater = None # Clear task again.
def _update_managed_devices(self, forced=False):
if self._managed_devices_updater is not None:
# Update already in progress, ignore.
return
all_managed_devices = self._domain_device_ids | self._daq_device_ids
if forced or len(all_managed_devices) != len(self.managedDevices):
# Trigger an update either if forced or the number of
# devices changed.
self._managed_devices_updater = background(
self._delayed_managed_devices_update())
async def _get_shared_keys(self, device_ids, keys): async def _get_shared_keys(self, device_ids, keys):
"""Find the most common property values on devices.""" """Find the most common property values on devices."""
...@@ -682,9 +717,9 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -682,9 +717,9 @@ class CalibrationManager(DeviceClientBase, Device):
# The value are then obtained from the Node object again since # The value are then obtained from the Node object again since
# enums are converted to their values by toSchemaAndAttrs, which # enums are converted to their values by toSchemaAndAttrs, which
# in turn is not valid for property definition. # in turn is not valid for property definition.
_, attrs = Descriptor.toSchemaAndAttrs(self.__class__.managed, _, attrs = Descriptor.toSchemaAndAttrs(self.__class__.managedKeys,
None, None) None, None)
managed_node_attrs = {key: getattr(self.__class__.managed, key) managed_node_attrs = {key: getattr(self.__class__.managedKeys, key)
for key in attrs.keys()} for key in attrs.keys()}
# Build a proxy from the managed schema, and create a new node # Build a proxy from the managed schema, and create a new node
...@@ -712,7 +747,7 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -712,7 +747,7 @@ class CalibrationManager(DeviceClientBase, Device):
remote_key=remote_key): remote_key=remote_key):
background(self._call_on_corrections(remote_key)) background(self._call_on_corrections(remote_key))
_managed_slot_called.__name__ = f'managed.{local_key}' _managed_slot_called.__name__ = f'managedKeys.{local_key}'
descr.__call__(_managed_slot_called) descr.__call__(_managed_slot_called)
# Managed slots can only be called in the ACTIVE # Managed slots can only be called in the ACTIVE
...@@ -761,7 +796,7 @@ class CalibrationManager(DeviceClientBase, Device): ...@@ -761,7 +796,7 @@ class CalibrationManager(DeviceClientBase, Device):
_sanitize_node(managed_node, managed_hash) _sanitize_node(managed_node, managed_hash)
# Inject the newly prepared node for managed keys. # Inject the newly prepared node for managed keys.
self.__class__.managed = managed_node self.__class__.managedKeys = managed_node
await self.publishInjectedParameters() await self.publishInjectedParameters()
self._managed_keys = managed_keys self._managed_keys = managed_keys
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment