Skip to content

Commit

Permalink
Interrupt movement routine when desk stops moving
Browse files Browse the repository at this point in the history
  • Loading branch information
abmantis committed Oct 7, 2023
1 parent 7b286e4 commit 2f09fda
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions idasen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import asyncio
import logging
import sys
import time


_UUID_HEIGHT: str = "99fa0021-338a-1024-8a49-009c0215f78a"
Expand Down Expand Up @@ -299,6 +300,7 @@ async def move_to_target(self, target: float):
async def do_move():
previous_height = await self.get_height()
will_move_up = target > previous_height
last_move_time: float | None = None
while True:
height = await self.get_height()
difference = target - height
Expand All @@ -310,6 +312,17 @@ async def do_move():
"stopped moving because desk safety feature kicked in"
)
return

if height == previous_height:
if last_move_time is not None and time.time() - last_move_time > 1:
self._logger.warning(
"desk is not moving anymore. physical button probably "
"pressed"
)
return
else:
last_move_time = time.time()

if not self._moving:
return

Expand Down

0 comments on commit 2f09fda

Please sign in to comment.