summaryrefslogtreecommitdiff
path: root/src/home/database/inverter.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-10-25 02:41:46 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-10-30 01:37:35 +0300
commitdb784dc98ba0c4e15ee7b501d909425c79c825fb (patch)
tree68270179f77c95dc49ec4ab62f9305aa651c4cd4 /src/home/database/inverter.py
parent0fce6c52516aba239acc81fd528dcb5051c04f68 (diff)
web_api: rewrite to aiohttp, drop flask
Diffstat (limited to 'src/home/database/inverter.py')
-rw-r--r--src/home/database/inverter.py31
1 files changed, 4 insertions, 27 deletions
diff --git a/src/home/database/inverter.py b/src/home/database/inverter.py
index 756186c..1e967c4 100644
--- a/src/home/database/inverter.py
+++ b/src/home/database/inverter.py
@@ -1,40 +1,17 @@
-import logging
-
-from zoneinfo import ZoneInfo
from time import time
-from datetime import datetime, timedelta
+from datetime import datetime
from typing import Optional
from collections import namedtuple
-from ..config import is_development_mode
-from .clickhouse import get_clickhouse
+from .clickhouse import ClickhouseDatabase
IntervalList = list[list[Optional[datetime]]]
-class InverterDatabase:
+class InverterDatabase(ClickhouseDatabase):
def __init__(self):
- self.db = get_clickhouse('solarmon')
- self.server_timezone = self.query('SELECT timezone()')[0][0]
-
- self.logger = logging.getLogger(self.__class__.__name__)
-
- def query(self, *args, **kwargs):
- settings = {'use_client_time_zone': True}
- kwargs['settings'] = settings
-
- if 'no_tz_fix' not in kwargs and len(args) > 1 and isinstance(args[1], dict):
- for k, v in args[1].items():
- if isinstance(v, datetime):
- args[1][k] = v.astimezone(tz=ZoneInfo(self.server_timezone))
-
- result = self.db.execute(*args, **kwargs)
-
- if is_development_mode():
- self.logger.debug(args[0] if len(args) == 1 else args[0] % args[1])
-
- return result
+ super().__init__('solarmon')
def add_generation(self, home_id: int, client_time: int, watts: int) -> None:
self.db.execute(