fix: Fix OPC UA client async security policy setting and handle missing Modbus registers

- OPC UA client: Await set_security_string method call
- Modbus client: Handle case where performance metrics registers might not exist
This commit is contained in:
openhands 2025-11-01 19:59:59 +00:00
parent ac89d72aa9
commit 2bad8c9ea0
1 changed files with 8 additions and 3 deletions

View File

@ -28,7 +28,7 @@ class OPCUAClient:
# Explicitly set security policy to match server configuration # Explicitly set security policy to match server configuration
# The server supports both Basic256Sha256 and None security policies # The server supports both Basic256Sha256 and None security policies
# Use None for development/testing # Use None for development/testing
self._client.set_security_string("http://opcfoundation.org/UA/SecurityPolicy#None") await self._client.set_security_string("http://opcfoundation.org/UA/SecurityPolicy#None")
# Set timeout for connection # Set timeout for connection
await asyncio.wait_for(self._client.connect(), timeout=5.0) await asyncio.wait_for(self._client.connect(), timeout=5.0)
@ -201,8 +201,13 @@ class ModbusClient:
# Read safety status - base address 200 # Read safety status - base address 200
safety_status = self.read_input_register(200 + pump_offset, 1) safety_status = self.read_input_register(200 + pump_offset, 1)
# Read performance metrics - base address 400 # Read performance metrics - base address 400 (if available)
efficiency = None
try:
efficiency = self.read_input_register(400 + pump_offset, 1) efficiency = self.read_input_register(400 + pump_offset, 1)
except Exception:
# Performance metrics might not be available
pass
return { return {
"setpoint": setpoint[0] if setpoint else None, "setpoint": setpoint[0] if setpoint else None,