修复了阀门更新版的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
def set_position(self, position: Union[int, str]):
def set_position(self, command: Union[int, str]):
"""
设置阀门位置
设置阀门位置 - 兼容 SendCmd 类型
Args:
position: 目标位置 (1-8)
command: 目标位置 (1-8) 或位置字符串
"""
try:
pos = int(position)
# 如果是字符串形式的位置,先转换为数字
if isinstance(command, str):
pos = int(command)
else:
pos = int(command)
if pos < 1 or pos > 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"
def set_state(self, state: Union[bool, str]):
def set_state(self, command: Union[bool, str]):
"""
设置阀门状态
设置阀门状态 - 兼容 SendCmd 类型
Args:
state: True/False 或 "open"/"close"
command: True/False 或 "open"/"close"
"""
if isinstance(state, bool):
return self.open() if state else self.close()
elif isinstance(state, str):
if state.lower() in ["open", "on", "true", "1"]:
if isinstance(command, bool):
return self.open() if command else self.close()
elif isinstance(command, str):
if command.lower() in ["open", "on", "true", "1"]:
return self.open()
elif state.lower() in ["close", "closed", "off", "false", "0"]:
elif command.lower() in ["close", "closed", "off", "false", "0"]:
return self.close()
else:
self._status = "Error"
return "Error: Invalid state"
return "Error: Invalid command"
else:
self._status = "Error"
return "Error: Invalid state type"
return "Error: Invalid command type"
def toggle(self):
"""切换阀门状态"""

View File

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