55from __future__ import annotations
66
77from enum import Enum
8- from typing import Any , Dict , List , Optional , Union
8+ from typing import Dict , List , Optional , Union
99from typing_extensions import Annotated
1010
11- from pydantic import BaseModel , BeforeValidator , ConfigDict , Field , RootModel , conint , field_serializer
11+ from pydantic import (
12+ BaseModel ,
13+ BeforeValidator ,
14+ ConfigDict ,
15+ Field ,
16+ RootModel ,
17+ field_serializer ,
18+ )
1219
1320
1421class PayloadType (str , Enum ):
15- U8 = ' uint8'
16- S8 = ' int8'
17- U16 = ' uint16'
18- S16 = ' int16'
19- U32 = ' uint32'
20- S32 = ' int32'
21- U64 = ' uint64'
22- S64 = ' int64'
23- Float = ' float32'
22+ U8 = " uint8"
23+ S8 = " int8"
24+ U16 = " uint16"
25+ S16 = " int16"
26+ U32 = " uint32"
27+ S32 = " int32"
28+ U64 = " uint64"
29+ S64 = " int64"
30+ Float = " float32"
2431
2532
2633class Access (Enum ):
27- Read = ' Read'
28- Write = ' Write'
29- Event = ' Event'
34+ Read = " Read"
35+ Write = " Write"
36+ Event = " Event"
3037
3138
3239class MaskValueItem (BaseModel ):
3340 model_config = ConfigDict (
34- extra = ' forbid' ,
41+ extra = " forbid" ,
3542 )
36- value : int = Field (..., description = ' Specifies the numerical mask value.' )
43+ value : int = Field (..., description = " Specifies the numerical mask value." )
3744 description : Optional [str ] = Field (
38- None , description = ' Specifies a summary description of the mask value function.'
45+ None , description = " Specifies a summary description of the mask value function."
3946 )
4047
4148 def __int__ (self ):
@@ -48,70 +55,70 @@ class MaskValue(RootModel[Union[int, MaskValueItem]]):
4855
4956class BitMask (BaseModel ):
5057 description : Optional [str ] = Field (
51- None , description = ' Specifies a summary description of the bit mask function.'
58+ None , description = " Specifies a summary description of the bit mask function."
5259 )
5360 bits : Dict [str , MaskValue ]
5461
5562
5663class GroupMask (BaseModel ):
5764 description : Optional [str ] = Field (
58- None , description = ' Specifies a summary description of the group mask function.'
65+ None , description = " Specifies a summary description of the group mask function."
5966 )
6067 values : Dict [str , MaskValue ]
6168
6269
6370class MaskType (RootModel [str ]):
6471 root : str = Field (
6572 ...,
66- description = ' Specifies the name of the bit mask or group mask used to represent the payload value.' ,
73+ description = " Specifies the name of the bit mask or group mask used to represent the payload value." ,
6774 )
6875
6976
7077class InterfaceType (RootModel [str ]):
7178 root : str = Field (
7279 ...,
73- description = ' Specifies the name of the type used to represent the payload value in the high-level interface.' ,
80+ description = " Specifies the name of the type used to represent the payload value in the high-level interface." ,
7481 )
7582
7683
7784class Converter (Enum ):
78- None_ = ' None'
79- Payload = ' Payload'
80- RawPayload = ' RawPayload'
85+ None_ = " None"
86+ Payload = " Payload"
87+ RawPayload = " RawPayload"
8188
8289
8390class MinValue (RootModel [float ]):
8491 root : float = Field (
8592 ...,
86- description = ' Specifies the minimum allowable value for the payload or payload member.' ,
93+ description = " Specifies the minimum allowable value for the payload or payload member." ,
8794 )
8895
8996
9097class MaxValue (RootModel [float ]):
9198 root : float = Field (
9299 ...,
93- description = ' Specifies the maximum allowable value for the payload or payload member.' ,
100+ description = " Specifies the maximum allowable value for the payload or payload member." ,
94101 )
95102
96103
97104class DefaultValue (RootModel [float ]):
98105 root : float = Field (
99106 ...,
100- description = ' Specifies the default value for the payload or payload member.' ,
107+ description = " Specifies the default value for the payload or payload member." ,
101108 )
102109
103110
104111class PayloadMember (BaseModel ):
105112 mask : Optional [int ] = Field (
106113 None ,
107- description = ' Specifies the mask used to read and write this payload member.' ,
114+ description = " Specifies the mask used to read and write this payload member." ,
108115 )
109116 offset : Optional [int ] = Field (
110117 None ,
111- description = ' Specifies the payload array offset where this payload member is stored.' ,
118+ description = " Specifies the payload array offset where this payload member is stored." ,
112119 )
113120 description : Optional [str ] = Field (
114- None , description = ' Specifies a summary description of the payload member.'
121+ None , description = " Specifies a summary description of the payload member."
115122 )
116123 minValue : Optional [MinValue ] = None
117124 maxValue : Optional [MaxValue ] = None
@@ -122,68 +129,74 @@ class PayloadMember(BaseModel):
122129
123130
124131class Visibility (Enum ):
125- public = ' public'
126- private = ' private'
132+ public = " public"
133+ private = " private"
127134
128135
129136class Register (BaseModel ):
130- address : conint (le = 255 ) = Field (
131- ..., description = 'Specifies the unique 8-bit address of the register.'
132- )
137+ address : Annotated [
138+ int ,
139+ Field (
140+ le = 255 , description = "Specifies the unique 8-bit address of the register."
141+ ),
142+ ]
133143 type : Annotated [PayloadType , BeforeValidator (lambda v : PayloadType [v ])]
134- length : Optional [conint (ge = 1 )] = Field (
135- default = 1 , description = 'Specifies the length of the register payload.'
136- )
144+ length : Annotated [
145+ Optional [int ],
146+ Field (
147+ ge = 1 , default = 1 , description = "Specifies the length of the register payload."
148+ ),
149+ ]
137150 access : Union [Access , List [Access ]] = Field (
138- ..., description = ' Specifies the expected use of the register.'
151+ ..., description = " Specifies the expected use of the register."
139152 )
140153 description : Optional [str ] = Field (
141- None , description = ' Specifies a summary description of the register function.'
154+ None , description = " Specifies a summary description of the register function."
142155 )
143156 minValue : Optional [MinValue ] = None
144157 maxValue : Optional [MaxValue ] = None
145158 defaultValue : Optional [DefaultValue ] = None
146159 maskType : Optional [MaskType ] = None
147160 visibility : Optional [Visibility ] = Field (
148161 None ,
149- description = ' Specifies whether the register function is exposed in the high-level interface.' ,
162+ description = " Specifies whether the register function is exposed in the high-level interface." ,
150163 )
151164 volatile : Optional [bool ] = Field (
152165 None ,
153- description = ' Specifies whether register values can be saved in non-volatile memory.' ,
166+ description = " Specifies whether register values can be saved in non-volatile memory." ,
154167 )
155168 payloadSpec : Optional [Dict [str , PayloadMember ]] = None
156169 interfaceType : Optional [InterfaceType ] = None
157170 converter : Optional [Converter ] = None
158171
159- @field_serializer (' type' )
172+ @field_serializer (" type" )
160173 def _serialize_type (self , type : PayloadType ):
161174 return type .name
162175
163176
164177class Registers (BaseModel ):
165178 registers : Dict [str , Register ] = Field (
166179 ...,
167- description = ' Specifies the collection of registers implementing the device function.' ,
180+ description = " Specifies the collection of registers implementing the device function." ,
168181 )
169182 bitMasks : Optional [Dict [str , BitMask ]] = Field (
170183 None ,
171- description = ' Specifies the collection of masks available to be used with the different registers.' ,
184+ description = " Specifies the collection of masks available to be used with the different registers." ,
172185 )
173186 groupMasks : Optional [Dict [str , GroupMask ]] = Field (
174187 None ,
175- description = ' Specifies the collection of group masks available to be used with the different registers.' ,
188+ description = " Specifies the collection of group masks available to be used with the different registers." ,
176189 )
177190
178191
179192class Model (Registers ):
180- device : str = Field (..., description = ' Specifies the name of the device.' )
193+ device : str = Field (..., description = " Specifies the name of the device." )
181194 whoAmI : int = Field (
182- ..., description = ' Specifies the unique identifier for this device type.'
195+ ..., description = " Specifies the unique identifier for this device type."
183196 )
184197 firmwareVersion : str = Field (
185- ..., description = ' Specifies the semantic version of the device firmware.'
198+ ..., description = " Specifies the semantic version of the device firmware."
186199 )
187200 hardwareTargets : str = Field (
188- ..., description = ' Specifies the semantic version of the device hardware.'
201+ ..., description = " Specifies the semantic version of the device hardware."
189202 )
0 commit comments