@@ -73,8 +73,8 @@ def __init__(self, name: str = ""):
7373 self .graph = nx .MultiDiGraph ()
7474
7575 # Stores the valve / connection mappings
76- self ._valve_map : Dict [Component , Connection ] = {}
77- self ._valve_type_map : Dict [Component , ValveType ] = {}
76+ self ._valve_map : Dict [str , Connection ] = {}
77+ self ._valve_type_map : Dict [str , ValveType ] = {}
7878
7979 @property
8080 def xspan (self ) -> Optional [int ]:
@@ -129,7 +129,9 @@ def valves(self) -> List[Component]:
129129 Returns:
130130 List[Component]: List of valve components in the device
131131 """
132- return list (self ._valve_map .keys ())
132+ # Retrieve the list of
133+ valve_ids = list (self ._valve_map .keys ())
134+ return [self .get_component (valve_id ) for valve_id in valve_ids ]
133135
134136 def map_valve (
135137 self ,
@@ -145,17 +147,8 @@ def map_valve(
145147 type_info (Optional[ValveType]): Type informaiton of the valve
146148
147149 """
148- self ._valve_map [valve ] = connection
149- if type_info is not None :
150- self .update_valve_type (valve , type_info )
151-
152- def get_valves (self ) -> List [Component ]:
153- """Returns the list of valves in the device
154-
155- Returns:
156- List[Component]: Valve Component Objects
157- """
158- return list (self ._valve_map .keys ())
150+ self ._valve_map [valve .ID ] = connection
151+ self .update_valve_type (valve , type_info )
159152
160153 def get_valve_connection (self , valve : Component ) -> Connection :
161154 """Returns the connection associated with the valve object
@@ -166,7 +159,7 @@ def get_valve_connection(self, valve: Component) -> Connection:
166159 Returns:
167160 Connection: connection object on which the valve is placed
168161 """
169- return self ._valve_map [valve ]
162+ return self ._valve_map [valve . ID ]
170163
171164 def update_valve_type (self , valve : Component , type_info : ValveType ) -> None :
172165 """Updates the type of the valve to normally closed or normally open
@@ -178,8 +171,8 @@ def update_valve_type(self, valve: Component, type_info: ValveType) -> None:
178171 Raises:
179172 KeyError: Raises the error if the valve object is not mapped as a valve in the device
180173 """
181- if valve in self ._valve_map :
182- self ._valve_type_map [valve ] = type_info
174+ if valve . ID in self ._valve_map . keys () :
175+ self ._valve_type_map [valve . ID ] = type_info
183176 else :
184177 raise KeyError (
185178 "Could not update type for valve: {} since it is not found in the valveMap of they device" .format (
@@ -195,8 +188,8 @@ def remove_valve(self, valve_id) -> None:
195188 """
196189 for valve in self .valves :
197190 if valve .ID == valve_id :
198- self ._valve_map .pop (valve )
199- self ._valve_type_map .pop (valve )
191+ self ._valve_map .pop (valve . ID )
192+ self ._valve_type_map .pop (valve . ID )
200193 break
201194
202195 self .remove_component (valve_id )
@@ -637,11 +630,13 @@ def to_parchmint_v1_2(self) -> Dict:
637630
638631 # Add the valvemap information
639632 valve_objects = []
640- for valve , connection in self ._valve_map .items ():
633+ for valve_id , connection in self ._valve_map .items ():
634+ if valve_id not in self ._valve_type_map :
635+ raise Exception (f"Could not find type info for valve id: { valve_id } " )
641636 valve_object = {
642- "componentid" : valve . ID ,
637+ "componentid" : valve_id ,
643638 "connectionid" : connection .ID ,
644- "type" : str (self ._valve_type_map [valve ]),
639+ "type" : str (self ._valve_type_map [valve_id ]),
645640 }
646641 valve_objects .append (valve_object )
647642 ret ["valves" ] = valve_objects
0 commit comments