feat: make home assistant add-on run optimization by default (#940)

When running as Home Assistant add-on the only viable usage is running with
cyclic optimization. Make this the default to als propvide a better experience
for first time users. The optimization will start with demo data, which also
helps to configure Akkudoktor-EOS to the personal usage.

The disabling of the automatic energy management is now an explicit mode
"DISABLED".

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
Bobby Noelte
2026-03-13 15:48:43 +01:00
committed by GitHub
parent 8a9aec6d57
commit b67148c47f
12 changed files with 81 additions and 44 deletions
+33 -5
View File
@@ -4,19 +4,47 @@ Kept in an extra module to avoid cyclic dependencies on package import.
"""
from enum import Enum
from typing import Optional
from typing import Optional, Union
from pydantic import Field
from akkudoktoreos.config.configabc import SettingsBaseModel
from akkudoktoreos.config.configabc import SettingsBaseModel, is_home_assistant_addon
class EnergyManagementMode(str, Enum):
"""Energy management mode."""
DISABLED = "DISABLED"
PREDICTION = "PREDICTION"
OPTIMIZATION = "OPTIMIZATION"
@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
class EnergyManagementCommonSettings(SettingsBaseModel):
"""Energy Management Configuration."""
@@ -38,10 +66,10 @@ class EnergyManagementCommonSettings(SettingsBaseModel):
},
)
mode: Optional[EnergyManagementMode] = Field(
default=None,
mode: EnergyManagementMode = Field(
default_factory=ems_default_mode,
json_schema_extra={
"description": "Energy management mode [OPTIMIZATION | PREDICTION].",
"description": "Energy management mode [DISABLED | OPTIMIZATION | PREDICTION].",
"examples": ["OPTIMIZATION", "PREDICTION"],
},
)