1515from .util import parse_dptype , remap_value
1616
1717
18- @dataclass
18+ @dataclass ( kw_only = True )
1919class TypeInformation :
2020 """Type information.
2121
2222 As provided by the SDK, from `device.function` / `device.status_range`.
2323 """
2424
2525 dpcode : DPCode
26+ type_data : str | None = None
2627
2728 @classmethod
28- def from_json (cls , dpcode : DPCode , data : str ) -> Self | None :
29+ def from_json (cls , dpcode : DPCode , type_data : str ) -> Self | None :
2930 """Load JSON string and return a TypeInformation object."""
30- return cls (dpcode )
31+ return cls (dpcode = dpcode , type_data = type_data )
3132
3233
33- @dataclass
34+ @dataclass ( kw_only = True )
3435class IntegerTypeData (TypeInformation ):
3536 """Integer Type Data."""
3637
@@ -84,13 +85,14 @@ def remap_value_from(
8485 return remap_value (value , from_min , from_max , self .min , self .max , reverse )
8586
8687 @classmethod
87- def from_json (cls , dpcode : DPCode , data : str ) -> Self | None :
88+ def from_json (cls , dpcode : DPCode , type_data : str ) -> Self | None :
8889 """Load JSON string and return a IntegerTypeData object."""
89- if not (parsed := cast (dict [str , Any ] | None , json_loads_object (data ))):
90+ if not (parsed := cast (dict [str , Any ] | None , json_loads_object (type_data ))):
9091 return None
9192
9293 return cls (
93- dpcode ,
94+ dpcode = dpcode ,
95+ type_data = type_data ,
9496 min = int (parsed ["min" ]),
9597 max = int (parsed ["max" ]),
9698 scale = int (parsed ["scale" ]),
@@ -99,32 +101,40 @@ def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
99101 )
100102
101103
102- @dataclass
104+ @dataclass ( kw_only = True )
103105class BitmapTypeInformation (TypeInformation ):
104106 """Bitmap type information."""
105107
106108 label : list [str ]
107109
108110 @classmethod
109- def from_json (cls , dpcode : DPCode , data : str ) -> Self | None :
111+ def from_json (cls , dpcode : DPCode , type_data : str ) -> Self | None :
110112 """Load JSON string and return a BitmapTypeInformation object."""
111- if not (parsed := json_loads_object (data )):
113+ if not (parsed := json_loads_object (type_data )):
112114 return None
113- return cls (dpcode , ** cast (dict [str , list [str ]], parsed ))
115+ return cls (
116+ dpcode = dpcode ,
117+ type_data = type_data ,
118+ ** cast (dict [str , list [str ]], parsed ),
119+ )
114120
115121
116- @dataclass
122+ @dataclass ( kw_only = True )
117123class EnumTypeData (TypeInformation ):
118124 """Enum Type Data."""
119125
120126 range : list [str ]
121127
122128 @classmethod
123- def from_json (cls , dpcode : DPCode , data : str ) -> Self | None :
129+ def from_json (cls , dpcode : DPCode , type_data : str ) -> Self | None :
124130 """Load JSON string and return a EnumTypeData object."""
125- if not (parsed := json_loads_object (data )):
131+ if not (parsed := json_loads_object (type_data )):
126132 return None
127- return cls (dpcode , ** cast (dict [str , list [str ]], parsed ))
133+ return cls (
134+ dpcode = dpcode ,
135+ type_data = type_data ,
136+ ** cast (dict [str , list [str ]], parsed ),
137+ )
128138
129139
130140_TYPE_INFORMATION_MAPPINGS : dict [DPType , type [TypeInformation ]] = {
@@ -147,7 +157,7 @@ class DPCodeWrapper(ABC):
147157 native_unit : str | None = None
148158 suggested_unit : str | None = None
149159
150- def __init__ (self , dpcode : str ) -> None :
160+ def __init__ (self , dpcode : DPCode ) -> None :
151161 """Init DPCodeWrapper."""
152162 self .dpcode = dpcode
153163
@@ -190,7 +200,7 @@ class DPCodeTypeInformationWrapper[T: TypeInformation](DPCodeWrapper):
190200 DPTYPE : DPType
191201 type_information : T
192202
193- def __init__ (self , dpcode : str , type_information : T ) -> None :
203+ def __init__ (self , dpcode : DPCode , type_information : T ) -> None :
194204 """Init DPCodeWrapper."""
195205 super ().__init__ (dpcode )
196206 self .type_information = type_information
@@ -297,7 +307,7 @@ class DPCodeIntegerWrapper(DPCodeTypeInformationWrapper[IntegerTypeData]):
297307
298308 DPTYPE = DPType .INTEGER
299309
300- def __init__ (self , dpcode : str , type_information : IntegerTypeData ) -> None :
310+ def __init__ (self , dpcode : DPCode , type_information : IntegerTypeData ) -> None :
301311 """Init DPCodeIntegerWrapper."""
302312 super ().__init__ (dpcode , type_information )
303313 self .native_unit = type_information .unit
@@ -327,7 +337,7 @@ def _convert_value_to_raw_value(self, device: CustomerDevice, value: Any) -> Any
327337class DPCodeBitmapBitWrapper (DPCodeWrapper ):
328338 """Simple wrapper for a specific bit in bitmap values."""
329339
330- def __init__ (self , dpcode : str , mask : int ) -> None :
340+ def __init__ (self , dpcode : DPCode , mask : int ) -> None :
331341 """Init DPCodeBitmapWrapper."""
332342 super ().__init__ (dpcode )
333343 self ._mask = mask
@@ -428,7 +438,7 @@ def find_dpcode(
428438 and parse_dptype (current_definition .type ) is dptype
429439 and (
430440 type_information := type_information_cls .from_json (
431- dpcode , current_definition .values
441+ dpcode = dpcode , type_data = current_definition .values
432442 )
433443 )
434444 ):
0 commit comments