2025-02-12 21:35:51 +01:00
|
|
|
"""Settings for energy management.
|
|
|
|
|
|
|
|
|
|
Kept in an extra module to avoid cyclic dependencies on package import.
|
|
|
|
|
"""
|
|
|
|
|
|
2025-10-28 02:50:31 +01:00
|
|
|
from enum import Enum
|
2026-03-13 15:48:43 +01:00
|
|
|
from typing import Optional, Union
|
2025-02-12 21:35:51 +01:00
|
|
|
|
|
|
|
|
from pydantic import Field
|
|
|
|
|
|
2026-03-13 15:48:43 +01:00
|
|
|
from akkudoktoreos.config.configabc import SettingsBaseModel, is_home_assistant_addon
|
2025-02-12 21:35:51 +01:00
|
|
|
|
|
|
|
|
|
2025-10-28 02:50:31 +01:00
|
|
|
class EnergyManagementMode(str, Enum):
|
|
|
|
|
"""Energy management mode."""
|
|
|
|
|
|
2026-03-13 15:48:43 +01:00
|
|
|
DISABLED = "DISABLED"
|
2025-10-28 02:50:31 +01:00
|
|
|
PREDICTION = "PREDICTION"
|
|
|
|
|
OPTIMIZATION = "OPTIMIZATION"
|
|
|
|
|
|
2026-03-13 15:48:43 +01:00
|
|
|
@classmethod
|
|
|
|
|
def is_valid(cls, mode: Union[str, "EnergyManagementMode"]) -> bool:
|
|
|
|
|
"""Check if value is a valid mode."""
|
|
|
|
|
try:
|
|
|
|
|
cls(mode)
|
|
|
|
|
return True
|
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_value(cls, value: str) -> Optional["EnergyManagementMode"]:
|
|
|
|
|
"""Safely convert string to enum, return None if invalid."""
|
|
|
|
|
try:
|
|
|
|
|
return cls(value)
|
|
|
|
|
except ValueError:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ems_default_mode() -> EnergyManagementMode:
|
|
|
|
|
"""Provide default EMS mode.
|
|
|
|
|
|
|
|
|
|
Returns OPTIMIZATION when running under Home Assistant, else DISABLED.
|
|
|
|
|
"""
|
|
|
|
|
if is_home_assistant_addon():
|
|
|
|
|
return EnergyManagementMode.OPTIMIZATION
|
|
|
|
|
return EnergyManagementMode.DISABLED
|
|
|
|
|
|
2025-10-28 02:50:31 +01:00
|
|
|
|
2025-02-12 21:35:51 +01:00
|
|
|
class EnergyManagementCommonSettings(SettingsBaseModel):
|
|
|
|
|
"""Energy Management Configuration."""
|
|
|
|
|
|
|
|
|
|
startup_delay: float = Field(
|
|
|
|
|
default=5,
|
|
|
|
|
ge=1,
|
2025-11-10 16:57:44 +01:00
|
|
|
json_schema_extra={
|
|
|
|
|
"description": "Startup delay in seconds for EOS energy management runs."
|
|
|
|
|
},
|
2025-02-12 21:35:51 +01:00
|
|
|
)
|
|
|
|
|
|
2026-02-22 14:12:42 +01:00
|
|
|
interval: float = Field(
|
|
|
|
|
default=300.0,
|
|
|
|
|
ge=60.0,
|
2025-11-10 16:57:44 +01:00
|
|
|
json_schema_extra={
|
2026-02-22 14:12:42 +01:00
|
|
|
"description": "Intervall between EOS energy management runs [seconds].",
|
2025-11-10 16:57:44 +01:00
|
|
|
"examples": ["300"],
|
|
|
|
|
},
|
2025-02-12 21:35:51 +01:00
|
|
|
)
|
2025-10-28 02:50:31 +01:00
|
|
|
|
2026-03-13 15:48:43 +01:00
|
|
|
mode: EnergyManagementMode = Field(
|
|
|
|
|
default_factory=ems_default_mode,
|
2025-11-10 16:57:44 +01:00
|
|
|
json_schema_extra={
|
2026-03-13 15:48:43 +01:00
|
|
|
"description": "Energy management mode [DISABLED | OPTIMIZATION | PREDICTION].",
|
2025-11-10 16:57:44 +01:00
|
|
|
"examples": ["OPTIMIZATION", "PREDICTION"],
|
|
|
|
|
},
|
2025-10-28 02:50:31 +01:00
|
|
|
)
|