File: utils.py

package info (click to toggle)
python-aiopvpc 4.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 592 kB
  • sloc: python: 1,415; makefile: 7
file content (14 lines) | stat: -rw-r--r-- 402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""ESIOS API handler for HomeAssistant. Utils."""

from datetime import datetime

from aiopvpc.const import UTC_TZ


def ensure_utc_time(ts: datetime) -> datetime:
    """Return tz-aware datetime in UTC from any datetime."""
    if ts.tzinfo is None:
        return datetime(*ts.timetuple()[:6], tzinfo=UTC_TZ)
    elif str(ts.tzinfo) != str(UTC_TZ):
        return ts.astimezone(UTC_TZ)
    return ts