Coverage for backend/common/src/common/config_types.py: 100%
72 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-05-13 02:47 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-05-13 02:47 +0000
1from enum import StrEnum
2from typing import Mapping, Union
3from pydantic import BaseModel, Field, RootModel, ConfigDict
4from pydantic.json_schema import SkipJsonSchema
5from typing import Literal, Tuple, Dict, List, Any
8PropertyPackageKey = str
9PortKey = str
11Transformer = Literal["inverse"]
13class PropertyType(BaseModel):
14 """
15 - propertySetGroup:
16 key of the property set group. If not specified, the property
17 will be added to the default property set group.
18 - value:
19 default value of the property. If not specified, the value will
20 be set to empty.
21 - unit:
22 default unit of the property. If not specified, the unit will
23 be set to the default unit of the unit type.
24 - unit_type (Required):
25 type of the unit (temperature, pressure, etc.) or "dimensionless" for no unit
26 - description:
27 description of the property
28 - type (Required):
29 type of the property (numeric, dropdown, checkbox, segmented, text, numeric_arg)
30 """
31 propertySetGroup: str = Field(default="default", description="Property set group")
32 displayName: str = Field(..., description="Display name of the property")
33 indexSets: List[str] | None = Field(default=None, description="Index sets of the property")
34 sumToOne: bool = Field(default=False, description="Flag indicating whether the property should sum to one. If true, the last instance of the first index set will be calcualted from the others. See compound_propogation.py")
35 value: Union[int, float,bool,str,List[str],None] = Field(default=None, description="Default value of the property")
36 unit: str | None= Field(default=None, description="Default unit of the property")
37 unitType: str = Field(..., description="Type of the unit")
38 description: str | None = Field(default=None, description="Description of the property")
39 type: Literal["numeric", "dropdown", "checkbox", "segmented", "text", "numeric_arg"] = Field(..., description="Type of the property")
40 many: bool = Field(default=False, description="Flag indicating whether there are multiple properties by this key")
41 default: int = Field(default=1, description="Default number of properties if many=True")
42 options: Dict[str, str] = Field(default={}, description="Options for the dropdown property. Key is the value, value is the display name")
43 hasTimeIndex: bool = Field(default=True, description="Flag indicating whether the property has a time index.")
46class PropertiesType(RootModel):
47 root: Dict[str, PropertyType]
49 def __iter__(self):
50 return iter(self.root)
52 def __getitem__(self, key):
53 return self.root[key]
55 def get(self, key, default=None):
56 return self.root.get(key, default)
58 def items(self):
59 return self.root.items()
61 def keys(self):
62 return self.root.keys()
64class ConType(StrEnum):
65 Inlet = "inlet"
66 Outlet = "outlet"
67 Branch = "branch"
70class PropertySetType(BaseModel):
71 type: Literal["All", "None", "composition", "stateVars", "exceptLast"]
72 displayName: str = Field(..., description="Display name of the property set")
73 stateVars: Tuple[str, ...] = Field(default=(), description="State variables of the property set")
74 toggle: str | None = Field(default=None, description="Key of property that is used to enable/disable the property set. Must be within the property set group.")
77class PortType(BaseModel):
78 displayName: str = Field(..., description="Display name of the port")
79 type: ConType = Field(..., description="Type of the port")
80 streamType: str = Field(default="stream", description="Type of the stream e.g stream, energy_stream")
81 many: bool = Field(default=False, description="Flag indicating whether the port can have multiple connections")
82 default: int = Field(default=1, description="Amount of ports to create if many=True")
83 minimum: int = Field(default=1, description="Minimum amount of ports if many=True")
84 makeStream: bool = Field(default=True, description="Flag indicating whether the port is a power stream port")
85 streamOffset: float = Field(default=0.75, description="Offset in grid units from unit opp to stream")
86 streamName: str = Field(default="Stream", description="default name of the stream")
90class GraphicObjectType(BaseModel):
91 width: float = Field(..., description="Width of the object")
92 height: float = Field(..., description="Height of the object")
93 autoHeight: bool = Field(False, description="Flag indicating whether the height should be automatically adjusted based on number of ports")
96class ObjectType(BaseModel):
97 model_config = ConfigDict(arbitrary_types_allowed=True)
99 displayType: str = Field(..., description="Display type of the object")
100 displayName: str | None = Field(
101 default=None, description="Display name of the object"
102 )
103 ports: Mapping[PortKey, PortType] | None = Field(None, description="Ports contained in the object")
104 graphicObject: GraphicObjectType = Field(..., description="Graphic object of the object")
105 indexSets: List[str] = Field(default=[], description="Index sets of the object")
106 properties: PropertiesType = Field(None, description="Properties of the object")
107 propertySetGroups: Dict[str, PropertySetType] = Field({}, description="Property set groups of the object")
108 propertyPackagePorts: Dict[str, List[PortKey]] | None = Field(None, description="Which ports are used by which property packages")
109 is_stream: bool = Field(default=False, description="Flag indicating whether the object is a stream")
110 info: str | None= Field(default=None, description="Info about the object")
111 keyProperties: List[str] | Dict[str, List[str]] = Field(None, description="Key properties of the object")
112 splitter_fraction_name: str | None = Field(default=None, description="Property for configuring outlet names for indexed items")
114 idaes_adapter: SkipJsonSchema[Any] = Field(
115 default=None,
116 exclude=True,
117 description="Django-side IDAES serialisation definition for this object type.",
118 )