mirror of
				https://github.com/Akkudoktor-EOS/EOS.git
				synced 2025-11-04 08:46:20 +00:00 
			
		
		
		
	Nested config, devices registry
* All config now nested.
    - Use default config from model field default values. If providers
      should be enabled by default, non-empty default config file could
      be provided again.
    - Environment variable support with EOS_ prefix and __ between levels,
      e.g. EOS_SERVER__EOS_SERVER_PORT=8503 where all values are case
      insensitive.
      For more information see:
      https://docs.pydantic.dev/latest/concepts/pydantic_settings/#parsing-environment-variable-values
    - Use devices as registry for configured devices. DeviceBase as base
      class with for now just initializion support (in the future expand
      to operations during optimization).
    - Strip down ConfigEOS to the only configuration instance. Reload
      from file or reset to defaults is possible.
 * Fix multi-initialization of derived SingletonMixin classes.
			
			
This commit is contained in:
		@@ -329,9 +329,9 @@ class CacheFileStore(ConfigMixin, metaclass=CacheFileStoreMeta):
 | 
			
		||||
                # File already available
 | 
			
		||||
                cache_file_obj = cache_item.cache_file
 | 
			
		||||
            else:
 | 
			
		||||
                self.config.data_cache_path.mkdir(parents=True, exist_ok=True)
 | 
			
		||||
                self.config.general.data_cache_path.mkdir(parents=True, exist_ok=True)
 | 
			
		||||
                cache_file_obj = tempfile.NamedTemporaryFile(
 | 
			
		||||
                    mode=mode, delete=delete, suffix=suffix, dir=self.config.data_cache_path
 | 
			
		||||
                    mode=mode, delete=delete, suffix=suffix, dir=self.config.general.data_cache_path
 | 
			
		||||
                )
 | 
			
		||||
                self._store[cache_file_key] = CacheFileRecord(
 | 
			
		||||
                    cache_file=cache_file_obj,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
import json
 | 
			
		||||
from typing import Any
 | 
			
		||||
from typing import Any, Optional
 | 
			
		||||
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
@@ -9,6 +9,14 @@ from akkudoktoreos.core.logging import get_logger
 | 
			
		||||
logger = get_logger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class classproperty(property):
 | 
			
		||||
    def __get__(self, _: Any, owner_cls: Optional[type[Any]] = None) -> Any:
 | 
			
		||||
        if owner_cls is None:
 | 
			
		||||
            return self
 | 
			
		||||
        assert self.fget is not None
 | 
			
		||||
        return self.fget(owner_cls)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class UtilsCommonSettings(SettingsBaseModel):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -34,7 +34,7 @@ class VisualizationReport(ConfigMixin):
 | 
			
		||||
        self.pdf_pages = PdfPages(filename, metadata={})  # Initialize PdfPages without metadata
 | 
			
		||||
        self.version = version  # overwrite version as test for constant output of pdf for test
 | 
			
		||||
        self.current_time = to_datetime(
 | 
			
		||||
            as_string="YYYY-MM-DD HH:mm:ss", in_timezone=self.config.timezone
 | 
			
		||||
            as_string="YYYY-MM-DD HH:mm:ss", in_timezone=self.config.prediction.timezone
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def add_chart_to_group(self, chart_func: Callable[[], None]) -> None:
 | 
			
		||||
@@ -51,7 +51,7 @@ class VisualizationReport(ConfigMixin):
 | 
			
		||||
 | 
			
		||||
    def _initialize_pdf(self) -> None:
 | 
			
		||||
        """Create the output directory if it doesn't exist and initialize the PDF."""
 | 
			
		||||
        output_dir = self.config.data_output_path
 | 
			
		||||
        output_dir = self.config.general.data_output_path
 | 
			
		||||
 | 
			
		||||
        # If self.filename is already a valid path, use it; otherwise, combine it with output_dir
 | 
			
		||||
        if os.path.isabs(self.filename):
 | 
			
		||||
@@ -173,7 +173,7 @@ class VisualizationReport(ConfigMixin):
 | 
			
		||||
            plt.grid(True)
 | 
			
		||||
 | 
			
		||||
            # Add vertical line for the current date if within the axis range
 | 
			
		||||
            current_time = pendulum.now(self.config.timezone)
 | 
			
		||||
            current_time = pendulum.now(self.config.prediction.timezone)
 | 
			
		||||
            if timestamps[0].subtract(hours=2) <= current_time <= timestamps[-1]:
 | 
			
		||||
                plt.axvline(current_time, color="r", linestyle="--", label="Now")
 | 
			
		||||
                plt.text(current_time, plt.ylim()[1], "Now", color="r", ha="center", va="bottom")
 | 
			
		||||
@@ -419,7 +419,7 @@ def prepare_visualize(
 | 
			
		||||
    start_hour: Optional[int] = 0,
 | 
			
		||||
) -> None:
 | 
			
		||||
    report = VisualizationReport(filename)
 | 
			
		||||
    next_full_hour_date = pendulum.now(report.config.timezone).start_of("hour").add(hours=1)
 | 
			
		||||
    next_full_hour_date = pendulum.now(report.config.prediction.timezone).start_of("hour").add(hours=1)
 | 
			
		||||
    # Group 1:
 | 
			
		||||
    report.create_line_chart_date(
 | 
			
		||||
        next_full_hour_date,  # start_date
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user