Parcourir la source

add a new router for ACATFC4

highing666 il y a 3 ans
Parent
commit
8f06337f69

+ 26 - 3
app/api/routers/devices.py

@@ -11,7 +11,10 @@ from app.controllers.equipment.ahu.supply_air_temperature_set import (
 )
 from app.controllers.equipment.ahu.switch import build_acatah_switch_set
 from app.controllers.equipment.ahu.thermal_mode import build_acatah_thermal_mode_set
-from app.controllers.equipment.fcu.basic import build_acatfc_instructions
+from app.controllers.equipment.fcu.basic import (
+    build_acatfc2_instructions,
+    build_acatfc4_instructions,
+)
 from app.controllers.equipment.fcu.early_start import (
     build_acatfc_early_start_prediction,
 )
@@ -187,8 +190,28 @@ async def get_acatvi_instructions(
 @router.post(
     "/instructions/acatfc", response_model=domain_devices.ACATFCInstructionsResponse
 )
-async def get_acatfc_instructions(params: domain_devices.ACATFCInstructionsRequest):
-    instructions = await build_acatfc_instructions(params)
+async def get_acatfc_instructions(params: domain_devices.ACATFC2InstructionsRequest):
+    instructions = await build_acatfc2_instructions(params)
+
+    logger.info(params)
+    logger.info(f"{params.device_id} - {instructions}")
+
+    response = domain_devices.ACATFCInstructionsResponse(
+        onOff=instructions.switch_set,
+        speed=instructions.speed_set,
+        temperature=instructions.temperature_set,
+        mode=instructions.mode_set,
+        water=instructions.water_valve_switch_set,
+    )
+
+    return response
+
+
+@router.post(
+    "/instructions/acatfc4", response_model=domain_devices.ACATFCInstructionsResponse
+)
+async def get_acatfc4_instructions(params: domain_devices.ACATFC4InstructionsRequest):
+    instructions = await build_acatfc4_instructions(params)
 
     logger.info(params)
     logger.info(f"{params.device_id} - {instructions}")

+ 31 - 3
app/controllers/equipment/fcu/basic.py

@@ -7,7 +7,10 @@ from httpx import AsyncClient
 from loguru import logger
 
 from app.controllers.equipment.controller import EquipmentController
-from app.models.domain.devices import ACATFCInstructionsRequest
+from app.models.domain.devices import (
+    ACATFC2InstructionsRequest,
+    ACATFC4InstructionsRequest,
+)
 from app.schemas.equipment import AirValveSpeed, FCU
 from app.schemas.instructions import ACATFCInstructions
 from app.schemas.space import Space
@@ -232,8 +235,8 @@ async def get_fcu_control_result(project_id: str, equipment_id: str) -> Dict:
 
 
 @logger.catch()
-async def build_acatfc_instructions(
-    params: ACATFCInstructionsRequest,
+async def build_acatfc2_instructions(
+    params: ACATFC2InstructionsRequest,
 ) -> ACATFCInstructions:
     space = Space(
         temperature_target=params.space_temperature_target,
@@ -254,3 +257,28 @@ async def build_acatfc_instructions(
     )
 
     return instructions
+
+
+@logger.catch()
+async def build_acatfc4_instructions(
+    params: ACATFC4InstructionsRequest,
+) -> ACATFCInstructions:
+    space = Space(
+        temperature_target=params.space_temperature_target,
+        realtime_temperature=params.space_realtime_temperature,
+    )
+    fcu = FCU(space=space)
+
+    controller = FCUController(fcu, Season(params.season))
+    await controller.run()
+    regulated_fcu = controller.get_results()
+
+    instructions = ACATFCInstructions(
+        switch_set=1 if regulated_fcu.running_status else 0,
+        speed_set=regulated_fcu.air_valve_speed.value,
+        temperature_set=float(round_half_up(regulated_fcu.setting_temperature, 1)),
+        mode_set=regulated_fcu.work_mode,
+        water_valve_switch_set=1 if regulated_fcu.running_status else 0,
+    )
+
+    return instructions

+ 9 - 1
app/models/domain/devices.py

@@ -52,13 +52,21 @@ class ACATVIInstructionsResponse(BaseModel):
     # mode_set: Optional[str]
 
 
-class ACATFCInstructionsRequest(BaseModel):
+class ACATFCInstructionsRequestBase(BaseModel):
     device_id: str
     season: str
     space_temperature_target: float
     space_realtime_temperature: Optional[float]
 
 
+class ACATFC2InstructionsRequest(ACATFCInstructionsRequestBase):
+    pass
+
+
+class ACATFC4InstructionsRequest(ACATFCInstructionsRequestBase):
+    pass
+
+
 class ACATFCInstructionsResponse(BaseModel):
     switch_set: int = Field(None, alias="onOff")
     speed_set: int = Field(None, alias="speed")