weheat 2024.11.1__py3-none-any.whl → 2025.11.24rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. weheat/__init__.py +6 -2
  2. weheat/abstractions/__init__.py +1 -1
  3. weheat/abstractions/discovery.py +11 -7
  4. weheat/abstractions/heat_pump.py +223 -81
  5. weheat/abstractions/user.py +16 -11
  6. weheat/api/__init__.py +1 -0
  7. weheat/api/energy_log_api.py +615 -127
  8. weheat/api/heat_pump_api.py +580 -374
  9. weheat/api/heat_pump_log_api.py +884 -360
  10. weheat/api/user_api.py +260 -115
  11. weheat/api_client.py +238 -265
  12. weheat/api_response.py +11 -15
  13. weheat/configuration.py +14 -9
  14. weheat/exceptions.py +59 -25
  15. weheat/models/__init__.py +8 -0
  16. weheat/models/boiler_type.py +8 -3
  17. weheat/models/device_state.py +9 -5
  18. weheat/models/dhw_type.py +8 -3
  19. weheat/models/energy_view_dto.py +87 -65
  20. weheat/models/heat_pump_log_view_dto.py +1394 -559
  21. weheat/models/heat_pump_model.py +8 -3
  22. weheat/models/heat_pump_status_enum.py +9 -4
  23. weheat/models/pagination_metadata.py +95 -0
  24. weheat/models/raw_heat_pump_log_dto.py +438 -375
  25. weheat/models/raw_heatpump_log_and_is_online_dto.py +578 -0
  26. weheat/models/read_all_heat_pump_dto.py +69 -53
  27. weheat/models/read_all_heat_pump_dto_paged_response.py +107 -0
  28. weheat/models/read_heat_pump_dto.py +64 -48
  29. weheat/models/read_user_dto.py +55 -37
  30. weheat/models/read_user_me_dto.py +124 -0
  31. weheat/models/role.py +10 -4
  32. weheat/models/total_energy_aggregate.py +111 -0
  33. weheat/rest.py +152 -259
  34. weheat-2025.11.24rc1.dist-info/METADATA +104 -0
  35. weheat-2025.11.24rc1.dist-info/RECORD +39 -0
  36. {weheat-2024.11.1.dist-info → weheat-2025.11.24rc1.dist-info}/WHEEL +1 -1
  37. weheat/abstractions/auth.py +0 -34
  38. weheat/models/heat_pump_type.py +0 -42
  39. weheat-2024.11.1.dist-info/METADATA +0 -107
  40. weheat-2024.11.1.dist-info/RECORD +0 -36
  41. {weheat-2024.11.1.dist-info → weheat-2025.11.24rc1.dist-info/licenses}/LICENSE +0 -0
  42. {weheat-2024.11.1.dist-info → weheat-2025.11.24rc1.dist-info}/top_level.txt +0 -0
@@ -18,103 +18,119 @@ import re # noqa: F401
18
18
  import json
19
19
 
20
20
  from datetime import datetime
21
- from typing import Optional
22
- from pydantic import BaseModel, Field, StrictStr, constr
21
+ from typing import Any, ClassVar, Dict, List, Optional
22
+ from pydantic import BaseModel, StrictStr
23
+ from pydantic import Field
24
+ from typing_extensions import Annotated
23
25
  from weheat.models.boiler_type import BoilerType
24
26
  from weheat.models.device_state import DeviceState
25
27
  from weheat.models.dhw_type import DhwType
26
28
  from weheat.models.heat_pump_model import HeatPumpModel
27
29
  from weheat.models.heat_pump_status_enum import HeatPumpStatusEnum
28
- from weheat.models.heat_pump_type import HeatPumpType
30
+ try:
31
+ from typing import Self
32
+ except ImportError:
33
+ from typing_extensions import Self
29
34
 
30
35
  class ReadAllHeatPumpDto(BaseModel):
31
36
  """
32
- Heat Pump dto used for the GetAll operation where the firmware version is needed # noqa: E501
33
- """
34
- id: StrictStr = Field(..., description="Identifier of the heat pump")
35
- control_board_id: StrictStr = Field(..., alias="controlBoardId", description="Identifier of the control board that is connected to the heat pump")
36
- serial_number: constr(strict=True, min_length=1) = Field(..., alias="serialNumber", description="Serial Number of this heat pump")
37
- part_number: Optional[StrictStr] = Field(None, alias="partNumber", description="Part Number of this heat pump")
38
- state: DeviceState = Field(...)
39
- name: Optional[StrictStr] = Field(None, description="Internal nickname of this heat pump")
37
+ Heat Pump dto used for the GetAll operation where the firmware version is needed
38
+ """ # noqa: E501
39
+ control_board_id: StrictStr = Field(description="Identifier of the control board that is connected to the heat pump", alias="controlBoardId")
40
+ name: Optional[StrictStr] = Field(default=None, description="Internal nickname of this heat pump")
40
41
  model: Optional[HeatPumpModel] = None
41
- dhw_type: Optional[DhwType] = Field(None, alias="dhwType")
42
- boiler_type: Optional[BoilerType] = Field(None, alias="boilerType")
42
+ dhw_type: Optional[DhwType] = Field(default=None, alias="dhwType")
43
+ boiler_type: Optional[BoilerType] = Field(default=None, alias="boilerType")
43
44
  status: Optional[HeatPumpStatusEnum] = None
44
- type: Optional[HeatPumpType] = None
45
- commissioned_at: Optional[datetime] = Field(None, alias="commissionedAt", description="Date when the heat pump was last commissioned (decommissioning sets this to null)")
46
- firmware_version: Optional[StrictStr] = Field(None, alias="firmwareVersion", description="Firmware version of control board connected to heat pump")
47
- __properties = ["id", "controlBoardId", "serialNumber", "partNumber", "state", "name", "model", "dhwType", "boilerType", "status", "type", "commissionedAt", "firmwareVersion"]
45
+ commissioned_at: Optional[datetime] = Field(default=None, description="Date when the heat pump was last commissioned (decommissioning sets this to null)", alias="commissionedAt")
46
+ serial_number: Annotated[str, Field(min_length=1, strict=True)] = Field(description="Serial Number of this heat pump", alias="serialNumber")
47
+ part_number: Optional[StrictStr] = Field(default=None, description="Part Number of this heat pump", alias="partNumber")
48
+ state: DeviceState
49
+ id: StrictStr = Field(description="Identifier of the heat pump")
50
+ firmware_version: Optional[StrictStr] = Field(default=None, description="Firmware version of control board connected to heat pump", alias="firmwareVersion")
51
+ __properties: ClassVar[List[str]] = ["controlBoardId", "name", "model", "dhwType", "boilerType", "status", "commissionedAt", "serialNumber", "partNumber", "state", "id", "firmwareVersion"]
52
+
53
+ model_config = {
54
+ "populate_by_name": True,
55
+ "validate_assignment": True,
56
+ "protected_namespaces": (),
57
+ }
48
58
 
49
- class Config:
50
- """Pydantic configuration"""
51
- allow_population_by_field_name = True
52
- validate_assignment = True
53
59
 
54
60
  def to_str(self) -> str:
55
61
  """Returns the string representation of the model using alias"""
56
- return pprint.pformat(self.dict(by_alias=True))
62
+ return pprint.pformat(self.model_dump(by_alias=True))
57
63
 
58
64
  def to_json(self) -> str:
59
65
  """Returns the JSON representation of the model using alias"""
66
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
60
67
  return json.dumps(self.to_dict())
61
68
 
62
69
  @classmethod
63
- def from_json(cls, json_str: str) -> ReadAllHeatPumpDto:
70
+ def from_json(cls, json_str: str) -> Self:
64
71
  """Create an instance of ReadAllHeatPumpDto from a JSON string"""
65
72
  return cls.from_dict(json.loads(json_str))
66
73
 
67
- def to_dict(self):
68
- """Returns the dictionary representation of the model using alias"""
69
- _dict = self.dict(by_alias=True,
70
- exclude={
71
- },
72
- exclude_none=True)
73
- # set to None if part_number (nullable) is None
74
- # and __fields_set__ contains the field
75
- if self.part_number is None and "part_number" in self.__fields_set__:
76
- _dict['partNumber'] = None
77
-
74
+ def to_dict(self) -> Dict[str, Any]:
75
+ """Return the dictionary representation of the model using alias.
76
+
77
+ This has the following differences from calling pydantic's
78
+ `self.model_dump(by_alias=True)`:
79
+
80
+ * `None` is only added to the output dict for nullable fields that
81
+ were set at model initialization. Other fields with value `None`
82
+ are ignored.
83
+ """
84
+ _dict = self.model_dump(
85
+ by_alias=True,
86
+ exclude={
87
+ },
88
+ exclude_none=True,
89
+ )
78
90
  # set to None if name (nullable) is None
79
- # and __fields_set__ contains the field
80
- if self.name is None and "name" in self.__fields_set__:
91
+ # and model_fields_set contains the field
92
+ if self.name is None and "name" in self.model_fields_set:
81
93
  _dict['name'] = None
82
94
 
83
95
  # set to None if commissioned_at (nullable) is None
84
- # and __fields_set__ contains the field
85
- if self.commissioned_at is None and "commissioned_at" in self.__fields_set__:
96
+ # and model_fields_set contains the field
97
+ if self.commissioned_at is None and "commissioned_at" in self.model_fields_set:
86
98
  _dict['commissionedAt'] = None
87
99
 
100
+ # set to None if part_number (nullable) is None
101
+ # and model_fields_set contains the field
102
+ if self.part_number is None and "part_number" in self.model_fields_set:
103
+ _dict['partNumber'] = None
104
+
88
105
  # set to None if firmware_version (nullable) is None
89
- # and __fields_set__ contains the field
90
- if self.firmware_version is None and "firmware_version" in self.__fields_set__:
106
+ # and model_fields_set contains the field
107
+ if self.firmware_version is None and "firmware_version" in self.model_fields_set:
91
108
  _dict['firmwareVersion'] = None
92
109
 
93
110
  return _dict
94
111
 
95
112
  @classmethod
96
- def from_dict(cls, obj: dict) -> ReadAllHeatPumpDto:
113
+ def from_dict(cls, obj: Dict) -> Self:
97
114
  """Create an instance of ReadAllHeatPumpDto from a dict"""
98
115
  if obj is None:
99
116
  return None
100
117
 
101
118
  if not isinstance(obj, dict):
102
- return ReadAllHeatPumpDto.parse_obj(obj)
119
+ return cls.model_validate(obj)
103
120
 
104
- _obj = ReadAllHeatPumpDto.parse_obj({
105
- "id": obj.get("id"),
106
- "control_board_id": obj.get("controlBoardId"),
107
- "serial_number": obj.get("serialNumber"),
108
- "part_number": obj.get("partNumber"),
109
- "state": obj.get("state"),
121
+ _obj = cls.model_validate({
122
+ "controlBoardId": obj.get("controlBoardId"),
110
123
  "name": obj.get("name"),
111
124
  "model": obj.get("model"),
112
- "dhw_type": obj.get("dhwType"),
113
- "boiler_type": obj.get("boilerType"),
125
+ "dhwType": obj.get("dhwType"),
126
+ "boilerType": obj.get("boilerType"),
114
127
  "status": obj.get("status"),
115
- "type": obj.get("type"),
116
- "commissioned_at": obj.get("commissionedAt"),
117
- "firmware_version": obj.get("firmwareVersion")
128
+ "commissionedAt": obj.get("commissionedAt"),
129
+ "serialNumber": obj.get("serialNumber"),
130
+ "partNumber": obj.get("partNumber"),
131
+ "state": obj.get("state"),
132
+ "id": obj.get("id"),
133
+ "firmwareVersion": obj.get("firmwareVersion")
118
134
  })
119
135
  return _obj
120
136
 
@@ -0,0 +1,107 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Weheat Backend
5
+
6
+ This is the backend for the Weheat project
7
+
8
+ The version of the OpenAPI document: v1
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+ import pprint
17
+ import re # noqa: F401
18
+ import json
19
+
20
+
21
+ from typing import Any, ClassVar, Dict, List, Optional
22
+ from pydantic import BaseModel
23
+ from weheat.models.pagination_metadata import PaginationMetadata
24
+ from weheat.models.read_all_heat_pump_dto import ReadAllHeatPumpDto
25
+ try:
26
+ from typing import Self
27
+ except ImportError:
28
+ from typing_extensions import Self
29
+
30
+ class ReadAllHeatPumpDtoPagedResponse(BaseModel):
31
+ """
32
+ ReadAllHeatPumpDtoPagedResponse
33
+ """ # noqa: E501
34
+ metadata: Optional[PaginationMetadata] = None
35
+ data: Optional[List[ReadAllHeatPumpDto]] = None
36
+ __properties: ClassVar[List[str]] = ["metadata", "data"]
37
+
38
+ model_config = {
39
+ "populate_by_name": True,
40
+ "validate_assignment": True,
41
+ "protected_namespaces": (),
42
+ }
43
+
44
+
45
+ def to_str(self) -> str:
46
+ """Returns the string representation of the model using alias"""
47
+ return pprint.pformat(self.model_dump(by_alias=True))
48
+
49
+ def to_json(self) -> str:
50
+ """Returns the JSON representation of the model using alias"""
51
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
52
+ return json.dumps(self.to_dict())
53
+
54
+ @classmethod
55
+ def from_json(cls, json_str: str) -> Self:
56
+ """Create an instance of ReadAllHeatPumpDtoPagedResponse from a JSON string"""
57
+ return cls.from_dict(json.loads(json_str))
58
+
59
+ def to_dict(self) -> Dict[str, Any]:
60
+ """Return the dictionary representation of the model using alias.
61
+
62
+ This has the following differences from calling pydantic's
63
+ `self.model_dump(by_alias=True)`:
64
+
65
+ * `None` is only added to the output dict for nullable fields that
66
+ were set at model initialization. Other fields with value `None`
67
+ are ignored.
68
+ """
69
+ _dict = self.model_dump(
70
+ by_alias=True,
71
+ exclude={
72
+ },
73
+ exclude_none=True,
74
+ )
75
+ # override the default output from pydantic by calling `to_dict()` of metadata
76
+ if self.metadata:
77
+ _dict['metadata'] = self.metadata.to_dict()
78
+ # override the default output from pydantic by calling `to_dict()` of each item in data (list)
79
+ _items = []
80
+ if self.data:
81
+ for _item in self.data:
82
+ if _item:
83
+ _items.append(_item.to_dict())
84
+ _dict['data'] = _items
85
+ # set to None if data (nullable) is None
86
+ # and model_fields_set contains the field
87
+ if self.data is None and "data" in self.model_fields_set:
88
+ _dict['data'] = None
89
+
90
+ return _dict
91
+
92
+ @classmethod
93
+ def from_dict(cls, obj: Dict) -> Self:
94
+ """Create an instance of ReadAllHeatPumpDtoPagedResponse from a dict"""
95
+ if obj is None:
96
+ return None
97
+
98
+ if not isinstance(obj, dict):
99
+ return cls.model_validate(obj)
100
+
101
+ _obj = cls.model_validate({
102
+ "metadata": PaginationMetadata.from_dict(obj.get("metadata")) if obj.get("metadata") is not None else None,
103
+ "data": [ReadAllHeatPumpDto.from_dict(_item) for _item in obj.get("data")] if obj.get("data") is not None else None
104
+ })
105
+ return _obj
106
+
107
+
@@ -18,96 +18,112 @@ import re # noqa: F401
18
18
  import json
19
19
 
20
20
  from datetime import datetime
21
- from typing import Optional
22
- from pydantic import BaseModel, Field, StrictStr, constr
21
+ from typing import Any, ClassVar, Dict, List, Optional
22
+ from pydantic import BaseModel, StrictStr
23
+ from pydantic import Field
24
+ from typing_extensions import Annotated
23
25
  from weheat.models.boiler_type import BoilerType
24
26
  from weheat.models.device_state import DeviceState
25
27
  from weheat.models.dhw_type import DhwType
26
28
  from weheat.models.heat_pump_model import HeatPumpModel
27
29
  from weheat.models.heat_pump_status_enum import HeatPumpStatusEnum
28
- from weheat.models.heat_pump_type import HeatPumpType
30
+ try:
31
+ from typing import Self
32
+ except ImportError:
33
+ from typing_extensions import Self
29
34
 
30
35
  class ReadHeatPumpDto(BaseModel):
31
36
  """
32
37
  ReadHeatPumpDto
33
- """
34
- id: StrictStr = Field(..., description="Identifier of the heat pump")
35
- control_board_id: StrictStr = Field(..., alias="controlBoardId", description="Identifier of the control board that is connected to the heat pump")
36
- serial_number: constr(strict=True, min_length=1) = Field(..., alias="serialNumber", description="Serial Number of this heat pump")
37
- part_number: Optional[StrictStr] = Field(None, alias="partNumber", description="Part Number of this heat pump")
38
- state: DeviceState = Field(...)
39
- name: Optional[StrictStr] = Field(None, description="Internal nickname of this heat pump")
38
+ """ # noqa: E501
39
+ control_board_id: StrictStr = Field(description="Identifier of the control board that is connected to the heat pump", alias="controlBoardId")
40
+ name: Optional[StrictStr] = Field(default=None, description="Internal nickname of this heat pump")
40
41
  model: Optional[HeatPumpModel] = None
41
- dhw_type: Optional[DhwType] = Field(None, alias="dhwType")
42
- boiler_type: Optional[BoilerType] = Field(None, alias="boilerType")
42
+ dhw_type: Optional[DhwType] = Field(default=None, alias="dhwType")
43
+ boiler_type: Optional[BoilerType] = Field(default=None, alias="boilerType")
43
44
  status: Optional[HeatPumpStatusEnum] = None
44
- type: Optional[HeatPumpType] = None
45
- commissioned_at: Optional[datetime] = Field(None, alias="commissionedAt", description="Date when the heat pump was last commissioned (decommissioning sets this to null)")
46
- __properties = ["id", "controlBoardId", "serialNumber", "partNumber", "state", "name", "model", "dhwType", "boilerType", "status", "type", "commissionedAt"]
45
+ commissioned_at: Optional[datetime] = Field(default=None, description="Date when the heat pump was last commissioned (decommissioning sets this to null)", alias="commissionedAt")
46
+ serial_number: Annotated[str, Field(min_length=1, strict=True)] = Field(description="Serial Number of this heat pump", alias="serialNumber")
47
+ part_number: Optional[StrictStr] = Field(default=None, description="Part Number of this heat pump", alias="partNumber")
48
+ state: DeviceState
49
+ id: StrictStr = Field(description="Identifier of the heat pump")
50
+ __properties: ClassVar[List[str]] = ["controlBoardId", "name", "model", "dhwType", "boilerType", "status", "commissionedAt", "serialNumber", "partNumber", "state", "id"]
51
+
52
+ model_config = {
53
+ "populate_by_name": True,
54
+ "validate_assignment": True,
55
+ "protected_namespaces": (),
56
+ }
47
57
 
48
- class Config:
49
- """Pydantic configuration"""
50
- allow_population_by_field_name = True
51
- validate_assignment = True
52
58
 
53
59
  def to_str(self) -> str:
54
60
  """Returns the string representation of the model using alias"""
55
- return pprint.pformat(self.dict(by_alias=True))
61
+ return pprint.pformat(self.model_dump(by_alias=True))
56
62
 
57
63
  def to_json(self) -> str:
58
64
  """Returns the JSON representation of the model using alias"""
65
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
59
66
  return json.dumps(self.to_dict())
60
67
 
61
68
  @classmethod
62
- def from_json(cls, json_str: str) -> ReadHeatPumpDto:
69
+ def from_json(cls, json_str: str) -> Self:
63
70
  """Create an instance of ReadHeatPumpDto from a JSON string"""
64
71
  return cls.from_dict(json.loads(json_str))
65
72
 
66
- def to_dict(self):
67
- """Returns the dictionary representation of the model using alias"""
68
- _dict = self.dict(by_alias=True,
69
- exclude={
70
- },
71
- exclude_none=True)
72
- # set to None if part_number (nullable) is None
73
- # and __fields_set__ contains the field
74
- if self.part_number is None and "part_number" in self.__fields_set__:
75
- _dict['partNumber'] = None
76
-
73
+ def to_dict(self) -> Dict[str, Any]:
74
+ """Return the dictionary representation of the model using alias.
75
+
76
+ This has the following differences from calling pydantic's
77
+ `self.model_dump(by_alias=True)`:
78
+
79
+ * `None` is only added to the output dict for nullable fields that
80
+ were set at model initialization. Other fields with value `None`
81
+ are ignored.
82
+ """
83
+ _dict = self.model_dump(
84
+ by_alias=True,
85
+ exclude={
86
+ },
87
+ exclude_none=True,
88
+ )
77
89
  # set to None if name (nullable) is None
78
- # and __fields_set__ contains the field
79
- if self.name is None and "name" in self.__fields_set__:
90
+ # and model_fields_set contains the field
91
+ if self.name is None and "name" in self.model_fields_set:
80
92
  _dict['name'] = None
81
93
 
82
94
  # set to None if commissioned_at (nullable) is None
83
- # and __fields_set__ contains the field
84
- if self.commissioned_at is None and "commissioned_at" in self.__fields_set__:
95
+ # and model_fields_set contains the field
96
+ if self.commissioned_at is None and "commissioned_at" in self.model_fields_set:
85
97
  _dict['commissionedAt'] = None
86
98
 
99
+ # set to None if part_number (nullable) is None
100
+ # and model_fields_set contains the field
101
+ if self.part_number is None and "part_number" in self.model_fields_set:
102
+ _dict['partNumber'] = None
103
+
87
104
  return _dict
88
105
 
89
106
  @classmethod
90
- def from_dict(cls, obj: dict) -> ReadHeatPumpDto:
107
+ def from_dict(cls, obj: Dict) -> Self:
91
108
  """Create an instance of ReadHeatPumpDto from a dict"""
92
109
  if obj is None:
93
110
  return None
94
111
 
95
112
  if not isinstance(obj, dict):
96
- return ReadHeatPumpDto.parse_obj(obj)
113
+ return cls.model_validate(obj)
97
114
 
98
- _obj = ReadHeatPumpDto.parse_obj({
99
- "id": obj.get("id"),
100
- "control_board_id": obj.get("controlBoardId"),
101
- "serial_number": obj.get("serialNumber"),
102
- "part_number": obj.get("partNumber"),
103
- "state": obj.get("state"),
115
+ _obj = cls.model_validate({
116
+ "controlBoardId": obj.get("controlBoardId"),
104
117
  "name": obj.get("name"),
105
118
  "model": obj.get("model"),
106
- "dhw_type": obj.get("dhwType"),
107
- "boiler_type": obj.get("boilerType"),
119
+ "dhwType": obj.get("dhwType"),
120
+ "boilerType": obj.get("boilerType"),
108
121
  "status": obj.get("status"),
109
- "type": obj.get("type"),
110
- "commissioned_at": obj.get("commissionedAt")
122
+ "commissionedAt": obj.get("commissionedAt"),
123
+ "serialNumber": obj.get("serialNumber"),
124
+ "partNumber": obj.get("partNumber"),
125
+ "state": obj.get("state"),
126
+ "id": obj.get("id")
111
127
  })
112
128
  return _obj
113
129
 
@@ -18,81 +18,99 @@ import re # noqa: F401
18
18
  import json
19
19
 
20
20
  from datetime import datetime
21
- from typing import Optional
22
- from pydantic import BaseModel, Field, StrictStr
21
+ from typing import Any, ClassVar, Dict, List, Optional
22
+ from pydantic import BaseModel, StrictStr
23
+ from pydantic import Field
23
24
  from weheat.models.role import Role
25
+ try:
26
+ from typing import Self
27
+ except ImportError:
28
+ from typing_extensions import Self
24
29
 
25
30
  class ReadUserDto(BaseModel):
26
31
  """
27
32
  ReadUserDto
28
- """
29
- id: StrictStr = Field(..., description="Identifier of the user")
30
- first_name: Optional[StrictStr] = Field(None, alias="firstName", description="First name of the user if available")
31
- last_name: Optional[StrictStr] = Field(None, alias="lastName", description="Last Name of the user if available")
32
- role: Role = Field(...)
33
- email: Optional[StrictStr] = Field(None, description="Email address of the user")
34
- updated_on: datetime = Field(..., alias="updatedOn", description="Timestamp of the last update to the user entry")
35
- created_on: datetime = Field(..., alias="createdOn", description="Timestamp of the creation of the user entry")
36
- __properties = ["id", "firstName", "lastName", "role", "email", "updatedOn", "createdOn"]
37
-
38
- class Config:
39
- """Pydantic configuration"""
40
- allow_population_by_field_name = True
41
- validate_assignment = True
33
+ """ # noqa: E501
34
+ id: StrictStr = Field(description="Identifier of the user")
35
+ first_name: Optional[StrictStr] = Field(default=None, description="First name of the user if available", alias="firstName")
36
+ last_name: Optional[StrictStr] = Field(default=None, description="Last Name of the user if available", alias="lastName")
37
+ role: Role
38
+ email: Optional[StrictStr] = Field(default=None, description="Email address of the user")
39
+ updated_on: datetime = Field(description="Timestamp of the last update to the user entry", alias="updatedOn")
40
+ created_on: datetime = Field(description="Timestamp of the creation of the user entry", alias="createdOn")
41
+ __properties: ClassVar[List[str]] = ["id", "firstName", "lastName", "role", "email", "updatedOn", "createdOn"]
42
+
43
+ model_config = {
44
+ "populate_by_name": True,
45
+ "validate_assignment": True,
46
+ "protected_namespaces": (),
47
+ }
48
+
42
49
 
43
50
  def to_str(self) -> str:
44
51
  """Returns the string representation of the model using alias"""
45
- return pprint.pformat(self.dict(by_alias=True))
52
+ return pprint.pformat(self.model_dump(by_alias=True))
46
53
 
47
54
  def to_json(self) -> str:
48
55
  """Returns the JSON representation of the model using alias"""
56
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49
57
  return json.dumps(self.to_dict())
50
58
 
51
59
  @classmethod
52
- def from_json(cls, json_str: str) -> ReadUserDto:
60
+ def from_json(cls, json_str: str) -> Self:
53
61
  """Create an instance of ReadUserDto from a JSON string"""
54
62
  return cls.from_dict(json.loads(json_str))
55
63
 
56
- def to_dict(self):
57
- """Returns the dictionary representation of the model using alias"""
58
- _dict = self.dict(by_alias=True,
59
- exclude={
60
- },
61
- exclude_none=True)
64
+ def to_dict(self) -> Dict[str, Any]:
65
+ """Return the dictionary representation of the model using alias.
66
+
67
+ This has the following differences from calling pydantic's
68
+ `self.model_dump(by_alias=True)`:
69
+
70
+ * `None` is only added to the output dict for nullable fields that
71
+ were set at model initialization. Other fields with value `None`
72
+ are ignored.
73
+ """
74
+ _dict = self.model_dump(
75
+ by_alias=True,
76
+ exclude={
77
+ },
78
+ exclude_none=True,
79
+ )
62
80
  # set to None if first_name (nullable) is None
63
- # and __fields_set__ contains the field
64
- if self.first_name is None and "first_name" in self.__fields_set__:
81
+ # and model_fields_set contains the field
82
+ if self.first_name is None and "first_name" in self.model_fields_set:
65
83
  _dict['firstName'] = None
66
84
 
67
85
  # set to None if last_name (nullable) is None
68
- # and __fields_set__ contains the field
69
- if self.last_name is None and "last_name" in self.__fields_set__:
86
+ # and model_fields_set contains the field
87
+ if self.last_name is None and "last_name" in self.model_fields_set:
70
88
  _dict['lastName'] = None
71
89
 
72
90
  # set to None if email (nullable) is None
73
- # and __fields_set__ contains the field
74
- if self.email is None and "email" in self.__fields_set__:
91
+ # and model_fields_set contains the field
92
+ if self.email is None and "email" in self.model_fields_set:
75
93
  _dict['email'] = None
76
94
 
77
95
  return _dict
78
96
 
79
97
  @classmethod
80
- def from_dict(cls, obj: dict) -> ReadUserDto:
98
+ def from_dict(cls, obj: Dict) -> Self:
81
99
  """Create an instance of ReadUserDto from a dict"""
82
100
  if obj is None:
83
101
  return None
84
102
 
85
103
  if not isinstance(obj, dict):
86
- return ReadUserDto.parse_obj(obj)
104
+ return cls.model_validate(obj)
87
105
 
88
- _obj = ReadUserDto.parse_obj({
106
+ _obj = cls.model_validate({
89
107
  "id": obj.get("id"),
90
- "first_name": obj.get("firstName"),
91
- "last_name": obj.get("lastName"),
108
+ "firstName": obj.get("firstName"),
109
+ "lastName": obj.get("lastName"),
92
110
  "role": obj.get("role"),
93
111
  "email": obj.get("email"),
94
- "updated_on": obj.get("updatedOn"),
95
- "created_on": obj.get("createdOn")
112
+ "updatedOn": obj.get("updatedOn"),
113
+ "createdOn": obj.get("createdOn")
96
114
  })
97
115
  return _obj
98
116