|
@@ -1,5 +1,7 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
+from typing import Dict
|
|
|
+
|
|
|
import numpy as np
|
|
|
from httpx import AsyncClient
|
|
|
from loguru import logger
|
|
@@ -8,14 +10,16 @@ from app.controllers.equipment.controller import EquipmentController
|
|
|
from app.schemas.equipment import AirValveSpeed, FCU
|
|
|
from app.schemas.space import Space
|
|
|
from app.services.platform import DataPlatformService
|
|
|
-from app.services.transfer import SpaceInfoService, EquipmentInfoService
|
|
|
+from app.services.transfer import SpaceInfoService, Duoduo, Season
|
|
|
+from app.utils.math import round_half_up
|
|
|
|
|
|
|
|
|
class FCUController(EquipmentController):
|
|
|
|
|
|
- def __init__(self, equipment: FCU):
|
|
|
+ def __init__(self, equipment: FCU, season: Season):
|
|
|
super(FCUController, self).__init__()
|
|
|
self._equipment = equipment
|
|
|
+ self.season = season
|
|
|
|
|
|
async def get_temperature_target(self) -> float:
|
|
|
target = self._equipment.space.temperature_target
|
|
@@ -48,25 +52,36 @@ class FCUController(EquipmentController):
|
|
|
else:
|
|
|
self._equipment.running_status = True
|
|
|
|
|
|
+ async def get_mode(self) -> None:
|
|
|
+ if self.season == Season.heating:
|
|
|
+ mode = 2
|
|
|
+ elif self.season == Season.cooling:
|
|
|
+ mode = 1
|
|
|
+ else:
|
|
|
+ mode = 0
|
|
|
+ self._equipment.work_mode = mode
|
|
|
+
|
|
|
async def run(self):
|
|
|
await self.get_temperature_target()
|
|
|
await self.get_air_valve_speed()
|
|
|
await self.get_running_status()
|
|
|
+ await self.get_mode()
|
|
|
|
|
|
def get_results(self):
|
|
|
return self._equipment
|
|
|
|
|
|
|
|
|
@logger.catch()
|
|
|
-async def get_fcu_control_result(project_id: str, equipment_id: str) -> FCU:
|
|
|
+async def get_fcu_control_result(project_id: str, equipment_id: str) -> Dict:
|
|
|
async with AsyncClient() as client:
|
|
|
- duo_duo = EquipmentInfoService(client, project_id)
|
|
|
+ duo_duo = Duoduo(client, project_id)
|
|
|
platform = DataPlatformService(client, project_id)
|
|
|
spaces = await duo_duo.get_space_by_equipment(equipment_id)
|
|
|
for sp in spaces:
|
|
|
transfer = SpaceInfoService(client, project_id, sp.get('id'))
|
|
|
current_target = await transfer.get_current_temperature_target()
|
|
|
realtime_temperature = await platform.get_realtime_temperature(sp.get('id'))
|
|
|
+ season = await transfer.get_season()
|
|
|
temp_space_params = {
|
|
|
'id': sp.get('id'),
|
|
|
'temperature_target': current_target,
|
|
@@ -81,8 +96,17 @@ async def get_fcu_control_result(project_id: str, equipment_id: str) -> FCU:
|
|
|
}
|
|
|
fcu = FCU(**fcu_temp_params)
|
|
|
|
|
|
- fcu_controller = FCUController(fcu)
|
|
|
+ fcu_controller = FCUController(fcu, season)
|
|
|
await fcu_controller.run()
|
|
|
regulated_fcu = fcu_controller.get_results()
|
|
|
|
|
|
- return regulated_fcu
|
|
|
+ output = {
|
|
|
+ 'onOff': 1 if regulated_fcu.running_status else 0,
|
|
|
+ 'mode': regulated_fcu.work_mode,
|
|
|
+ 'speed': regulated_fcu.air_valve_speed.value,
|
|
|
+ 'temperature': int(round_half_up(regulated_fcu.setting_temperature, 1)),
|
|
|
+ 'water': 1 if regulated_fcu.running_status else 0
|
|
|
+ }
|
|
|
+ logger.debug(output)
|
|
|
+
|
|
|
+ return output
|