Add whatsapp feature
This commit is contained in:
@@ -8,7 +8,31 @@ from typing import Optional, List
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from app.models.production import EquipmentType, EquipmentStatus
|
||||
from app.models.production import EquipmentType, EquipmentStatus, IoTProtocol, IoTConnectionStatus
|
||||
|
||||
|
||||
class IoTConnectionConfig(BaseModel):
|
||||
"""Schema for IoT connection configuration"""
|
||||
protocol: str = Field(..., description="IoT protocol (rest_api, opc_ua, mqtt, modbus, custom)")
|
||||
endpoint: str = Field(..., description="Connection endpoint (URL or IP address)")
|
||||
port: Optional[int] = Field(None, description="Connection port")
|
||||
username: Optional[str] = Field(None, description="Username for authentication")
|
||||
password: Optional[str] = Field(None, description="Password for authentication")
|
||||
api_key: Optional[str] = Field(None, description="API key for authentication")
|
||||
token: Optional[str] = Field(None, description="Authentication token")
|
||||
additional_config: Optional[dict] = Field(None, description="Additional protocol-specific configuration")
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"protocol": "rest_api",
|
||||
"endpoint": "https://connectedcooking.com/api/v1",
|
||||
"port": 443,
|
||||
"api_key": "your-api-key-here",
|
||||
"additional_config": {"poll_interval": 30}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class EquipmentCreate(BaseModel):
|
||||
@@ -18,6 +42,8 @@ class EquipmentCreate(BaseModel):
|
||||
model: Optional[str] = Field(None, max_length=100, description="Equipment model")
|
||||
serial_number: Optional[str] = Field(None, max_length=100, description="Serial number")
|
||||
location: Optional[str] = Field(None, max_length=255, description="Physical location")
|
||||
manufacturer: Optional[str] = Field(None, max_length=100, description="Manufacturer")
|
||||
firmware_version: Optional[str] = Field(None, max_length=50, description="Firmware version")
|
||||
status: EquipmentStatus = Field(default=EquipmentStatus.OPERATIONAL, description="Equipment status")
|
||||
|
||||
# Installation and maintenance
|
||||
@@ -40,6 +66,23 @@ class EquipmentCreate(BaseModel):
|
||||
current_temperature: Optional[float] = Field(None, description="Current temperature")
|
||||
target_temperature: Optional[float] = Field(None, description="Target temperature")
|
||||
|
||||
# IoT Connectivity
|
||||
iot_enabled: bool = Field(default=False, description="Enable IoT connectivity")
|
||||
iot_protocol: Optional[str] = Field(None, description="IoT protocol")
|
||||
iot_endpoint: Optional[str] = Field(None, description="IoT endpoint URL or IP")
|
||||
iot_port: Optional[int] = Field(None, description="IoT connection port")
|
||||
iot_config: Optional[dict] = Field(None, description="IoT configuration")
|
||||
|
||||
# Real-time monitoring
|
||||
supports_realtime: bool = Field(default=False, description="Supports real-time monitoring")
|
||||
poll_interval_seconds: Optional[int] = Field(None, ge=1, description="Polling interval in seconds")
|
||||
|
||||
# Sensor capabilities
|
||||
temperature_zones: Optional[int] = Field(None, ge=1, description="Number of temperature zones")
|
||||
supports_humidity: bool = Field(default=False, description="Supports humidity monitoring")
|
||||
supports_energy_monitoring: bool = Field(default=False, description="Supports energy monitoring")
|
||||
supports_remote_control: bool = Field(default=False, description="Supports remote control")
|
||||
|
||||
# Notes
|
||||
notes: Optional[str] = Field(None, description="Additional notes")
|
||||
|
||||
@@ -70,6 +113,8 @@ class EquipmentUpdate(BaseModel):
|
||||
model: Optional[str] = Field(None, max_length=100)
|
||||
serial_number: Optional[str] = Field(None, max_length=100)
|
||||
location: Optional[str] = Field(None, max_length=255)
|
||||
manufacturer: Optional[str] = Field(None, max_length=100)
|
||||
firmware_version: Optional[str] = Field(None, max_length=50)
|
||||
status: Optional[EquipmentStatus] = None
|
||||
|
||||
# Installation and maintenance
|
||||
@@ -92,6 +137,23 @@ class EquipmentUpdate(BaseModel):
|
||||
current_temperature: Optional[float] = None
|
||||
target_temperature: Optional[float] = None
|
||||
|
||||
# IoT Connectivity
|
||||
iot_enabled: Optional[bool] = None
|
||||
iot_protocol: Optional[str] = None
|
||||
iot_endpoint: Optional[str] = None
|
||||
iot_port: Optional[int] = None
|
||||
iot_config: Optional[dict] = None
|
||||
|
||||
# Real-time monitoring
|
||||
supports_realtime: Optional[bool] = None
|
||||
poll_interval_seconds: Optional[int] = Field(None, ge=1)
|
||||
|
||||
# Sensor capabilities
|
||||
temperature_zones: Optional[int] = Field(None, ge=1)
|
||||
supports_humidity: Optional[bool] = None
|
||||
supports_energy_monitoring: Optional[bool] = None
|
||||
supports_remote_control: Optional[bool] = None
|
||||
|
||||
# Notes
|
||||
notes: Optional[str] = None
|
||||
|
||||
@@ -119,6 +181,8 @@ class EquipmentResponse(BaseModel):
|
||||
model: Optional[str] = None
|
||||
serial_number: Optional[str] = None
|
||||
location: Optional[str] = None
|
||||
manufacturer: Optional[str] = None
|
||||
firmware_version: Optional[str] = None
|
||||
status: EquipmentStatus
|
||||
|
||||
# Installation and maintenance
|
||||
@@ -141,6 +205,25 @@ class EquipmentResponse(BaseModel):
|
||||
current_temperature: Optional[float] = None
|
||||
target_temperature: Optional[float] = None
|
||||
|
||||
# IoT Connectivity
|
||||
iot_enabled: bool = False
|
||||
iot_protocol: Optional[str] = None
|
||||
iot_endpoint: Optional[str] = None
|
||||
iot_port: Optional[int] = None
|
||||
iot_connection_status: Optional[str] = None
|
||||
iot_last_connected: Optional[datetime] = None
|
||||
iot_config: Optional[dict] = None
|
||||
|
||||
# Real-time monitoring
|
||||
supports_realtime: bool = False
|
||||
poll_interval_seconds: Optional[int] = None
|
||||
|
||||
# Sensor capabilities
|
||||
temperature_zones: Optional[int] = None
|
||||
supports_humidity: bool = False
|
||||
supports_energy_monitoring: bool = False
|
||||
supports_remote_control: bool = False
|
||||
|
||||
# Status
|
||||
is_active: bool
|
||||
notes: Optional[str] = None
|
||||
@@ -196,3 +279,189 @@ class EquipmentDeletionSummary(BaseModel):
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# ================================================================
|
||||
# IoT-SPECIFIC SCHEMAS
|
||||
# ================================================================
|
||||
|
||||
class EquipmentSensorReadingResponse(BaseModel):
|
||||
"""Schema for equipment sensor reading response"""
|
||||
id: UUID
|
||||
tenant_id: UUID
|
||||
equipment_id: UUID
|
||||
batch_id: Optional[UUID] = None
|
||||
reading_time: datetime
|
||||
|
||||
# Temperature readings
|
||||
temperature: Optional[float] = None
|
||||
temperature_zones: Optional[dict] = None
|
||||
target_temperature: Optional[float] = None
|
||||
|
||||
# Humidity
|
||||
humidity: Optional[float] = None
|
||||
target_humidity: Optional[float] = None
|
||||
|
||||
# Energy monitoring
|
||||
energy_consumption_kwh: Optional[float] = None
|
||||
power_current_kw: Optional[float] = None
|
||||
|
||||
# Equipment status
|
||||
operational_status: Optional[str] = None
|
||||
cycle_stage: Optional[str] = None
|
||||
cycle_progress_percentage: Optional[float] = None
|
||||
time_remaining_minutes: Optional[int] = None
|
||||
|
||||
# Process parameters
|
||||
motor_speed_rpm: Optional[float] = None
|
||||
door_status: Optional[str] = None
|
||||
steam_level: Optional[float] = None
|
||||
|
||||
# Quality indicators
|
||||
product_weight_kg: Optional[float] = None
|
||||
moisture_content: Optional[float] = None
|
||||
|
||||
# Additional sensor data
|
||||
additional_sensors: Optional[dict] = None
|
||||
|
||||
# Data quality
|
||||
data_quality_score: Optional[float] = None
|
||||
is_anomaly: bool = False
|
||||
|
||||
created_at: datetime
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class EquipmentConnectionTestResponse(BaseModel):
|
||||
"""Schema for IoT connection test response"""
|
||||
success: bool = Field(..., description="Whether connection test succeeded")
|
||||
status: str = Field(..., description="Connection status")
|
||||
message: str = Field(..., description="Detailed message")
|
||||
response_time_ms: Optional[int] = Field(None, description="Response time in milliseconds")
|
||||
protocol_tested: str = Field(..., description="Protocol that was tested")
|
||||
endpoint_tested: str = Field(..., description="Endpoint that was tested")
|
||||
error_details: Optional[str] = Field(None, description="Error details if connection failed")
|
||||
supported_features: Optional[List[str]] = Field(None, description="List of supported IoT features")
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"success": True,
|
||||
"status": "connected",
|
||||
"message": "Successfully connected to equipment",
|
||||
"response_time_ms": 145,
|
||||
"protocol_tested": "rest_api",
|
||||
"endpoint_tested": "https://connectedcooking.com/api/v1",
|
||||
"supported_features": ["temperature", "humidity", "energy_monitoring"]
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class RealTimeDataResponse(BaseModel):
|
||||
"""Schema for real-time equipment data response"""
|
||||
equipment_id: UUID
|
||||
equipment_name: str
|
||||
timestamp: datetime
|
||||
connection_status: str
|
||||
|
||||
# Current readings
|
||||
temperature: Optional[float] = None
|
||||
temperature_zones: Optional[dict] = None
|
||||
humidity: Optional[float] = None
|
||||
energy_consumption_kwh: Optional[float] = None
|
||||
power_current_kw: Optional[float] = None
|
||||
|
||||
# Status
|
||||
operational_status: Optional[str] = None
|
||||
cycle_stage: Optional[str] = None
|
||||
cycle_progress_percentage: Optional[float] = None
|
||||
time_remaining_minutes: Optional[int] = None
|
||||
|
||||
# Active batch
|
||||
active_batch_id: Optional[UUID] = None
|
||||
active_batch_name: Optional[str] = None
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"equipment_id": "123e4567-e89b-12d3-a456-426614174000",
|
||||
"equipment_name": "Horno Principal #1",
|
||||
"timestamp": "2025-01-12T10:30:00Z",
|
||||
"connection_status": "connected",
|
||||
"temperature": 185.5,
|
||||
"temperature_zones": {"zone1": 180, "zone2": 190, "zone3": 185},
|
||||
"humidity": 65.0,
|
||||
"operational_status": "running",
|
||||
"cycle_stage": "baking",
|
||||
"cycle_progress_percentage": 45.0,
|
||||
"time_remaining_minutes": 12
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class EquipmentIoTAlertResponse(BaseModel):
|
||||
"""Schema for IoT alert response"""
|
||||
id: UUID
|
||||
tenant_id: UUID
|
||||
equipment_id: UUID
|
||||
batch_id: Optional[UUID] = None
|
||||
|
||||
# Alert information
|
||||
alert_type: str
|
||||
severity: str
|
||||
alert_time: datetime
|
||||
|
||||
# Alert details
|
||||
title: str
|
||||
message: str
|
||||
|
||||
# Threshold information
|
||||
threshold_value: Optional[float] = None
|
||||
actual_value: Optional[float] = None
|
||||
deviation_percentage: Optional[float] = None
|
||||
|
||||
# Status
|
||||
is_active: bool
|
||||
is_acknowledged: bool
|
||||
acknowledged_by: Optional[UUID] = None
|
||||
acknowledged_at: Optional[datetime] = None
|
||||
|
||||
is_resolved: bool
|
||||
resolved_by: Optional[UUID] = None
|
||||
resolved_at: Optional[datetime] = None
|
||||
resolution_notes: Optional[str] = None
|
||||
|
||||
# Automated response
|
||||
auto_resolved: bool
|
||||
corrective_action_taken: Optional[str] = None
|
||||
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class EquipmentSensorHistoryResponse(BaseModel):
|
||||
"""Schema for sensor reading history response"""
|
||||
equipment_id: UUID
|
||||
equipment_name: str
|
||||
start_time: datetime
|
||||
end_time: datetime
|
||||
total_readings: int
|
||||
readings: List[EquipmentSensorReadingResponse]
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"equipment_id": "123e4567-e89b-12d3-a456-426614174000",
|
||||
"equipment_name": "Horno Principal #1",
|
||||
"start_time": "2025-01-12T08:00:00Z",
|
||||
"end_time": "2025-01-12T12:00:00Z",
|
||||
"total_readings": 48,
|
||||
"readings": []
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user