22import logging
33from typing import Union , Dict , Optional
44
5+ from unilabos .registry .decorators import topic_config
6+
57
68class VirtualMultiwayValve :
79 """
@@ -41,13 +43,11 @@ def current_position(self) -> int:
4143 def target_position (self ) -> int :
4244 return self ._target_position
4345
44- def get_current_position (self ) -> int :
45- """获取当前阀门位置 📍"""
46- return self ._current_position
47-
48- def get_current_port (self ) -> str :
49- """获取当前连接的端口名称 🔌"""
50- return self ._current_position
46+ @property
47+ @topic_config ()
48+ def current_port (self ) -> str :
49+ """当前连接的端口名称 🔌"""
50+ return self .port
5151
5252 def set_position (self , command : Union [int , str ]):
5353 """
@@ -169,12 +169,14 @@ def close(self):
169169 self ._status = "Idle"
170170 self ._valve_state = "Closed"
171171
172- close_msg = f"🔒 阀门已关闭,保持在位置 { self ._current_position } ({ self .get_current_port () } )"
172+ close_msg = f"🔒 阀门已关闭,保持在位置 { self ._current_position } ({ self .port } )"
173173 self .logger .info (close_msg )
174174 return close_msg
175175
176- def get_valve_position (self ) -> int :
177- """获取阀门位置 - 兼容性方法 📍"""
176+ @property
177+ @topic_config ()
178+ def valve_position (self ) -> int :
179+ """阀门位置 📍"""
178180 return self ._current_position
179181
180182 def set_valve_position (self , command : Union [int , str ]):
@@ -229,19 +231,16 @@ def switch_between_pump_and_port(self, port_number: int):
229231 self .logger .info (f"🔄 从端口 { self ._current_position } 切换到泵位置..." )
230232 return self .set_to_pump_position ()
231233
232- def get_flow_path (self ) -> str :
233- """获取当前流路路径描述 🌊"""
234- current_port = self .get_current_port ()
234+ @property
235+ @topic_config ()
236+ def flow_path (self ) -> str :
237+ """当前流路路径描述 🌊"""
235238 if self ._current_position == 0 :
236- flow_path = f"🚰 转移泵已连接 (位置 { self ._current_position } )"
237- else :
238- flow_path = f"🔌 端口 { self ._current_position } 已连接 ({ current_port } )"
239-
240- # 删除debug日志:self.logger.debug(f"🌊 当前流路: {flow_path}")
241- return flow_path
239+ return f"🚰 转移泵已连接 (位置 { self ._current_position } )"
240+ return f"🔌 端口 { self ._current_position } 已连接 ({ self .current_port } )"
242241
243242 def __str__ (self ):
244- current_port = self .get_current_port ()
243+ current_port = self .current_port
245244 status_emoji = "✅" if self ._status == "Idle" else "🔄" if self ._status == "Busy" else "❌"
246245
247246 return f"🔄 VirtualMultiwayValve({ status_emoji } 位置: { self ._current_position } /{ self .max_positions } , 端口: { current_port } , 状态: { self ._status } )"
@@ -253,7 +252,7 @@ def __str__(self):
253252
254253 print ("🔄 === 虚拟九通阀门测试 === ✨" )
255254 print (f"🏠 初始状态: { valve } " )
256- print (f"🌊 当前流路: { valve .get_flow_path () } " )
255+ print (f"🌊 当前流路: { valve .flow_path } " )
257256
258257 # 切换到试剂瓶1(1号位)
259258 print (f"\n 🔌 切换到1号位: { valve .set_position (1 )} " )
0 commit comments