Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions packages/modules/devices/sonnen/sonnenbatterie/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,23 @@ def update_inverter(self, sim_counter: SimCounter) -> InverterState:
return InverterState(exported=exported,
power=pv_power)
else:
return self.__state_from_channel(
inverter_state = self.__state_from_channel(
self.__read_power_meter(direction=self.PowerMeterDirection.PRODUCTION)[0])
# meter value is updated way too slow, so we use a sim counter to get the exported energy
_, inverter_state.exported = sim_counter.sim_count(inverter_state.power)
return inverter_state

def update_consumption_counter(self) -> CounterState:
def update_consumption_counter(self, sim_counter: SimCounter) -> CounterState:
"""
Updates the consumption counter state by reading data from the JSON API.
Returns:
CounterState: The updated consumption counter state.
"""
return self.__state_from_channel(
counter_state = self.__state_from_channel(
self.__read_power_meter(direction=self.PowerMeterDirection.CONSUMPTION)[0])
# meter value is updated way too slow, so we use a sim counter to get the im-/exported energy
counter_state.imported, counter_state.exported = sim_counter.sim_count(counter_state.power)
return counter_state

def set_power_limit(self, power_limit: Optional[int]) -> None:
if self.power_limit_controllable() is False:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from modules.common.abstract_device import AbstractCounter
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
from modules.common.simcount import SimCounter
from modules.common.store import get_counter_value_store

from modules.devices.sonnen.sonnenbatterie.api import JsonApi, JsonApiVersion
Expand All @@ -25,22 +26,23 @@ def __init__(self, component_config: SonnenbatterieConsumptionCounterSetup, **kw
self.kwargs: KwargsDict = kwargs

def initialize(self) -> None:
self.__device_id: int = self.kwargs['device_id']
self.__device_address: str = self.kwargs['device_address']
self.__device_variant: int = self.kwargs['device_variant']
self.__api_v2_token: Optional[str] = self.kwargs['device_api_v2_token']
if self.__device_variant in [0, 1, 2]:
raise ValueError("Die ausgewählte API bietet keine Verbrauchsdaten!")
if self.__device_variant != 3:
raise ValueError("Unbekannte API: " + str(self.__device_variant))

self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="consumption")
self.store = get_counter_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
self.api = JsonApi(host=self.__device_address,
api_version=JsonApiVersion.V2,
auth_token=self.__api_v2_token)

def update(self) -> None:
self.store.set(self.api.update_consumption_counter())
self.store.set(self.api.update_consumption_counter(sim_counter=self.sim_counter))


component_descriptor = ComponentDescriptor(configuration_factory=SonnenbatterieConsumptionCounterSetup)
1 change: 1 addition & 0 deletions packages/modules/devices/sonnen/sonnenbatterie/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def create_evu_counter_component(component_config: SonnenbatterieCounterSetup):

def create_consumption_counter_component(component_config: SonnenbatterieConsumptionCounterSetup):
return SonnenbatterieConsumptionCounter(component_config,
device_id=device_config.id,
device_address=device_config.configuration.ip_address,
device_variant=device_config.configuration.variant,
device_api_v2_token=device_config.configuration.api_v2_token)
Expand Down