Skip to content

Commit a7b400e

Browse files
committed
fix stuff
1 parent 7eece59 commit a7b400e

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

src/genie_python/genie_epics_api.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ def __init__(
5959
globs: globals
6060
environment_details: details of the computer environment
6161
"""
62-
self.waitfor: WaitForController | None = None # type: WaitForController
62+
self.waitfor: WaitForController | None = None
6363
self.wait_for_move: WaitForMoveController | None = None
64-
self.dae: Dae | None = None # type: Dae
65-
self.blockserver: BlockServer | None = None # type: BlockServer
66-
self.exp_data: GetExperimentData | None = None # type: GetExperimentData
64+
self.dae: Dae | None = None
65+
self.blockserver: BlockServer | None = None
66+
self.exp_data: GetExperimentData | None = None
6767
self.inst_prefix: str = ""
6868
self.instrument_name = ""
6969
self.machine_name = ""
@@ -364,6 +364,26 @@ def set_pv_value(
364364
self.logger.log_error_msg("set_pv_value exception {!r}".format(e))
365365
raise e
366366

367+
@typing.overload
368+
def get_pv_value(
369+
self,
370+
name: str,
371+
to_string: typing.Literal[True] = True,
372+
attempts: int = 3,
373+
is_local: bool = True,
374+
use_numpy: None = None,
375+
) -> str: ...
376+
377+
@typing.overload
378+
def get_pv_value(
379+
self,
380+
name: str,
381+
to_string: bool = False,
382+
attempts: int = 3,
383+
is_local: bool = False,
384+
use_numpy: bool | None = None,
385+
) -> "PVValue": ...
386+
367387
def get_pv_value(
368388
self,
369389
name: str,
@@ -524,7 +544,8 @@ def set_block_value(
524544
full_name = self.get_pv_from_block(name)
525545

526546
if lowlimit is not None and highlimit is not None:
527-
assert isinstance(value, (float, int))
547+
if not isinstance(value, (float, int)):
548+
raise ValueError("Both limits provided but value is not a number")
528549
if lowlimit > highlimit:
529550
print(
530551
"Low limit ({}) higher than high limit ({}), "
@@ -546,7 +567,8 @@ def set_block_value(
546567
self.set_pv_value(full_name, value)
547568

548569
if wait:
549-
assert isinstance(value, WAITFOR_VALUE)
570+
if not isinstance(value, WAITFOR_VALUE):
571+
raise ValueError(f"Wait value is not a WAITFOR_VALUE: {value}")
550572
assert self.waitfor is not None
551573
self.waitfor.start_waiting(name, value, lowlimit, highlimit)
552574
return
@@ -740,19 +762,20 @@ def check_limit_violations(self, blocks: list[str]) -> list[str]:
740762
list: the blocks which have soft limit violations
741763
"""
742764
violation_states = self._get_fields_from_blocks(blocks, "LVIO", "limit violation")
743-
return [t[0] for t in violation_states if t[1] == "1"]
765+
766+
return [t[0] for t in violation_states if typing.cast(bool, t[1]) == 1]
744767

745768
def _get_fields_from_blocks(
746769
self, blocks: list[str], field_name: str, field_description: str
747-
) -> list[str]:
770+
) -> list[tuple[str, "PVValue"]]:
748771
field_values = list()
749772
for block in blocks:
750773
if self.block_exists(block):
751774
block_name = self.correct_blockname(block, False)
752775
full_block_pv = self.get_pv_from_block(block)
753776
try:
754777
field_value = self.get_pv_value(full_block_pv + "." + field_name, attempts=1)
755-
field_values.append([block_name, str(field_value)])
778+
field_values.append((block_name, field_value))
756779
except IOError:
757780
# Could not get value
758781
print("Could not get {} for block: {}".format(field_description, block))
@@ -892,7 +915,6 @@ def get_pv_alarm(self, pv_name: str) -> str:
892915
alarm_val = self.get_pv_value(
893916
"{}.SEVR".format(remove_field_from_pv(pv_name)), to_string=True
894917
)
895-
assert isinstance(alarm_val, str)
896918
return alarm_val
897919

898920
except Exception:

0 commit comments

Comments
 (0)