Skip to content

Commit

Permalink
made :LABEL update .EGU
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Nov 13, 2024
1 parent ee8bb95 commit e603c51
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/fastcs_pandablocks/handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dataclasses import asdict
from typing import Any

from fastcs.attributes import Attribute, AttrR, AttrW, Handler, Sender, Updater
Expand Down Expand Up @@ -30,13 +31,17 @@ def __init__(self, panda_name: PandaName):


class EguSender(Sender):
def __init__(self, attr_to_update: Attribute):
def __init__(self, panda_name: PandaName, attr_to_update: Attribute):
"""Update the attr"""
self.panda_name = panda_name
self.attr_to_update = attr_to_update

async def put(self, controller: Any, attr: AttrW, value: str) -> None:
# TODO find out how to update attr_to_update's EGU with the value
...
await controller.put_value_to_panda(self.panda_name, value)
kwargs = asdict(self.attr_to_update.datatype)
kwargs["units"] = value
new_attribute_datatype = type(self.attr_to_update.datatype)(**kwargs)
self.attr_to_update.update_datatype(new_attribute_datatype)


class CaptureHandler(Handler):
Expand Down
24 changes: 18 additions & 6 deletions src/fastcs_pandablocks/panda/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,20 @@ def __init__(
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)

units_panda_name = panda_name + PandaName(sub_field="units")
initial_units = initial_values[units_panda_name]

self.top_level_attribute = AttrRW(
Float(),
Float(units=initial_units),
handler=DefaultFieldHandler(panda_name),
description=_strip_description(field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=float(initial_values[panda_name]),
)
self._additional_attributes["units"] = AttrW(
String(),
handler=EguSender(self.top_level_attribute),
handler=EguSender(units_panda_name, self.top_level_attribute),
group=WidgetGroup.PARAMETERS.value,
allowed_values=field_info.units_labels,
)
Expand All @@ -149,8 +153,12 @@ def __init__(
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)

units_panda_name = panda_name + PandaName(sub_field="units")
initial_units = initial_values[units_panda_name]

self.top_level_attribute = AttrR(
Float(),
Float(units=initial_units),
handler=DefaultFieldUpdater(
panda_name=panda_name,
),
Expand All @@ -160,7 +168,7 @@ def __init__(
)
self._additional_attributes["units"] = AttrW(
String(),
handler=EguSender(self.top_level_attribute),
handler=EguSender(units_panda_name, self.top_level_attribute),
group=WidgetGroup.OUTPUTS.value,
allowed_values=field_info.units_labels,
)
Expand All @@ -171,11 +179,15 @@ def __init__(
self,
panda_name: PandaName,
field_info: SubtypeTimeFieldInfo,
initial_value: RawInitialValuesType,
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)

units_panda_name = panda_name + PandaName(sub_field="units")
initial_units = initial_values[units_panda_name]

self.top_level_attribute = AttrW(
Float(),
Float(units=initial_units),
handler=DefaultFieldSender(panda_name),
description=_strip_description(field_info.description),
group=WidgetGroup.OUTPUTS.value,
Expand Down

0 comments on commit e603c51

Please sign in to comment.