2
2
3
3
import time
4
4
from builtins import object
5
+ from typing import TYPE_CHECKING , Any , Callable , ParamSpec , TypeVar
5
6
6
7
from genie_python .utilities import compress_and_hex , dehex_decompress_and_dejson
7
8
9
+ if TYPE_CHECKING :
10
+ from genie_python .genie import PVValue
11
+ from genie_python .genie_epics_api import API
12
+
13
+ Param = ParamSpec ("Param" )
14
+ RetType = TypeVar ("RetType" )
15
+
8
16
# Prefix for block server pvs
9
17
PV_BLOCK_NAMES = "BLOCKNAMES"
10
18
BLOCK_SERVER_PREFIX = "CS:BLOCKSERVER:"
11
19
12
20
13
- def _blockserver_retry (func ) :
14
- def wrapper (* args , ** kwargs ) :
21
+ def _blockserver_retry (func : Callable [ Param , RetType ]) -> Callable [ Param , RetType ] :
22
+ def wrapper (* args : Param . args , ** kwargs : Param . kwargs ) -> RetType :
15
23
while True :
16
24
try :
17
25
return func (* args , ** kwargs )
@@ -27,38 +35,38 @@ def wrapper(*args, **kwargs):
27
35
28
36
29
37
class BlockServer (object ):
30
- def __init__ (self , api ) :
31
- self .api = api
38
+ def __init__ (self , api : "API" ) -> None :
39
+ self .api : "API" = api
32
40
33
- def _get_pv_value (self , pv , as_string = False ):
41
+ def _get_pv_value (self , pv : str , as_string : bool = False ) -> "PVValue" :
34
42
"""Just a convenient wrapper for calling the api's get_pv_value method"""
35
43
return self .api .get_pv_value (self .api .prefix_pv_name (pv ), as_string )
36
44
37
- def _set_pv_value (self , pv , value , wait = False ):
45
+ def _set_pv_value (self , pv : str , value : "PVValue | bytes" , wait : bool = False ) -> None :
38
46
"""Just a convenient wrapper for calling the api's set_pv_value method"""
39
47
return self .api .set_pv_value (self .api .prefix_pv_name (pv ), value , wait )
40
48
41
49
@_blockserver_retry
42
- def get_sample_par_names (self ):
50
+ def get_sample_par_names (self ) -> Any : # noqa: ANN401
43
51
"""Get the current sample parameter names as a list."""
44
52
# Get the names from the blockserver
45
53
raw = self ._get_pv_value (BLOCK_SERVER_PREFIX + "SAMPLE_PARS" , True )
46
54
return dehex_decompress_and_dejson (raw )
47
55
48
56
@_blockserver_retry
49
- def get_beamline_par_names (self ):
57
+ def get_beamline_par_names (self ) -> Any : # noqa: ANN401
50
58
"""Get the current beamline parameter names as a list."""
51
59
# Get the names from the blockserver
52
60
raw = self ._get_pv_value (BLOCK_SERVER_PREFIX + "BEAMLINE_PARS" , True )
53
61
return dehex_decompress_and_dejson (raw )
54
62
55
63
@_blockserver_retry
56
- def get_runcontrol_settings (self ):
64
+ def get_runcontrol_settings (self ) -> Any : # noqa: ANN401
57
65
"""Get the current run-control settings."""
58
66
raw = self ._get_pv_value (BLOCK_SERVER_PREFIX + "GET_RC_PARS" , True )
59
67
return dehex_decompress_and_dejson (raw )
60
68
61
- def reload_current_config (self ):
69
+ def reload_current_config (self ) -> None :
62
70
"""Reload the current configuration."""
63
71
raw = compress_and_hex ("1" )
64
72
self ._set_pv_value (BLOCK_SERVER_PREFIX + "RELOAD_CURRENT_CONFIG" , raw , True )
0 commit comments