Skip to content

Commit

Permalink
Added envoy login 12h autorefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonajack committed Dec 23, 2023
1 parent d424d57 commit 8b7a528
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ RUN \
python3 -m pip install --upgrade pip && \
python3 -m pip install poetry && \
python3 -m pip cache purge && \
# Configure poetry for localized install
poetry config virtualenvs.path /opt/envoy_logger/.cache && \
poetry config virtualenvs.create false && \
# Install dependencies
poetry install

ENV ENVOY_LOGGER_CFG_PATH=/etc/envoy_logger/config.yml
Expand Down
18 changes: 16 additions & 2 deletions envoy_logger/envoy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from dataclasses import dataclass
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone
from typing import Dict, Optional

import requests
Expand All @@ -20,13 +20,27 @@ class Envoy:
url: str
enphase_energy: EnphaseEnergy
session_id: Optional[str] = None
session_id_last_update: datetime = datetime.now()

def get_session_id(self) -> str:
if not self.session_id:
now = datetime.now()
elapsed = now - self.session_id_last_update

if not self.session_id or elapsed > timedelta(hours = 12):
self._login()
self.session_id_last_update = now

return self.session_id

def _wait_for_next_cycle(self) -> None:
# Determine how long until the next sample needs to be taken

try:
time.sleep(time_to_next)
except KeyboardInterrupt:
print("Exiting with Ctrl-C")
sys.exit(0)

def _login(self) -> None:
"""
Login to local envoy and return the session id
Expand Down

0 comments on commit 8b7a528

Please sign in to comment.