-
Notifications
You must be signed in to change notification settings - Fork 4
/
custom_attributes.py
55 lines (42 loc) · 1.22 KB
/
custom_attributes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# SPDX-FileCopyrightText: 2023 Alliander
#
# SPDX-License-Identifier: Apache-2.0
import json
from functools import cached_property
from pydantic import Field
from pydantic.dataclasses import dataclass
from pycgmes.resources.ACLineSegment import ACLineSegment
from pycgmes.utils.profile import BaseProfile, Profile
class CustomProfile(BaseProfile):
MYOWN = 100
@dataclass
class CustomAttribute(ACLineSegment):
colour: str = Field(
default="Red",
in_profiles=[
CustomProfile.MYOWN,
],
namespace="custom for colour",
)
structure: str = Field(
default="chewy",
in_profiles=[
CustomProfile.MYOWN,
],
# No namespace defined, it will use the class namespace.
)
@classmethod
def apparent_name(cls):
return cls.__base__.__name__
@cached_property
def namespace(self) -> str:
return "custom from class"
if __name__ == "__main__":
my_resource = CustomAttribute(colour="red")
print("Attributes in profile MYOWN:")
print(
json.dumps(
{qualname: attr for qualname, attr in my_resource.cgmes_attributes_in_profile(CustomProfile.MYOWN).items()},
indent=2,
)
)