SIENTIAPDE-1110

SIENTIAPDE-1110 Refactor OPC activity to use server IDs instead of names, update values.yaml for OPC_ID, and enhance OpcRepository initialization for improved clarity and consistency.
This commit is contained in:
vitor-aignosi
2025-06-27 10:37:06 -03:00
parent 82356ca3b0
commit ce69b0839f
4 changed files with 24 additions and 24 deletions

View File

@@ -35,12 +35,12 @@ data_type_map = {
class OpcRepository():
def __init__(self, name: str, url: str, logger: Logger,
def __init__(self, id: str, url: str, logger: Logger,
notification_handler: NotificationHandler,
reconnection_interval: int = 60, server_uri: str = None, cert_path: str = None,
private_key_path: str = None, server_cert_path: str = None):
self.url = url
self.name = name
self.id = id
self.server_uri = server_uri
self.cert_path = cert_path
self.private_key_path = private_key_path
@@ -121,7 +121,7 @@ class OpcRepository():
except Exception as e:
trace = traceback.format_exc()
self.notification_handler.build_and_send_notification(
notification_id=f"OPC_CONNECTION_ERROR_{self.name}",
notification_id=f"OPC_CONNECTION_ERROR_{self.id}",
message=f"Failed to connect to OPC server: {e}",
block="opc_repository",
level=NotificationLevel.ERROR,
@@ -165,7 +165,7 @@ class OpcRepository():
if self.error_count > 5:
self.logger.warning(
f"OPC server {self.name} will be disconnected due to multiple errors")
f"OPC server {self.id} will be disconnected due to multiple errors")
try:
self.disconnect()
except Exception as e:
@@ -173,7 +173,7 @@ class OpcRepository():
self.logger.error(f"Failed to disconnect from OPC server: {e}")
self.logger.error(trace)
self.logger.info(
f"Attempting to reconnect to OPC server {self.name}...")
f"Attempting to reconnect to OPC server {self.id}...")
return self.connect()
if hasattr(self.client, 'aio_obj') and self.client.aio_obj.uaclient.protocol is None or \
@@ -181,11 +181,11 @@ class OpcRepository():
self.client.aio_obj.uaclient.protocol.state == "closed"):
self.logger.error(
f"OPC server {self.name} is not connected")
f"OPC server {self.id} is not connected")
if (datetime.now() - self.last_reconnection_time).total_seconds(
) > self.reconnection_interval:
self.logger.error(
f"Trying to reconnect to OPC server {self.name}...")
f"Trying to reconnect to OPC server {self.id}...")
return self.try_connect()
return False
@@ -210,7 +210,7 @@ class OpcRepository():
except Exception as e:
trace = traceback.format_exc()
self.notification_handler.build_and_send_notification(
notification_id=f"OPC_WRITE_GET_NODE_ERROR_{self.name}",
notification_id=f"OPC_WRITE_GET_NODE_ERROR_{self.id}",
message=f"Failed to get node from OPC server: {e}",
block="opc_repository",
level=NotificationLevel.ERROR,
@@ -222,7 +222,7 @@ class OpcRepository():
if data_type not in data_type_map:
self.notification_handler.build_and_send_notification(
notification_id=f"OPC_WRITE_DATA_TYPE_ERROR_{self.name}",
notification_id=f"OPC_WRITE_DATA_TYPE_ERROR_{self.id}",
message=f"Unsupported data type: {data_type}",
block="opc_repository",
level=NotificationLevel.ERROR
@@ -239,7 +239,7 @@ class OpcRepository():
except Exception as e:
trace = traceback.format_exc()
self.notification_handler.build_and_send_notification(
notification_id=f"OPC_WRITE_DATA_ERROR_{self.name}",
notification_id=f"OPC_WRITE_DATA_ERROR_{self.id}",
message=f"Failed to write data to OPC server: {e}",
block="opc_repository",
level=NotificationLevel.ERROR,