Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time formatting in logs #78

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions occameracontrol/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import datetime
import logging
import requests
import time
Expand Down Expand Up @@ -98,6 +99,13 @@ def move_to_preset(self, preset: int):
self.position = preset
register_camera_move(self.url, preset)

def from_now(self, ts: float) -> str:
'''Get a string representation of the time until the provided time
stamp is reached.
'''
seconds = int(ts - time.time()) # seconds are enough accuracy
return str(datetime.timedelta(seconds=seconds))

def update_position(self):
'''Check for currently active events with the camera's capture agent
and move the camera to the appropriate (active, inactive) position if
Expand All @@ -108,11 +116,11 @@ def update_position(self):

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())
logger.log(level, '[%s] Next event `%s` starts in %s',
agent_id, event.title[:40], self.from_now(event.start))
elif event.active():
logger.log(level, '[%s] Active event `%s` ends in %i seconds',
agent_id, event.title[:40], event.end - time.time())
logger.log(level, '[%s] Active event `%s` ends in %s',
agent_id, event.title[:40], self.from_now(event.end))
else:
logger.log(level, '[%s] No planned events', agent_id)

Expand Down
Loading