feat: Implement configurable pump control preprocessing logic #5
|
|
@ -1105,23 +1105,23 @@ async def apply_discovery_results(scan_id: str, station_id: str, pump_id: str, d
|
|||
if not result:
|
||||
raise HTTPException(status_code=404, detail=f"Discovery scan {scan_id} not found")
|
||||
|
||||
if result.status != DiscoveryStatus.COMPLETED:
|
||||
if result.get("status") != "completed":
|
||||
raise HTTPException(status_code=400, detail="Cannot apply incomplete discovery scan")
|
||||
|
||||
created_mappings = []
|
||||
errors = []
|
||||
|
||||
for endpoint in result.discovered_endpoints:
|
||||
for endpoint in result.get("discovered_endpoints", []):
|
||||
try:
|
||||
# Create protocol mapping from discovered endpoint
|
||||
mapping_id = f"{endpoint.device_id}_{data_type}"
|
||||
mapping_id = f"{endpoint.get('device_id')}_{data_type}"
|
||||
|
||||
protocol_mapping = ProtocolMapping(
|
||||
id=mapping_id,
|
||||
station_id=station_id,
|
||||
pump_id=pump_id,
|
||||
protocol_type=endpoint.protocol_type,
|
||||
protocol_address=endpoint.address,
|
||||
protocol_type=endpoint.get("protocol_type"),
|
||||
protocol_address=endpoint.get("address"),
|
||||
data_type=data_type,
|
||||
db_source=db_source
|
||||
)
|
||||
|
|
@ -1132,10 +1132,10 @@ async def apply_discovery_results(scan_id: str, station_id: str, pump_id: str, d
|
|||
if success:
|
||||
created_mappings.append(mapping_id)
|
||||
else:
|
||||
errors.append(f"Failed to create mapping for {endpoint.device_name}")
|
||||
errors.append(f"Failed to create mapping for {endpoint.get('device_name')}")
|
||||
|
||||
except Exception as e:
|
||||
errors.append(f"Error creating mapping for {endpoint.device_name}: {str(e)}")
|
||||
errors.append(f"Error creating mapping for {endpoint.get('device_name')}: {str(e)}")
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
|
|
|
|||
|
|
@ -97,9 +97,9 @@ class PersistentProtocolDiscoveryService:
|
|||
for row in result
|
||||
]
|
||||
|
||||
# Get total discovered endpoints
|
||||
# Get total discovered endpoints (count unique endpoints across all scans)
|
||||
query = text("""
|
||||
SELECT COUNT(*)
|
||||
SELECT COUNT(DISTINCT endpoint->>'device_id')
|
||||
FROM discovery_results dr,
|
||||
jsonb_array_elements(dr.discovered_endpoints) AS endpoint
|
||||
WHERE dr.status = 'completed'
|
||||
|
|
|
|||
Loading…
Reference in New Issue