From 45d17c75d15b19d4a5be40dbdaafbb93e6e0f0de Mon Sep 17 00:00:00 2001 From: Eva Lott Date: Mon, 11 Nov 2024 13:47:44 +0000 Subject: [PATCH] added `:LABEL` to fields from metadata --- src/fastcs_pandablocks/panda/controller.py | 8 ++++++++ src/fastcs_pandablocks/panda/fields.py | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/fastcs_pandablocks/panda/controller.py b/src/fastcs_pandablocks/panda/controller.py index b717400..4d4f8a9 100644 --- a/src/fastcs_pandablocks/panda/controller.py +++ b/src/fastcs_pandablocks/panda/controller.py @@ -59,6 +59,8 @@ def __init__(self, hostname: str, poll_period: float) -> None: self._raw_panda = RawPanda(hostname) self._blocks: dict[PandaName, FieldController] = {} + self.connected = False + super().__init__() @property @@ -66,9 +68,14 @@ def additional_attributes(self): return self._additional_attributes async def connect(self) -> None: + if self.connected: + # `connect` needs to be called in `initialise`, + # then FastCS will attempt to call it again. + return await self._raw_panda.connect() blocks, fields, labels, initial_values = await self._raw_panda.introspect() self._blocks = _parse_introspected_data(blocks, fields, labels, initial_values) + self.connected = True async def initialise(self) -> None: await self.connect() @@ -109,6 +116,7 @@ async def update_field_value(self, panda_name: PandaName, value: str): @scan(0.1) async def update(self): + raise RuntimeError("FINALLY CALLED!") changes = await self._raw_panda.get_changes() await asyncio.gather( *[ diff --git a/src/fastcs_pandablocks/panda/fields.py b/src/fastcs_pandablocks/panda/fields.py index 9f1a795..c46fe58 100644 --- a/src/fastcs_pandablocks/panda/fields.py +++ b/src/fastcs_pandablocks/panda/fields.py @@ -56,6 +56,13 @@ def __init__( self._additional_attributes: dict[str, Attribute] = {} + if label is not None: + self._additional_attributes["label"] = AttrR( + String(), + description="Label from metadata.", + initial_value=label, + ) + super().__init__(search_device_for_attributes=False) def make_sub_fields( @@ -641,7 +648,7 @@ def __init__( super().__init__(panda_name) # We use a raw string for this since many labels won't fit into - # mbbIn fields because of EPICS limitations. + # `mbbIn` fields because of EPICS limitations. # Since this is read only it doesn't matter. self.top_level_attribute = AttrR( String(),