Browse Source

Added defensive code if the previous position is not set.

Dominick Meglio 1 year ago
parent
commit
7fc8bc8f6e
1 changed files with 3 additions and 1 deletions
  1. 3 1
      switchbot/devices/curtain.py

+ 3 - 1
switchbot/devices/curtain.py

@@ -152,8 +152,10 @@ class SwitchbotCurtain(SwitchbotDevice):
             "timers": _data[7],
         }
     
-    def _update_motion_direction(self, in_motion: bool, previous_position: int, new_position: int) -> None:
+    def _update_motion_direction(self, in_motion: bool, previous_position: int|None, new_position: int) -> None:
         """Update opening/closing status based on movement."""
+        if previous_position is None:
+            return
         if in_motion == True:
             if new_position != previous_position:
                 self._is_opening = new_position > previous_position