mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-06-11 05:56:17 +00:00
fix: optimization fail after restart (#1007)
Some checks failed
Bump Version / Bump Version Workflow (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
Some checks failed
Bump Version / Bump Version Workflow (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
Fix documentation for the loadforecast_power_w key. Fix documentation to explain the usage of import file/ JSON string to primarily initialise prediction data. Fix code scanning alert no. 6: URL redirection from remote source Enable to automatically save the configuration to the configuration file by default, which is a widespread user expectation. Make the genetic parameters non optional for better pydantic compliance. Update: - bump pytest to 9.0.3 - bump pillow to 12.2.0 - bump platformdirs to 4.9.6 - bump typespyyaml to 6.0.12.20260408 - bump tzfpy to 1.2.0 - bump pydantic to 2.13.0 - bump types-requests to 2.33.0.20260408 Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com> Co-authored-by: Normann <github@koldrack.com>
This commit is contained in:
@@ -23,7 +23,11 @@ from pydantic import Field, computed_field, field_validator
|
||||
|
||||
# settings
|
||||
from akkudoktoreos.adapter.adapter import AdapterCommonSettings
|
||||
from akkudoktoreos.config.configabc import SettingsBaseModel, is_home_assistant_addon
|
||||
from akkudoktoreos.config.configabc import (
|
||||
ConfigSaveMode,
|
||||
SettingsBaseModel,
|
||||
is_home_assistant_addon,
|
||||
)
|
||||
from akkudoktoreos.config.configmigrate import migrate_config_data, migrate_config_file
|
||||
from akkudoktoreos.core.cachesettings import CacheCommonSettings
|
||||
from akkudoktoreos.core.coreabc import SingletonMixin
|
||||
@@ -117,6 +121,26 @@ def default_data_folder_path() -> Path:
|
||||
class GeneralSettings(SettingsBaseModel):
|
||||
"""General settings."""
|
||||
|
||||
config_save_mode: ConfigSaveMode = Field(
|
||||
default=ConfigSaveMode.AUTOMATIC,
|
||||
json_schema_extra={
|
||||
"description": (
|
||||
"Configuration file save mode for configuration changes "
|
||||
"['MANUAL', 'AUTOMATIC']. Defaults to 'AUTOMATIC'."
|
||||
),
|
||||
},
|
||||
examples=["AUTOMATIC", "MANUAL"],
|
||||
)
|
||||
|
||||
config_save_interval_sec: int = Field(
|
||||
default=60,
|
||||
ge=5,
|
||||
json_schema_extra={
|
||||
"description": ("Automatic configuration file saving interval [seconds]."),
|
||||
"examples": [60],
|
||||
},
|
||||
)
|
||||
|
||||
home_assistant_addon: bool = Field(
|
||||
default_factory=is_home_assistant_addon,
|
||||
json_schema_extra={"description": "EOS is running as home assistant add-on."},
|
||||
@@ -359,6 +383,7 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
|
||||
"with_file_secret_settings": True,
|
||||
}
|
||||
_config_file_path: ClassVar[Optional[Path]] = None
|
||||
_config_autosave: ClassVar[str] = ""
|
||||
_force_documentation_mode = False
|
||||
|
||||
def __hash__(self) -> int:
|
||||
@@ -1003,6 +1028,20 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
|
||||
raise ValueError("Configuration file path unknown.")
|
||||
with self.general.config_file_path.open("w", encoding="utf-8", newline="\n") as f_out:
|
||||
f_out.write(self.to_config_json())
|
||||
logger.info(f"Saved configuration to '{self.general.config_file_path}'.")
|
||||
|
||||
def autosave(self) -> None:
|
||||
"""Saves the current configuration if AUTOMATIC save mode is configured.
|
||||
|
||||
Tries to avoid save operation if there are no changes between last and actual save.
|
||||
"""
|
||||
if self.general.config_save_mode != ConfigSaveMode.AUTOMATIC:
|
||||
return
|
||||
|
||||
config_str = self.to_config_json()
|
||||
if config_str != ConfigEOS._config_autosave:
|
||||
self.to_config_file()
|
||||
ConfigEOS._config_autosave = config_str
|
||||
|
||||
def update(self) -> None:
|
||||
"""Updates all configuration fields.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import calendar
|
||||
import os
|
||||
import sys
|
||||
from enum import StrEnum
|
||||
from typing import Any, ClassVar, Iterator, Optional, Union
|
||||
|
||||
import numpy as np
|
||||
@@ -20,6 +21,13 @@ from akkudoktoreos.utils.datetimeutil import (
|
||||
)
|
||||
|
||||
|
||||
class ConfigSaveMode(StrEnum):
|
||||
"""Configuration file save mode."""
|
||||
|
||||
AUTOMATIC = "AUTOMATIC"
|
||||
MANUAL = "MANUAL"
|
||||
|
||||
|
||||
def is_home_assistant_addon() -> bool:
|
||||
"""Detect Home Assistant add-on environment.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user