Kaynağa Gözat

fix a bug if there is no target

chenhaiyang 4 yıl önce
ebeveyn
işleme
db45c1a8e2
2 değiştirilmiş dosya ile 12 ekleme ve 9 silme
  1. 2 2
      app/controllers/equipment/fcu.py
  2. 10 7
      app/services/transfer.py

+ 2 - 2
app/controllers/equipment/fcu.py

@@ -18,7 +18,7 @@ class FCUController(EquipmentController):
 
     async def get_temperature_target(self) -> float:
         target = self._equipment.space.temperature_target
-        if not np.isnan(target) and target > 0:
+        if not np.isnan(target):
             setting_target = target
         else:
             setting_target = 25.0
@@ -28,7 +28,7 @@ class FCUController(EquipmentController):
 
     async def get_air_valve_speed(self):
         temperature_target = await self.get_temperature_target()
-        if temperature_target and temperature_target > 0:
+        if temperature_target > 0:
             self._equipment.air_valve_speed = AirValveSpeed.auto
         else:
             self._equipment.air_valve_speed = AirValveSpeed.off

+ 10 - 7
app/services/transfer.py

@@ -114,14 +114,17 @@ class SpaceInfoService(Service):
 
         return custom_target_df
 
-    async def get_current_temperature_target(self) -> float:
+    async def get_current_temperature_target(self) -> object:
         current_targets = await self.get_custom_target()
-        temp = arrow.get(self._now_time, TIME_FMT).shift(minutes=15).timestamp // (15 * 60) * (15 * 60)
-        next_quarter_minutes = arrow.get(temp).time().strftime('%H%M%S')
-        try:
-            current_lower_target = current_targets['temperatureMin'].loc[next_quarter_minutes]
-            current_upper_target = current_targets['temperatureMax'].loc[next_quarter_minutes]
-        except KeyError:
+        if len(current_targets) > 0:
+            temp = arrow.get(self._now_time, TIME_FMT).shift(minutes=15).timestamp // (15 * 60) * (15 * 60)
+            next_quarter_minutes = arrow.get(temp).time().strftime('%H%M%S')
+            try:
+                current_lower_target = current_targets['temperatureMin'].loc[next_quarter_minutes]
+                current_upper_target = current_targets['temperatureMax'].loc[next_quarter_minutes]
+            except KeyError:
+                current_lower_target, current_upper_target = 0.0, 0.0
+        else:
             current_lower_target, current_upper_target = np.NAN, np.NAN
 
         return (current_lower_target + current_upper_target) / 2