Skip to content

Commit

Permalink
Make last_reset for today_energy timezone aware
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh committed Aug 6, 2021
1 parent d5b5bde commit 1211723
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/omnikdatalogger/omnik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

logging.basicConfig(stream=sys.stdout, level=os.environ.get("LOGLEVEL", logging.INFO))

__version__ = "1.6.5"
__version__ = "1.6.6"

logger = logging.getLogger(__name__)

Expand Down
25 changes: 13 additions & 12 deletions apps/omnikdatalogger/omnik/plugin_output/mqtt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from datetime import datetime, tzinfo
import pytz
import json
import time
from omnik.ha_logger import hybridlogger
Expand All @@ -15,9 +16,8 @@ def __init__(self):
super().__init__()
self.name = "mqtt"
self.description = "Write output to internal mqtt facility of Home Assistant"
# tz = self.config.get('default', 'timezone',
# fallback='Europe/Amsterdam')
# self.timezone = pytz.timezone(tz)
tz = self.config.get("default", "timezone", fallback="Europe/Amsterdam")
self.timezone = pytz.timezone(tz)

self.mqtt_client_name = (
self.config.get(
Expand Down Expand Up @@ -438,11 +438,15 @@ def _publish_last_reset(self, topics, last_reset_pl):
)
if last_reset == "today":
payload = str(
datetime(
year=datetime.now().year,
month=datetime.now().month,
day=datetime.now().day,
).isoformat()
datetime.now(self.timezone)
.replace(
hour=0,
minute=0,
second=0,
microsecond=0,
)
.astimezone(pytz.utc)
.isoformat()
)
elif type(last_reset) is datetime:
payload = str(last_reset.isoformat())
Expand Down Expand Up @@ -493,9 +497,6 @@ def process(self, **args):
# Get argument
msg = args["msg"]

# Set report time in local timezone
# msg['reporttime'] = time.localtime(msg['last_update'])

# Assemble config
asset_classes, last_reset = self._init_config(msg)

Expand Down

0 comments on commit 1211723

Please sign in to comment.