mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-10-11 11:56:17 +00:00
Some checks failed
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 logging configuration issues that made logging stop operation. Switch to Loguru logging (from Python logging). Enable console and file logging with different log levels. Add logging documentation. * Fix logging configuration and EOS configuration out of sync. Added tracking support for nested value updates of Pydantic models. This used to update the logging configuration when the EOS configurationm for logging is changed. Should keep logging config and EOS config in sync as long as all changes to the EOS logging configuration are done by set_nested_value(), which is the case for the REST API. * Fix energy management task looping endlessly after the second update when trying to update the last_update datetime. * Fix get_nested_value() to correctly take values from the dicts in a Pydantic model instance. * Fix usage of model classes instead of model instances in nested value access when evaluation the value type that is associated to each key. * Fix illegal json format in prediction documentation for PVForecastAkkudoktor provider. * Fix documentation qirks and add EOS Connect to integrations. * Support deprecated fields in configuration in documentation generation and EOSdash. * Enhance EOSdash demo to show BrightSky humidity data (that is often missing) * Update documentation reference to German EOS installation videos. Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
76 lines
3.0 KiB
Python
76 lines
3.0 KiB
Python
"""Retrieves elecprice forecast data from an import file.
|
|
|
|
This module provides classes and mappings to manage elecprice data obtained from
|
|
an import file, including support for various elecprice attributes such as temperature,
|
|
humidity, cloud cover, and solar irradiance. The data is mapped to the `ElecPriceDataRecord`
|
|
format, enabling consistent access to forecasted and historical elecprice attributes.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from typing import Optional, Union
|
|
|
|
from loguru import logger
|
|
from pydantic import Field, field_validator
|
|
|
|
from akkudoktoreos.config.configabc import SettingsBaseModel
|
|
from akkudoktoreos.prediction.elecpriceabc import ElecPriceProvider
|
|
from akkudoktoreos.prediction.predictionabc import PredictionImportProvider
|
|
|
|
|
|
class ElecPriceImportCommonSettings(SettingsBaseModel):
|
|
"""Common settings for elecprice data import from file or JSON String."""
|
|
|
|
import_file_path: Optional[Union[str, Path]] = Field(
|
|
default=None,
|
|
description="Path to the file to import elecprice data from.",
|
|
examples=[None, "/path/to/prices.json"],
|
|
)
|
|
|
|
import_json: Optional[str] = Field(
|
|
default=None,
|
|
description="JSON string, dictionary of electricity price forecast value lists.",
|
|
examples=['{"elecprice_marketprice_wh": [0.0003384, 0.0003318, 0.0003284]}'],
|
|
)
|
|
|
|
# Validators
|
|
@field_validator("import_file_path", mode="after")
|
|
@classmethod
|
|
def validate_import_file_path(cls, value: Optional[Union[str, Path]]) -> Optional[Path]:
|
|
if value is None:
|
|
return None
|
|
if isinstance(value, str):
|
|
value = Path(value)
|
|
"""Ensure file is available."""
|
|
value.resolve()
|
|
if not value.is_file():
|
|
raise ValueError(f"Import file path '{value}' is not a file.")
|
|
return value
|
|
|
|
|
|
class ElecPriceImport(ElecPriceProvider, PredictionImportProvider):
|
|
"""Fetch PV forecast data from import file or JSON string.
|
|
|
|
ElecPriceImport is a singleton-based class that retrieves elecprice forecast data
|
|
from a file or JSON string and maps it to `ElecPriceDataRecord` fields. It manages the forecast
|
|
over a range of hours into the future and retains historical data.
|
|
"""
|
|
|
|
@classmethod
|
|
def provider_id(cls) -> str:
|
|
"""Return the unique identifier for the ElecPriceImport provider."""
|
|
return "ElecPriceImport"
|
|
|
|
def _update_data(self, force_update: Optional[bool] = False) -> None:
|
|
if self.config.elecprice.provider_settings is None:
|
|
logger.debug(f"{self.provider_id()} data update without provider settings.")
|
|
return
|
|
if self.config.elecprice.provider_settings.import_file_path:
|
|
self.import_from_file(
|
|
self.config.elecprice.provider_settings.import_file_path,
|
|
key_prefix="elecprice",
|
|
)
|
|
if self.config.elecprice.provider_settings.import_json:
|
|
self.import_from_json(
|
|
self.config.elecprice.provider_settings.import_json, key_prefix="elecprice"
|
|
)
|