Skip to content

Commit

Permalink
add logging for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mausy5043 committed Dec 17, 2024
1 parent 51505aa commit c6eecdb
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bin/libmyenergi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import configparser
import datetime as dt
import json
import logging
import os
import syslog
import time
Expand All @@ -19,6 +20,7 @@
import requests
from requests.auth import HTTPDigestAuth

LOGGER: logging.Logger = logging.getLogger(__name__)
pd.options.display.float_format = "{:.3f}".format

# constants
Expand Down Expand Up @@ -230,21 +232,25 @@ def fetch_data(self, day_to_fetch: dt.datetime) -> None:
current_day_data: list = []
# fmt: off
# pylint: disable=line-too-long
if (_dif.days) < 7:
extra_day1_data = [self.standardise_json_block(block) for block in self._fetch(day_to_fetch - dt.timedelta(days=2.0))[f"U{self.zappi_serial}"]]
previous_day_data = [self.standardise_json_block(block) for block in self._fetch(day_to_fetch - dt.timedelta(days=1.0))[f"U{self.zappi_serial}"]]
current_day_data = [self.standardise_json_block(block) for block in self._fetch(day_to_fetch)[f"U{self.zappi_serial}"]]
# fmt: on
try:
if (_dif.days) < 7:
extra_day1_data = [self.standardise_json_block(block) for block in self._fetch(day_to_fetch - dt.timedelta(days=2.0))[f"U{self.zappi_serial}"]]
previous_day_data = [self.standardise_json_block(block) for block in self._fetch(day_to_fetch - dt.timedelta(days=1.0))[f"U{self.zappi_serial}"]]
current_day_data = [self.standardise_json_block(block) for block in self._fetch(day_to_fetch)[f"U{self.zappi_serial}"]]

mf.syslog_trace(f"> {extra_day1_data[0]}", False, self.DEBUG)
mf.syslog_trace(f"> {extra_day1_data[1]}", False, self.DEBUG)
mf.syslog_trace(f"> {previous_day_data[0]}", False, self.DEBUG)
mf.syslog_trace(f"> {previous_day_data[1]}", False, self.DEBUG)
mf.syslog_trace(f"> {current_day_data[-2]}", False, self.DEBUG)
mf.syslog_trace(f"> {current_day_data[-1]}", False, self.DEBUG)
except IndexError:
LOGGER.warning(f"IndexError encountered for {day_to_fetch.strftime(format=constants.DT_FORMAT)}")
pass

except KeyError:
LOGGER.warning(f"KeyError encountered for {day_to_fetch.strftime(format=constants.DT_FORMAT)}")
pass
# fmt: on
result = extra_day1_data + previous_day_data + current_day_data
self.zappi_data = self.compact_data(result)

Expand Down

0 comments on commit c6eecdb

Please sign in to comment.