修复了阀门更新版的bug

This commit is contained in:
KCFeng425
2025-06-15 13:55:51 +08:00
parent b875f86bbb
commit ff6998501e
3 changed files with 24 additions and 19 deletions

View File

@@ -36,15 +36,20 @@ class VirtualMultiwayValve:
"""获取当前阀门位置""" """获取当前阀门位置"""
return self._current_position return self._current_position
def set_position(self, position: Union[int, str]): def set_position(self, command: Union[int, str]):
""" """
设置阀门位置 设置阀门位置 - 兼容 SendCmd 类型
Args: Args:
position: 目标位置 (1-8) command: 目标位置 (1-8) 或位置字符串
""" """
try: try:
pos = int(position) # 如果是字符串形式的位置,先转换为数字
if isinstance(command, str):
pos = int(command)
else:
pos = int(command)
if pos < 1 or pos > self.max_positions: if pos < 1 or pos > self.max_positions:
raise ValueError(f"Position must be between 1 and {self.max_positions}") raise ValueError(f"Position must be between 1 and {self.max_positions}")

View File

@@ -80,26 +80,26 @@ class VirtualSolenoidValve:
return "Valve closed" return "Valve closed"
def set_state(self, state: Union[bool, str]): def set_state(self, command: Union[bool, str]):
""" """
设置阀门状态 设置阀门状态 - 兼容 SendCmd 类型
Args: Args:
state: True/False 或 "open"/"close" command: True/False 或 "open"/"close"
""" """
if isinstance(state, bool): if isinstance(command, bool):
return self.open() if state else self.close() return self.open() if command else self.close()
elif isinstance(state, str): elif isinstance(command, str):
if state.lower() in ["open", "on", "true", "1"]: if command.lower() in ["open", "on", "true", "1"]:
return self.open() return self.open()
elif state.lower() in ["close", "closed", "off", "false", "0"]: elif command.lower() in ["close", "closed", "off", "false", "0"]:
return self.close() return self.close()
else: else:
self._status = "Error" self._status = "Error"
return "Error: Invalid state" return "Error: Invalid command"
else: else:
self._status = "Error" self._status = "Error"
return "Error: Invalid state type" return "Error: Invalid command type"
def toggle(self): def toggle(self):
"""切换阀门状态""" """切换阀门状态"""

View File

@@ -185,7 +185,7 @@ virtual_multiway_valve:
set_position: set_position:
type: SendCmd type: SendCmd
goal: goal:
position: position command: position
feedback: {} feedback: {}
result: result:
success: success success: success
@@ -267,7 +267,7 @@ virtual_solenoid_valve:
status_types: status_types:
status: String status: String
valve_state: String # "open" or "closed" valve_state: String # "open" or "closed"
is_open: Boolean is_open: Bool
action_value_mappings: action_value_mappings:
open: open:
type: EmptyIn type: EmptyIn
@@ -282,9 +282,9 @@ virtual_solenoid_valve:
result: result:
success: success success: success
set_state: set_state:
type: BoolSingleInput type: SendCmd
goal: goal:
state: state command: command
feedback: {} feedback: {}
result: result:
success: success success: success