Skip to content

Commit e603c51

Browse files
committed
made :LABEL update .EGU
1 parent ee8bb95 commit e603c51

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/fastcs_pandablocks/handlers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from dataclasses import asdict
12
from typing import Any
23

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

3132

3233
class EguSender(Sender):
33-
def __init__(self, attr_to_update: Attribute):
34+
def __init__(self, panda_name: PandaName, attr_to_update: Attribute):
3435
"""Update the attr"""
36+
self.panda_name = panda_name
3537
self.attr_to_update = attr_to_update
3638

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

4146

4247
class CaptureHandler(Handler):

src/fastcs_pandablocks/panda/fields.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,20 @@ def __init__(
126126
initial_values: RawInitialValuesType,
127127
):
128128
super().__init__(panda_name)
129+
130+
units_panda_name = panda_name + PandaName(sub_field="units")
131+
initial_units = initial_values[units_panda_name]
132+
129133
self.top_level_attribute = AttrRW(
130-
Float(),
134+
Float(units=initial_units),
131135
handler=DefaultFieldHandler(panda_name),
132136
description=_strip_description(field_info.description),
133137
group=WidgetGroup.PARAMETERS.value,
134138
initial_value=float(initial_values[panda_name]),
135139
)
136140
self._additional_attributes["units"] = AttrW(
137141
String(),
138-
handler=EguSender(self.top_level_attribute),
142+
handler=EguSender(units_panda_name, self.top_level_attribute),
139143
group=WidgetGroup.PARAMETERS.value,
140144
allowed_values=field_info.units_labels,
141145
)
@@ -149,8 +153,12 @@ def __init__(
149153
initial_values: RawInitialValuesType,
150154
):
151155
super().__init__(panda_name)
156+
157+
units_panda_name = panda_name + PandaName(sub_field="units")
158+
initial_units = initial_values[units_panda_name]
159+
152160
self.top_level_attribute = AttrR(
153-
Float(),
161+
Float(units=initial_units),
154162
handler=DefaultFieldUpdater(
155163
panda_name=panda_name,
156164
),
@@ -160,7 +168,7 @@ def __init__(
160168
)
161169
self._additional_attributes["units"] = AttrW(
162170
String(),
163-
handler=EguSender(self.top_level_attribute),
171+
handler=EguSender(units_panda_name, self.top_level_attribute),
164172
group=WidgetGroup.OUTPUTS.value,
165173
allowed_values=field_info.units_labels,
166174
)
@@ -171,11 +179,15 @@ def __init__(
171179
self,
172180
panda_name: PandaName,
173181
field_info: SubtypeTimeFieldInfo,
174-
initial_value: RawInitialValuesType,
182+
initial_values: RawInitialValuesType,
175183
):
176184
super().__init__(panda_name)
185+
186+
units_panda_name = panda_name + PandaName(sub_field="units")
187+
initial_units = initial_values[units_panda_name]
188+
177189
self.top_level_attribute = AttrW(
178-
Float(),
190+
Float(units=initial_units),
179191
handler=DefaultFieldSender(panda_name),
180192
description=_strip_description(field_info.description),
181193
group=WidgetGroup.OUTPUTS.value,

0 commit comments

Comments
 (0)