Skip to content
8 changes: 8 additions & 0 deletions src/mesido/base_component_type_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def energy_system_components(self) -> Dict[str, str]:
"""
raise NotImplementedError

@property
@abstractmethod
def energy_system_owners(self) -> Dict[str, str]:
"""
This method return a dict with the components structured by owner.
"""
raise NotImplementedError

def energy_system_components_get(self, list_types: list) -> list:
components = []
for component_type in list_types:
Expand Down
31 changes: 30 additions & 1 deletion src/mesido/component_type_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ModelicaComponentTypeMixin(BaseComponentTypeMixin):
def __init__(self, *args, **kwargs):
super().__init__(**kwargs)
self.__hn_component_types = None
self.__owners = None

def pre(self):
"""
Expand Down Expand Up @@ -347,7 +348,13 @@ def energy_system_components(self) -> Dict[str, Set[str]]:

# Find the components in model, detection by string
# (name.component_type: type)
component_types = sorted({v for k, v in string_parameters.items()})
component_types = sorted(
{
v
for k, v in string_parameters.items()
if ("component_type" in k or "component_subtype" in k)
}
)

components = {}
for c in component_types:
Expand All @@ -359,6 +366,28 @@ def energy_system_components(self) -> Dict[str, Set[str]]:

return self.__hn_component_types

@property
def energy_system_owners(self):
if self.__owners is None:
# Create the dictionary once after that it will be available
string_parameters = self.string_parameters(0)

# Find the components in model, detection by string
# (name.component_type: type)
owners = sorted({v for k, v in string_parameters.items() if "owner" in k})

ownership_dict = {}
for c in owners:
ownership_dict[c] = sorted(
{k.split(".")[0] for k, v in string_parameters.items() if v == c}
)

ownership_dict.pop("__", None)

self.__owners = ownership_dict

return self.__owners

@property
def energy_system_topology(self) -> Topology:
"""
Expand Down
Loading