Переглянути джерело

update ATFU control logic

highing666 3 роки тому
батько
коміт
3e2b5ea87f
2 змінених файлів з 35 додано та 5 видалено
  1. 31 2
      app/controllers/equipment/pau/switch.py
  2. 4 3
      app/models/domain/devices.py

+ 31 - 2
app/controllers/equipment/pau/switch.py

@@ -11,6 +11,31 @@ class PAUSwitch(Switch):
     def __init__(self, equipment: PAU):
         super(PAUSwitch, self).__init__(equipment)
 
+    def break_time_action(self, begin: str, end: str, is_workday: bool) -> SwitchSet:
+        if self._equip.in_cloud_status:
+            if is_workday:
+                if begin and end:
+                    switch_flag = True
+                    if begin <= end:
+                        if begin <= self._now_time <= end:
+                            switch_flag = False
+                    else:
+                        if not end <= self._now_time <= begin:
+                            switch_flag = False
+
+                    if not switch_flag:
+                        action = SwitchSet.off
+                    else:
+                        action = SwitchSet.hold
+                else:
+                    action = SwitchSet.hold
+            else:
+                action = SwitchSet.hold
+        else:
+            action = SwitchSet.hold
+
+        return action
+
 
 @logger.catch()
 async def build_acatfu_switch_set(params: ACATFUSwitchSetRequest) -> SwitchSet:
@@ -20,8 +45,12 @@ async def build_acatfu_switch_set(params: ACATFUSwitchSetRequest) -> SwitchSet:
         on_time=params.on_time,
         off_time=params.off_time,
     )
-    action = await PAUSwitch(pau).build_next_action(params.is_workday)
-    if not params.is_workday:
+    pau_switch_controller = PAUSwitch(pau)
+    action = await pau_switch_controller.build_next_action(params.is_workday)
+    break_action = pau_switch_controller.break_time_action(
+        params.break_start_time, params.break_end_time, params.is_workday
+    )
+    if break_action == "off":
         action = SwitchSet.off
 
     return action

+ 4 - 3
app/models/domain/devices.py

@@ -189,7 +189,8 @@ class ACVTSFSwitchSetResponse(SwitchSetResponseBase):
 
 
 class ACATFUSwitchSetRequest(SwitchSetRequestBase):
-    pass
+    break_start_time: Optional[str]
+    break_end_time: Optional[str]
 
 
 class ACATFUSwitchSetResponse(SwitchSetResponseBase):
@@ -197,8 +198,8 @@ class ACATFUSwitchSetResponse(SwitchSetResponseBase):
 
 
 class ACATAHSwitchSetRequest(SwitchSetRequestBase):
-    break_start_time: str
-    break_end_time: str
+    break_start_time: Optional[str]
+    break_end_time: Optional[str]
 
 
 class ACATAHSwitchSetResponse(SwitchSetResponseBase):