Skip to content

Commit 7f2d733

Browse files
committed
Check if device.set_value is async before calling
Some devices need awaiting and some dont
1 parent 1d50128 commit 7f2d733

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/pytac/data_source.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ async def get_value(self, field, handle, throw=True):
338338
FieldException: if the device does not have the specified field.
339339
"""
340340
device = self.get_device(field)
341-
# TODO some devices dont need to be awaited as they are just retrieving stored data,
342-
# but other get data from PVs so do, make this better
341+
# TODO some devices dont need to be awaited as they are just retrieving stored
342+
# data, but others get data from PVs so do, make this better
343343
val = 0
344344
if inspect.iscoroutinefunction(device.get_value):
345345
val = await device.get_value(handle, throw)
@@ -360,4 +360,10 @@ async def set_value(self, field, value, throw=True):
360360
Raises:
361361
FieldException: if the device does not have the specified field.
362362
"""
363-
await self.get_device(field).set_value(value, throw)
363+
device = self.get_device(field)
364+
# TODO some devices dont need to be awaited as they are just setting local
365+
# data, but others set data to PVs, so do, make this better
366+
if inspect.iscoroutinefunction(device.set_value):
367+
await device.set_value(value, throw)
368+
else:
369+
device.set_value(value, throw)

0 commit comments

Comments
 (0)