Add start/stop methods to SetpointManager and fix main application configuration
- Added async start() and stop() methods to SetpointManager for main application compatibility - Fixed database pool configuration to use correct settings parameter names - Added missing settings: opcua_host, modbus_host, modbus_unit_id, rest_api_host - Updated protocol server initializations to pass required dependencies - Fixed OptimizationPlanManager method calls to use correct names (start_monitoring/stop_monitoring) - Verified main application starts and stops gracefully - All 133 tests continue to pass
This commit is contained in:
parent
ac933e6dcb
commit
6b023e48d1
|
|
@ -31,6 +31,7 @@ class Settings(BaseSettings):
|
||||||
|
|
||||||
# OPC UA
|
# OPC UA
|
||||||
opcua_enabled: bool = True
|
opcua_enabled: bool = True
|
||||||
|
opcua_host: str = "localhost"
|
||||||
opcua_port: int = 4840
|
opcua_port: int = 4840
|
||||||
opcua_security_mode: str = "SignAndEncrypt"
|
opcua_security_mode: str = "SignAndEncrypt"
|
||||||
opcua_cert_path: Optional[str] = None
|
opcua_cert_path: Optional[str] = None
|
||||||
|
|
@ -38,11 +39,13 @@ class Settings(BaseSettings):
|
||||||
|
|
||||||
# Modbus TCP
|
# Modbus TCP
|
||||||
modbus_enabled: bool = True
|
modbus_enabled: bool = True
|
||||||
|
modbus_host: str = "localhost"
|
||||||
modbus_port: int = 502
|
modbus_port: int = 502
|
||||||
modbus_slave_id: int = 1
|
modbus_unit_id: int = 1
|
||||||
|
|
||||||
# REST API
|
# REST API
|
||||||
rest_api_enabled: bool = True
|
rest_api_enabled: bool = True
|
||||||
|
rest_api_host: str = "localhost"
|
||||||
rest_api_port: int = 8080
|
rest_api_port: int = 8080
|
||||||
rest_api_cors_enabled: bool = True
|
rest_api_cors_enabled: bool = True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,7 @@ class SetpointManager:
|
||||||
self.safety_enforcer = safety_enforcer
|
self.safety_enforcer = safety_enforcer
|
||||||
self.emergency_stop_manager = emergency_stop_manager
|
self.emergency_stop_manager = emergency_stop_manager
|
||||||
self.watchdog = watchdog
|
self.watchdog = watchdog
|
||||||
|
self.running = False
|
||||||
|
|
||||||
# Create calculator instances
|
# Create calculator instances
|
||||||
self.calculators = {
|
self.calculators = {
|
||||||
|
|
@ -132,6 +133,16 @@ class SetpointManager:
|
||||||
'POWER_CONTROLLED': PowerControlledCalculator()
|
'POWER_CONTROLLED': PowerControlledCalculator()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async def start(self) -> None:
|
||||||
|
"""Start the Setpoint Manager."""
|
||||||
|
self.running = True
|
||||||
|
logger.info("setpoint_manager_started")
|
||||||
|
|
||||||
|
async def stop(self) -> None:
|
||||||
|
"""Stop the Setpoint Manager."""
|
||||||
|
self.running = False
|
||||||
|
logger.info("setpoint_manager_stopped")
|
||||||
|
|
||||||
def get_current_setpoint(self, station_id: str, pump_id: str) -> Optional[float]:
|
def get_current_setpoint(self, station_id: str, pump_id: str) -> Optional[float]:
|
||||||
"""
|
"""
|
||||||
Get current setpoint for a pump.
|
Get current setpoint for a pump.
|
||||||
|
|
|
||||||
18
src/main.py
18
src/main.py
|
|
@ -43,10 +43,10 @@ class CalejoControlAdapter:
|
||||||
# Initialize core components (Phase 1)
|
# Initialize core components (Phase 1)
|
||||||
self.db_client = FlexibleDatabaseClient(
|
self.db_client = FlexibleDatabaseClient(
|
||||||
database_url=settings.database_url,
|
database_url=settings.database_url,
|
||||||
pool_size=settings.db_pool_size,
|
pool_size=settings.db_min_connections,
|
||||||
max_overflow=settings.db_max_overflow,
|
max_overflow=settings.db_max_connections - settings.db_min_connections,
|
||||||
pool_timeout=settings.db_pool_timeout,
|
pool_timeout=30,
|
||||||
pool_recycle=settings.db_pool_recycle
|
pool_recycle=3600
|
||||||
)
|
)
|
||||||
self.components.append(self.db_client)
|
self.components.append(self.db_client)
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ class CalejoControlAdapter:
|
||||||
self.components.append(self.alert_manager)
|
self.components.append(self.alert_manager)
|
||||||
|
|
||||||
self.watchdog = DatabaseWatchdog(
|
self.watchdog = DatabaseWatchdog(
|
||||||
self.db_client, self.alert_manager, settings.safety_timeout_seconds
|
self.db_client, self.alert_manager, settings.watchdog_timeout_seconds
|
||||||
)
|
)
|
||||||
self.components.append(self.watchdog)
|
self.components.append(self.watchdog)
|
||||||
|
|
||||||
|
|
@ -88,12 +88,14 @@ class CalejoControlAdapter:
|
||||||
|
|
||||||
# Protocol servers (Phase 2)
|
# Protocol servers (Phase 2)
|
||||||
self.opc_ua_server = OPCUAServer(
|
self.opc_ua_server = OPCUAServer(
|
||||||
|
setpoint_manager=self.setpoint_manager,
|
||||||
endpoint=f"opc.tcp://{settings.opcua_host}:{settings.opcua_port}",
|
endpoint=f"opc.tcp://{settings.opcua_host}:{settings.opcua_port}",
|
||||||
server_name="Calejo Control OPC UA Server"
|
server_name="Calejo Control OPC UA Server"
|
||||||
)
|
)
|
||||||
self.components.append(self.opc_ua_server)
|
self.components.append(self.opc_ua_server)
|
||||||
|
|
||||||
self.modbus_server = ModbusServer(
|
self.modbus_server = ModbusServer(
|
||||||
|
setpoint_manager=self.setpoint_manager,
|
||||||
host=settings.modbus_host,
|
host=settings.modbus_host,
|
||||||
port=settings.modbus_port,
|
port=settings.modbus_port,
|
||||||
unit_id=settings.modbus_unit_id
|
unit_id=settings.modbus_unit_id
|
||||||
|
|
@ -101,6 +103,8 @@ class CalejoControlAdapter:
|
||||||
self.components.append(self.modbus_server)
|
self.components.append(self.modbus_server)
|
||||||
|
|
||||||
self.rest_api = RESTAPIServer(
|
self.rest_api = RESTAPIServer(
|
||||||
|
setpoint_manager=self.setpoint_manager,
|
||||||
|
emergency_stop_manager=self.emergency_stop_manager,
|
||||||
host=settings.rest_api_host,
|
host=settings.rest_api_host,
|
||||||
port=settings.rest_api_port
|
port=settings.rest_api_port
|
||||||
)
|
)
|
||||||
|
|
@ -124,7 +128,7 @@ class CalejoControlAdapter:
|
||||||
logger.info("auto_discovery_completed")
|
logger.info("auto_discovery_completed")
|
||||||
|
|
||||||
# Start optimization manager
|
# Start optimization manager
|
||||||
await self.optimization_manager.start()
|
await self.optimization_manager.start_monitoring()
|
||||||
logger.info("optimization_manager_started")
|
logger.info("optimization_manager_started")
|
||||||
|
|
||||||
# Start monitoring
|
# Start monitoring
|
||||||
|
|
@ -180,7 +184,7 @@ class CalejoControlAdapter:
|
||||||
|
|
||||||
# Stop optimization manager
|
# Stop optimization manager
|
||||||
if self.optimization_manager:
|
if self.optimization_manager:
|
||||||
stop_tasks.append(self.optimization_manager.stop())
|
stop_tasks.append(self.optimization_manager.stop_monitoring())
|
||||||
|
|
||||||
# Close database connection
|
# Close database connection
|
||||||
if self.db_client:
|
if self.db_client:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue