1
1
from collections .abc import Generator
2
2
3
- from fastcs .attributes import AttrR , AttrRW , AttrW
3
+ from fastcs .attributes import Attribute , AttrR , AttrRW , AttrW
4
4
from fastcs .controller import SubController
5
5
from pandablocks .responses import BlockInfo
6
6
7
- from fastcs_pandablocks .types import AttrType , EpicsName , PandaName , ResponseType
7
+ from fastcs_pandablocks .types import EpicsName , PandaName , ResponseType
8
8
9
- from .fields import FIELD_TYPE_TO_FASTCS_TYPE , FieldType
9
+ from .fields import FieldControllerType , get_field_controller_from_field_info
10
10
11
11
12
12
class BlockController (SubController ):
13
- fields : dict [str , FieldType ]
13
+ fields : dict [str , FieldControllerType ]
14
14
15
15
def __init__ (
16
16
self ,
@@ -19,30 +19,31 @@ def __init__(
19
19
description : str | None | None ,
20
20
raw_fields : dict [str , ResponseType ],
21
21
):
22
- super (). __init__ ()
22
+ self . _additional_attributes : dict [ str , Attribute ] = {}
23
23
self .panda_name = panda_name
24
24
self .number = number
25
25
self .description = description
26
26
self .fields = {}
27
27
28
28
for field_raw_name , field_info in raw_fields .items ():
29
- field_panda_name = self .panda_name + PandaName (field = field_raw_name )
29
+ field_panda_name = PandaName (field = field_raw_name )
30
+ field = get_field_controller_from_field_info (field_info )
31
+ self .fields [field_panda_name .attribute_name ] = field
30
32
31
- field = FIELD_TYPE_TO_FASTCS_TYPE [field_info .type ][field_info .subtype ](
32
- # TODO make type safe after match statment
33
- field_panda_name ,
34
- field_info , # type: ignore
35
- )
36
- self .fields [field_raw_name ] = field
33
+ super ().__init__ ()
37
34
38
35
def initialise (self ):
39
36
for field_name , field in self .fields .items ():
40
- if field .named_attribute :
41
- setattr (self , * field .named_attribute )
42
- if field .sub_field_controller :
43
- self .register_sub_controller (
44
- field_name , sub_controller = field .sub_field_controller
45
- )
37
+ if field .additional_attributes :
38
+ self .register_sub_controller (field_name , sub_controller = field )
39
+ if field .top_level_attribute :
40
+ self ._additional_attributes [field_name ] = field .top_level_attribute
41
+
42
+ field .initialise ()
43
+
44
+ @property
45
+ def additional_attributes (self ) -> dict [str , Attribute ]:
46
+ return self ._additional_attributes
46
47
47
48
48
49
class Blocks :
@@ -97,8 +98,8 @@ def flattened_attribute_tree(
97
98
yield (block .panda_name .attribute_name , block )
98
99
99
100
def __getitem__ (
100
- self , name : EpicsName | PandaName
101
- ) -> dict [int | None , BlockController ] | BlockController | AttrType :
101
+ self , name : PandaName
102
+ ) -> dict [int | None , BlockController ] | BlockController | Attribute :
102
103
if name .block is None :
103
104
raise ValueError (f"Cannot find block for name { name } ." )
104
105
blocks = self ._blocks [name .block ]
@@ -109,8 +110,7 @@ def __getitem__(
109
110
return block
110
111
field = block .fields [name .field ]
111
112
if not name .sub_field :
112
- assert field .named_attribute
113
- return field .named_attribute . attribute
113
+ assert field .top_level_attribute
114
+ return field .top_level_attribute
114
115
115
- sub_field = getattr (field .sub_field_controller , name .sub_field )
116
- return sub_field
116
+ return field .additional_attributes [name .sub_field ]
0 commit comments