Skip to content

Commit

Permalink
fix simcount data including nan for home consumption (openWB#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
LKuemmel authored Jul 25, 2024
1 parent dbd5c62 commit 5c9cb4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/helpermodules/utils/topic_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ def get_index(topic: str) -> str:
"""
regex = re.search('(?!/)([0-9]*)(?=/|$)', topic)
if regex is None:
raise Exception(f"Couldn't find index in {topic}")
raise ValueError(f"Couldn't find index in {topic}")
return regex.group()


def get_index_position(topic: str) -> int:
regex = re.search('(?!/)([0-9]*)(?=/|$)', topic)
if regex is None:
raise Exception(f"Couldn't find index in {topic}")
raise ValueError(f"Couldn't find index in {topic}")
return regex.end()


Expand All @@ -24,14 +24,14 @@ def get_second_index(topic: str) -> str:
"""
regex = re.search('^.+/([0-9]*)/.+/([0-9]+)/*.*$', topic)
if regex is None:
raise Exception(f"Couldn't find index in {topic}")
raise ValueError(f"Couldn't find index in {topic}")
return regex.group(2)


def get_second_index_position(topic: str) -> int:
regex = re.search('^.+/([0-9]*)/.+/([0-9]+)/*.*$', topic)
if regex is None:
raise Exception(f"Couldn't find index in {topic}")
raise ValueError(f"Couldn't find index in {topic}")
return regex.end(2)


Expand Down
20 changes: 14 additions & 6 deletions packages/modules/common/simcount/_simcounter_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,20 @@ def save(self, prefix: str, topic: str, state: SimCounterState):


def restore_last_energy(topic: str, value: str):
device_id = get_index(topic)
component_id = get_second_index(topic)
module_type = type_to_topic_mapping(
data.data.system_data[f"device{device_id}"].components[f"component{component_id}"].component_config.type)
module = getattr(data.data, f"{module_type}_data")[f"{module_type}{get_second_index(topic)}"].data.get
return getattr(module, value)
try:
device_id = get_index(topic)
component_id = get_second_index(topic)
module_type = type_to_topic_mapping(
data.data.system_data[f"device{device_id}"].components[f"component{component_id}"].component_config.type)
module = getattr(data.data, f"{module_type}_data")[f"{module_type}{get_second_index(topic)}"].data.get
return getattr(module, value)
except ValueError:
# Wenn kein Index enthalten, ist es Hausverbrauch.
if value == "exported":
# wird beim Hausverbrauch nicht ausgewertet.
return 0
elif value == "imported":
return data.data.counter_all_data.data.set.imported_home_consumption


def get_sim_counter_store() -> SimCounterStore:
Expand Down

0 comments on commit 5c9cb4e

Please sign in to comment.