Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/helpermodules/compatibility.py

This file was deleted.

3 changes: 3 additions & 0 deletions packages/helpermodules/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from enum import Enum
from pathlib import Path


NO_ERROR = "Kein Fehler."

RAMDISK_PATH = Path(__file__).resolve().parents[2] / "ramdisk"


class DEFAULT_COLORS(Enum):
CHARGEPOINT = "#007bff"
Expand Down
23 changes: 12 additions & 11 deletions packages/helpermodules/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import os
import shutil

from helpermodules.constants import RAMDISK_PATH

FORMAT_STR_DETAILED = '%(asctime)s - {%(name)s:%(lineno)s} - {%(levelname)s:%(threadName)s} - %(message)s'
FORMAT_STR_SHORT = '%(asctime)s - %(message)s'
RAMDISK_PATH = str(Path(__file__).resolve().parents[2]) + '/ramdisk/'
PERSISTENT_LOG_PATH = str(Path(__file__).resolve().parents[2]) + '/data/log/'
NUMBER_OF_LOGFILES = 3

Expand Down Expand Up @@ -230,7 +231,7 @@ def mb_to_bytes(megabytes: int) -> int:
# to do: add smarthome and soc to in_memory_log_handlers, needs updates in individual thread calls

# Main logger
main_file_handler = RotatingFileHandler(RAMDISK_PATH + 'main.log', maxBytes=mb_to_bytes(5), backupCount=4)
main_file_handler = RotatingFileHandler(RAMDISK_PATH / 'main.log', maxBytes=mb_to_bytes(5), backupCount=4)
main_file_handler.setFormatter(logging.Formatter(FORMAT_STR_DETAILED))
main_file_handler.addFilter(RedactingFilter())
in_memory_log_handlers["main"] = InMemoryLogHandler(main_file_handler)
Expand All @@ -244,7 +245,7 @@ def mb_to_bytes(megabytes: int) -> int:
chargelog_log = logging.getLogger("chargelog")
chargelog_log.propagate = False
chargelog_file_handler = RotatingFileHandler(
RAMDISK_PATH + 'chargelog.log', maxBytes=mb_to_bytes(2), backupCount=1)
RAMDISK_PATH / 'chargelog.log', maxBytes=mb_to_bytes(2), backupCount=1)
chargelog_file_handler.setFormatter(logging.Formatter(FORMAT_STR_SHORT))
chargelog_file_handler.addFilter(RedactingFilter())
chargelog_log.addHandler(chargelog_file_handler)
Expand All @@ -261,7 +262,7 @@ def mb_to_bytes(megabytes: int) -> int:
# MQTT logger
mqtt_log = logging.getLogger("mqtt")
mqtt_log.propagate = False
mqtt_file_handler = RotatingFileHandler(RAMDISK_PATH + 'mqtt.log', maxBytes=mb_to_bytes(3), backupCount=1)
mqtt_file_handler = RotatingFileHandler(RAMDISK_PATH / 'mqtt.log', maxBytes=mb_to_bytes(3), backupCount=1)
mqtt_file_handler.setFormatter(logging.Formatter(FORMAT_STR_SHORT))
mqtt_file_handler.addFilter(RedactingFilter())
mqtt_log.addHandler(mqtt_file_handler)
Expand All @@ -278,27 +279,27 @@ def mb_to_bytes(megabytes: int) -> int:
garbage_collector_log = logging.getLogger("garbage_collector")
garbage_collector_log.propagate = False
garbage_collector_file_handler = RotatingFileHandler(
RAMDISK_PATH + 'garbage_collector.log', maxBytes=mb_to_bytes(0.5), backupCount=1)
RAMDISK_PATH / 'garbage_collector.log', maxBytes=mb_to_bytes(0.5), backupCount=1)
garbage_collector_file_handler.setFormatter(logging.Formatter(FORMAT_STR_SHORT))
garbage_collector_log.addHandler(garbage_collector_file_handler)

# tracemalloc logger
tracemalloc_log = logging.getLogger("tracemalloc")
tracemalloc_log.propagate = False
tracemalloc_file_handler = RotatingFileHandler(
RAMDISK_PATH + 'tracemalloc.log', maxBytes=mb_to_bytes(0.5), backupCount=1)
RAMDISK_PATH / 'tracemalloc.log', maxBytes=mb_to_bytes(0.5), backupCount=1)
tracemalloc_file_handler.setFormatter(logging.Formatter(FORMAT_STR_SHORT))
tracemalloc_log.addHandler(tracemalloc_file_handler)

# Smarthome logger
smarthome_log_handler = RotatingFileHandler(RAMDISK_PATH + 'smarthome.log', maxBytes=mb_to_bytes(1), backupCount=1)
smarthome_log_handler = RotatingFileHandler(RAMDISK_PATH / 'smarthome.log', maxBytes=mb_to_bytes(1), backupCount=1)
smarthome_log_handler.setFormatter(logging.Formatter(FORMAT_STR_SHORT))
smarthome_log_handler.addFilter(functools.partial(filter_pos, "smarthome"))
smarthome_log_handler.addFilter(RedactingFilter())
logging.getLogger().addHandler(smarthome_log_handler)

# SoC logger
soc_log_handler = RotatingFileHandler(RAMDISK_PATH + 'soc.log', maxBytes=mb_to_bytes(2), backupCount=1)
soc_log_handler = RotatingFileHandler(RAMDISK_PATH / 'soc.log', maxBytes=mb_to_bytes(2), backupCount=1)
soc_log_handler.setFormatter(logging.Formatter(FORMAT_STR_DETAILED))
soc_log_handler.addFilter(functools.partial(filter_pos, "soc"))
soc_log_handler.addFilter(RedactingFilter())
Expand All @@ -308,7 +309,7 @@ def mb_to_bytes(megabytes: int) -> int:
logging.getLogger().addHandler(in_memory_log_handlers["soc"])

# Internal chargepoint logger
internal_chargepoint_log_handler = RotatingFileHandler(RAMDISK_PATH + 'internal_chargepoint.log',
internal_chargepoint_log_handler = RotatingFileHandler(RAMDISK_PATH / 'internal_chargepoint.log',
maxBytes=mb_to_bytes(1),
backupCount=1)
internal_chargepoint_log_handler.setFormatter(logging.Formatter(FORMAT_STR_DETAILED))
Expand All @@ -322,7 +323,7 @@ def mb_to_bytes(megabytes: int) -> int:
# urllib3 logger
urllib3_log = logging.getLogger("urllib3.connectionpool")
urllib3_log.propagate = True
urllib3_file_handler = RotatingFileHandler(RAMDISK_PATH + 'soc.log', maxBytes=mb_to_bytes(2), backupCount=1)
urllib3_file_handler = RotatingFileHandler(RAMDISK_PATH / 'soc.log', maxBytes=mb_to_bytes(2), backupCount=1)
urllib3_file_handler.setFormatter(logging.Formatter(FORMAT_STR_DETAILED))
urllib3_file_handler.addFilter(RedactingFilter())
urllib3_file_handler.addFilter(functools.partial(filter_pos, "soc"))
Expand All @@ -332,7 +333,7 @@ def mb_to_bytes(megabytes: int) -> int:
logging.getLogger("uModbus").setLevel(logging.WARNING)
logging.getLogger("websockets").setLevel(logging.WARNING)

thread_errors_path = Path(RAMDISK_PATH+"thread_errors.log")
thread_errors_path = RAMDISK_PATH / "thread_errors.log"
with thread_errors_path.open("w") as f:
f.write("")

Expand Down
2 changes: 1 addition & 1 deletion packages/modules/common/powerwall.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from requests import HTTPError

from modules.common.req import get_http_session
from modules.common.store import RAMDISK_PATH
from helpermodules.constants import RAMDISK_PATH

COOKIE_FILE = RAMDISK_PATH / "powerwall_cookie.txt"
log = logging.getLogger(__name__)
Expand Down
2 changes: 0 additions & 2 deletions packages/modules/common/store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@
from modules.common.store._inverter import get_inverter_value_store
from modules.common.store._io import get_io_value_store
from modules.common.store._tariff import get_flexible_tariff_value_store, get_grid_fee_value_store
from modules.common.store.ramdisk.io import ramdisk_write, ramdisk_read, ramdisk_read_float, ramdisk_read_int, \
RAMDISK_PATH
17 changes: 1 addition & 16 deletions packages/modules/common/store/_battery.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
from helpermodules import compatibility
from modules.common.component_state import BatState
from modules.common.store import ValueStore
from modules.common.store._api import LoggingValueStore
from modules.common.store._broker import pub_to_broker
from modules.common.store.ramdisk import files


class BatteryValueStoreRamdisk(ValueStore[BatState]):
def __init__(self, component_num: int) -> None:
self.num = component_num

def set(self, bat_state: BatState):
files.battery.power.write(bat_state.power)
files.battery.soc.write(bat_state.soc)
files.battery.energy_imported.write(bat_state.imported)
files.battery.energy_exported.write(bat_state.exported)


class BatteryValueStoreBroker(ValueStore[BatState]):
Expand Down Expand Up @@ -47,6 +34,4 @@ def update(self) -> None:


def get_bat_value_store(component_num: int) -> ValueStore[BatState]:
return PurgeBatteryState(LoggingValueStore(
(BatteryValueStoreRamdisk if compatibility.is_ramdisk_in_use() else BatteryValueStoreBroker)(component_num)
))
return PurgeBatteryState(LoggingValueStore(BatteryValueStoreBroker(component_num)))
14 changes: 1 addition & 13 deletions packages/modules/common/store/_car.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
from helpermodules import compatibility
from modules.common.component_state import CarState
from modules.common.store import ValueStore
from modules.common.store._api import LoggingValueStore
from modules.common.store._broker import pub_to_broker
from modules.common.store.ramdisk import files


class CarValueStoreRamdisk(ValueStore[CarState]):
def __init__(self, charge_point: int):
self.file = files.charge_points[charge_point - 1].soc

def set(self, state: CarState) -> None:
self.file.write(int(state.soc))


class CarValueStoreBroker(ValueStore[CarState]):
Expand All @@ -29,6 +19,4 @@ def update(self):


def get_car_value_store(id: int) -> ValueStore[CarState]:
return LoggingValueStore(
CarValueStoreRamdisk(id) if compatibility.is_ramdisk_in_use() else CarValueStoreBroker(id)
)
return LoggingValueStore(CarValueStoreBroker(id))
20 changes: 1 addition & 19 deletions packages/modules/common/store/_chargepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
from modules.common.store import ValueStore
from modules.common.store._api import LoggingValueStore
from modules.common.store._broker import pub_to_broker
from modules.common.store.ramdisk import files
from helpermodules import compatibility


class ChargepointValueStoreRamdisk(ValueStore[ChargepointState]):
def __init__(self, cp_id: int):
self.num = cp_id

def set(self, cp_state: ChargepointState):
charge_point = files.charge_points[self.num]
charge_point.is_charging.write(cp_state.charge_state)
charge_point.voltages.write(cp_state.voltages)
charge_point.currents.write(cp_state.currents)
charge_point.energy.write(cp_state.imported/1000)
charge_point.is_plugged.write(cp_state.plug_state)
charge_point.power.write(int(cp_state.power))


class ChargepointValueStoreBroker(ValueStore[ChargepointState]):
Expand Down Expand Up @@ -68,6 +52,4 @@ def update(self):


def get_chargepoint_value_store(id: int) -> ValueStore[ChargepointState]:
return LoggingValueStore(
ChargepointValueStoreRamdisk(id) if compatibility.is_ramdisk_in_use() else ChargepointValueStoreBroker(id)
)
return LoggingValueStore(ChargepointValueStoreBroker(id))
20 changes: 1 addition & 19 deletions packages/modules/common/store/_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,18 @@
from typing import Dict, Optional

from control import data
from helpermodules import compatibility
from helpermodules.phase_handling import convert_cp_currents_to_evu_currents
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentType
from modules.common.simcount._simcounter import SimCounter
from modules.common.store import ValueStore
from modules.common.store._api import LoggingValueStore
from modules.common.store._broker import pub_to_broker
from modules.common.store.ramdisk import files
from modules.common.utils.component_parser import get_component_obj_by_id

log = logging.getLogger(__name__)


class CounterValueStoreRamdisk(ValueStore[CounterState]):
def set(self, counter_state: CounterState):
files.evu.voltages.write(counter_state.voltages)
if counter_state.currents:
files.evu.currents.write(counter_state.currents)
files.evu.powers_import.write([int(p) for p in counter_state.powers])
files.evu.power_factors.write(counter_state.power_factors)
files.evu.energy_import.write(counter_state.imported)
files.evu.energy_export.write(counter_state.exported)
files.evu.power_import.write(int(counter_state.power))
files.evu.frequency.write(counter_state.frequency)


class CounterValueStoreBroker(ValueStore[CounterState]):
def __init__(self, component_num: int) -> None:
self.num = component_num
Expand Down Expand Up @@ -172,8 +157,5 @@ def calc_uncounted_consumption(self) -> CounterState:
def get_counter_value_store(component_num: int,
add_child_values: bool = False,
simcounter: Optional[SimCounter] = None) -> PurgeCounterState:
if compatibility.is_ramdisk_in_use():
delegate = CounterValueStoreRamdisk()
else:
delegate = CounterValueStoreBroker(component_num)
delegate = CounterValueStoreBroker(component_num)
return PurgeCounterState(LoggingValueStore(delegate), add_child_values, simcounter)
21 changes: 1 addition & 20 deletions packages/modules/common/store/_inverter.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
import logging

from control import data
from helpermodules import compatibility
from modules.common.component_state import InverterState
from modules.common.store import ValueStore
from modules.common.store._api import LoggingValueStore
from modules.common.store._broker import pub_to_broker
from modules.common.store.ramdisk import files

log = logging.getLogger(__name__)


class InverterValueStoreRamdisk(ValueStore[InverterState]):
def __init__(self, component_num: int) -> None:
self.__pv = files.pv[component_num - 1]

def set(self, inverter_state: InverterState):
self.__pv.power.write(int(inverter_state.power))
if inverter_state.exported is not None:
self.__pv.energy.write(inverter_state.exported)
self.__pv.energy_k.write(inverter_state.exported / 1000)
else:
log.debug("Kein gültiger Zählerstand. Wert wird nicht aktualisiert.")
if inverter_state.currents:
self.__pv.currents.write(inverter_state.currents)


class InverterValueStoreBroker(ValueStore[InverterState]):
def __init__(self, component_num: int) -> None:
self.num = component_num
Expand Down Expand Up @@ -88,6 +71,4 @@ def fix_hybrid_values(self, state: InverterState) -> InverterState:


def get_inverter_value_store(component_num: int) -> PurgeInverterState:
return PurgeInverterState(LoggingValueStore(
(InverterValueStoreRamdisk if compatibility.is_ramdisk_in_use() else InverterValueStoreBroker)(component_num)
))
return PurgeInverterState(LoggingValueStore(InverterValueStoreBroker(component_num)))
Comment on lines 73 to +74
Empty file.
Loading