Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/modules/devices/sonnen/sonnenbatterie/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ class JsonApiVersion(Enum):

class JsonApi():
class OperatingMode(Enum):
# only define modes we can override savely
MANUAL = "1"
SELF_CONSUMPTION = "2"
# MODULE_EXTENSION = "6"
TIME_OF_USE = "10"
# OPTIMIZATION = "11"

class PowerMeterDirection(Enum):
PRODUCTION = "production"
Expand Down Expand Up @@ -447,12 +450,18 @@ def set_power_limit(self, power_limit: Optional[int]) -> None:
configurations = self.__get_configurations()
if "EM_OperatingMode" not in configurations:
raise KeyError("The key 'EM_OperatingMode' is missing in the API response.")
try:
self.OperatingMode(configurations["EM_OperatingMode"])
except ValueError:
raise ValueError("Aktive Speichersteuerung wird in "
f"Betriebsmodus {configurations['EM_OperatingMode']} "
"nicht unterstützt.")
if self.default_operating_mode is None:
# Store the default operating mode for later restoration
self.default_operating_mode = self.OperatingMode(configurations["EM_OperatingMode"])
log.debug(f"default_operating_mode set to: {self.default_operating_mode}")

operating_mode = self.OperatingMode(configurations["EM_OperatingMode"])

if power_limit is None:
# No specific power limit is set, activating default mode to allow the system to optimize energy usage by it
# self.
Expand Down