Skip to content

Commit

Permalink
Initial Position after Restart
Browse files Browse the repository at this point in the history
This patch ensures that the calendar data is updated at least once
before repositioning the camera. This ensures that active recordings are
no longer interrupted by moving the camera to the neutral position on
(re-)start.

This fixes #63
  • Loading branch information
lkiesow committed Apr 8, 2024
1 parent 7aac488 commit d6dcf84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions occameracontrol/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Agent:
'''
agent_id: str
events: list[Event] = []
calendar_initialized: bool = False

def __init__(self, agent_id: str):
self.agent_id = agent_id
Expand Down Expand Up @@ -108,6 +109,7 @@ def update_calendar(self):

self.events = self.parse_calendar(calendar)
register_calendar_update(self.agent_id)
self.calendar_initialized = True

def active_events(self):
'''Return a list of active events
Expand Down
7 changes: 6 additions & 1 deletion occameracontrol/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@ def update_position(self):
necessary.
'''
agent_id = self.agent.agent_id
level = logging.DEBUG if int(time.time()) % 60 else logging.INFO

while not self.agent.calendar_initialized:
logger.log(level, '[%s] Calendar not yet initialized…', agent_id)
time.sleep(1)

event = self.agent.next_event()

level = logging.DEBUG if int(time.time()) % 60 else logging.INFO
if event.future():
logger.log(level, '[%s] Next event `%s` starts in %i seconds',
agent_id, event.title[:40], event.start - time.time())
Expand Down

0 comments on commit d6dcf84

Please sign in to comment.