Skip to content

Commit 639ab86

Browse files
authored
Merge pull request #25 from ISISComputingGroup/24
Default to None rather than empty string
2 parents 62d51bd + 192800a commit 639ab86

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

src/genie_python/genie.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,9 +859,9 @@ def connected_pvs_in_list(pv_list: list[str], is_local: bool = False) -> list[st
859859
def begin(
860860
period: int = 1,
861861
meas_id: str | None = None,
862-
meas_type: str = "",
863-
meas_subid: str = "",
864-
sample_id: str = "",
862+
meas_type: str | None = None,
863+
meas_subid: str | None = None,
864+
sample_id: str | None = None,
865865
delayed: bool = False,
866866
quiet: bool = False,
867867
paused: bool = False,

src/genie_python/genie_epics_api.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def __init__(
7777
self.motion_suffix = "CS:MOT:MOVING"
7878
self.pre_post_cmd_manager = PrePostCmdManager()
7979
self.logger = GenieLogger()
80+
self._sample_par_names_cache = None
81+
self._beamline_par_names_cache = None
8082

8183
if environment_details is None:
8284
self._environment_details = EnvironmentDetails()
@@ -680,19 +682,21 @@ def set_sample_par(self, name: str, value: "PVValue") -> None:
680682
name: the name of the parameter to change
681683
value: the new value
682684
"""
685+
683686
assert self.blockserver is not None
684-
names = self.blockserver.get_sample_par_names()
685-
if (
686-
names is not None
687-
and isinstance(names, list)
688-
and all(isinstance(elem, str) for elem in names)
689-
):
687+
try:
688+
names = self.blockserver.get_sample_par_names()
689+
self._sample_par_names_cache = names
690+
except Exception:
691+
names = self._sample_par_names_cache
692+
if names is not None and isinstance(names, list):
690693
for n in names:
691-
m = re.match(".+:SAMPLE:%s" % name.upper(), n)
692-
if m is not None:
693-
# Found it!
694-
self.set_pv_value(self.prefix_pv_name(n), value)
695-
return
694+
if isinstance(n, str):
695+
m = re.match(".+:SAMPLE:%s" % name.upper(), n)
696+
if m is not None:
697+
# Found it!
698+
self.set_pv_value(self.prefix_pv_name(n), value)
699+
return
696700
raise Exception("Sample parameter %s does not exist" % name)
697701

698702
def get_beamline_pars(self) -> "_GetbeamlineparsReturn":
@@ -712,8 +716,14 @@ def set_beamline_par(self, name: str, value: "PVValue") -> None:
712716
name: the name of the parameter to change
713717
value: the new value
714718
"""
719+
715720
assert self.blockserver is not None
716-
names = self.blockserver.get_beamline_par_names()
721+
try:
722+
names = self.blockserver.get_beamline_par_names()
723+
self._beamline_par_names_cache = names
724+
except Exception:
725+
names = self._beamline_par_names_cache
726+
717727
if names is not None:
718728
for n in names:
719729
m = re.match(".+:BL:%s" % name.upper(), n)

0 commit comments

Comments
 (0)