weheat 2025.1.14rc1__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.

Potentially problematic release.


This version of weheat might be problematic. Click here for more details.

weheat/api_response.py ADDED
@@ -0,0 +1,29 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Any, Dict, Optional
5
+
6
+ try:
7
+ from pydantic.v1 import Field, StrictInt, StrictStr
8
+ except ImportError:
9
+ from pydantic import Field, StrictInt, StrictStr
10
+
11
+ class ApiResponse:
12
+ """
13
+ API response object
14
+ """
15
+
16
+ status_code: Optional[StrictInt] = Field(None, description="HTTP status code")
17
+ headers: Optional[Dict[StrictStr, StrictStr]] = Field(None, description="HTTP headers")
18
+ data: Optional[Any] = Field(None, description="Deserialized data given the data type")
19
+ raw_data: Optional[Any] = Field(None, description="Raw data (HTTP response body)")
20
+
21
+ def __init__(self,
22
+ status_code=None,
23
+ headers=None,
24
+ data=None,
25
+ raw_data=None) -> None:
26
+ self.status_code = status_code
27
+ self.headers = headers
28
+ self.data = data
29
+ self.raw_data = raw_data
@@ -0,0 +1,442 @@
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
+ import copy
16
+ import logging
17
+ import multiprocessing
18
+ import sys
19
+ import urllib3
20
+
21
+ import http.client as httplib
22
+
23
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
24
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
25
+ 'minimum', 'exclusiveMinimum', 'maxLength',
26
+ 'minLength', 'pattern', 'maxItems', 'minItems'
27
+ }
28
+
29
+ class Configuration:
30
+ """This class contains various settings of the API client.
31
+
32
+ :param host: Base url.
33
+ :param api_key: Dict to store API key(s).
34
+ Each entry in the dict specifies an API key.
35
+ The dict key is the name of the security scheme in the OAS specification.
36
+ The dict value is the API key secret.
37
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
38
+ The dict key is the name of the security scheme in the OAS specification.
39
+ The dict value is an API key prefix when generating the auth data.
40
+ :param username: Username for HTTP basic authentication.
41
+ :param password: Password for HTTP basic authentication.
42
+ :param access_token: Access token.
43
+ :param server_index: Index to servers configuration.
44
+ :param server_variables: Mapping with string values to replace variables in
45
+ templated server configuration. The validation of enums is performed for
46
+ variables with defined enum values before.
47
+ :param server_operation_index: Mapping from operation ID to an index to server
48
+ configuration.
49
+ :param server_operation_variables: Mapping from operation ID to a mapping with
50
+ string values to replace variables in templated server configuration.
51
+ The validation of enums is performed for variables with defined enum
52
+ values before.
53
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
54
+ in PEM format.
55
+
56
+ :Example:
57
+ """
58
+
59
+ _default = None
60
+
61
+ def __init__(self, host=None,
62
+ api_key=None, api_key_prefix=None,
63
+ username=None, password=None,
64
+ access_token=None,
65
+ server_index=None, server_variables=None,
66
+ server_operation_index=None, server_operation_variables=None,
67
+ ssl_ca_cert=None,
68
+ ) -> None:
69
+ """Constructor
70
+ """
71
+ self._base_path = "http://localhost" if host is None else host
72
+ """Default Base url
73
+ """
74
+ self.server_index = 0 if server_index is None and host is None else server_index
75
+ self.server_operation_index = server_operation_index or {}
76
+ """Default server index
77
+ """
78
+ self.server_variables = server_variables or {}
79
+ self.server_operation_variables = server_operation_variables or {}
80
+ """Default server variables
81
+ """
82
+ self.temp_folder_path = None
83
+ """Temp file folder for downloading files
84
+ """
85
+ # Authentication Settings
86
+ self.api_key = {}
87
+ if api_key:
88
+ self.api_key = api_key
89
+ """dict to store API key(s)
90
+ """
91
+ self.api_key_prefix = {}
92
+ if api_key_prefix:
93
+ self.api_key_prefix = api_key_prefix
94
+ """dict to store API prefix (e.g. Bearer)
95
+ """
96
+ self.refresh_api_key_hook = None
97
+ """function hook to refresh API key if expired
98
+ """
99
+ self.username = username
100
+ """Username for HTTP basic authentication
101
+ """
102
+ self.password = password
103
+ """Password for HTTP basic authentication
104
+ """
105
+ self.access_token = access_token
106
+ """Access token
107
+ """
108
+ self.logger = {}
109
+ """Logging Settings
110
+ """
111
+ self.logger["package_logger"] = logging.getLogger("weheat")
112
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
113
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
114
+ """Log format
115
+ """
116
+ self.logger_stream_handler = None
117
+ """Log stream handler
118
+ """
119
+ self.logger_file_handler = None
120
+ """Log file handler
121
+ """
122
+ self.logger_file = None
123
+ """Debug file location
124
+ """
125
+ self.debug = False
126
+ """Debug switch
127
+ """
128
+
129
+ self.verify_ssl = True
130
+ """SSL/TLS verification
131
+ Set this to false to skip verifying SSL certificate when calling API
132
+ from https server.
133
+ """
134
+ self.ssl_ca_cert = ssl_ca_cert
135
+ """Set this to customize the certificate file to verify the peer.
136
+ """
137
+ self.cert_file = None
138
+ """client certificate file
139
+ """
140
+ self.key_file = None
141
+ """client key file
142
+ """
143
+ self.assert_hostname = None
144
+ """Set this to True/False to enable/disable SSL hostname verification.
145
+ """
146
+ self.tls_server_name = None
147
+ """SSL/TLS Server Name Indication (SNI)
148
+ Set this to the SNI value expected by the server.
149
+ """
150
+
151
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
152
+ """urllib3 connection pool's maximum number of connections saved
153
+ per pool. urllib3 uses 1 connection as default value, but this is
154
+ not the best value when you are making a lot of possibly parallel
155
+ requests to the same host, which is often the case here.
156
+ cpu_count * 5 is used as default value to increase performance.
157
+ """
158
+
159
+ self.proxy = None
160
+ """Proxy URL
161
+ """
162
+ self.proxy_headers = None
163
+ """Proxy headers
164
+ """
165
+ self.safe_chars_for_path_param = ''
166
+ """Safe chars for path_param
167
+ """
168
+ self.retries = None
169
+ """Adding retries to override urllib3 default value 3
170
+ """
171
+ # Enable client side validation
172
+ self.client_side_validation = True
173
+
174
+ self.socket_options = None
175
+ """Options to pass down to the underlying urllib3 socket
176
+ """
177
+
178
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
179
+ """datetime format
180
+ """
181
+
182
+ self.date_format = "%Y-%m-%d"
183
+ """date format
184
+ """
185
+
186
+ def __deepcopy__(self, memo):
187
+ cls = self.__class__
188
+ result = cls.__new__(cls)
189
+ memo[id(self)] = result
190
+ for k, v in self.__dict__.items():
191
+ if k not in ('logger', 'logger_file_handler'):
192
+ setattr(result, k, copy.deepcopy(v, memo))
193
+ # shallow copy of loggers
194
+ result.logger = copy.copy(self.logger)
195
+ # use setters to configure loggers
196
+ result.logger_file = self.logger_file
197
+ result.debug = self.debug
198
+ return result
199
+
200
+ def __setattr__(self, name, value):
201
+ object.__setattr__(self, name, value)
202
+
203
+ @classmethod
204
+ def set_default(cls, default):
205
+ """Set default instance of configuration.
206
+
207
+ It stores default configuration, which can be
208
+ returned by get_default_copy method.
209
+
210
+ :param default: object of Configuration
211
+ """
212
+ cls._default = default
213
+
214
+ @classmethod
215
+ def get_default_copy(cls):
216
+ """Deprecated. Please use `get_default` instead.
217
+
218
+ Deprecated. Please use `get_default` instead.
219
+
220
+ :return: The configuration object.
221
+ """
222
+ return cls.get_default()
223
+
224
+ @classmethod
225
+ def get_default(cls):
226
+ """Return the default configuration.
227
+
228
+ This method returns newly created, based on default constructor,
229
+ object of Configuration class or returns a copy of default
230
+ configuration.
231
+
232
+ :return: The configuration object.
233
+ """
234
+ if cls._default is None:
235
+ cls._default = Configuration()
236
+ return cls._default
237
+
238
+ @property
239
+ def logger_file(self):
240
+ """The logger file.
241
+
242
+ If the logger_file is None, then add stream handler and remove file
243
+ handler. Otherwise, add file handler and remove stream handler.
244
+
245
+ :param value: The logger_file path.
246
+ :type: str
247
+ """
248
+ return self.__logger_file
249
+
250
+ @logger_file.setter
251
+ def logger_file(self, value):
252
+ """The logger file.
253
+
254
+ If the logger_file is None, then add stream handler and remove file
255
+ handler. Otherwise, add file handler and remove stream handler.
256
+
257
+ :param value: The logger_file path.
258
+ :type: str
259
+ """
260
+ self.__logger_file = value
261
+ if self.__logger_file:
262
+ # If set logging file,
263
+ # then add file handler and remove stream handler.
264
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
265
+ self.logger_file_handler.setFormatter(self.logger_formatter)
266
+ for _, logger in self.logger.items():
267
+ logger.addHandler(self.logger_file_handler)
268
+
269
+ @property
270
+ def debug(self):
271
+ """Debug status
272
+
273
+ :param value: The debug status, True or False.
274
+ :type: bool
275
+ """
276
+ return self.__debug
277
+
278
+ @debug.setter
279
+ def debug(self, value):
280
+ """Debug status
281
+
282
+ :param value: The debug status, True or False.
283
+ :type: bool
284
+ """
285
+ self.__debug = value
286
+ if self.__debug:
287
+ # if debug status is True, turn on debug logging
288
+ for _, logger in self.logger.items():
289
+ logger.setLevel(logging.DEBUG)
290
+ # turn on httplib debug
291
+ httplib.HTTPConnection.debuglevel = 1
292
+ else:
293
+ # if debug status is False, turn off debug logging,
294
+ # setting log level to default `logging.WARNING`
295
+ for _, logger in self.logger.items():
296
+ logger.setLevel(logging.WARNING)
297
+ # turn off httplib debug
298
+ httplib.HTTPConnection.debuglevel = 0
299
+
300
+ @property
301
+ def logger_format(self):
302
+ """The logger format.
303
+
304
+ The logger_formatter will be updated when sets logger_format.
305
+
306
+ :param value: The format string.
307
+ :type: str
308
+ """
309
+ return self.__logger_format
310
+
311
+ @logger_format.setter
312
+ def logger_format(self, value):
313
+ """The logger format.
314
+
315
+ The logger_formatter will be updated when sets logger_format.
316
+
317
+ :param value: The format string.
318
+ :type: str
319
+ """
320
+ self.__logger_format = value
321
+ self.logger_formatter = logging.Formatter(self.__logger_format)
322
+
323
+ def get_api_key_with_prefix(self, identifier, alias=None):
324
+ """Gets API key (with prefix if set).
325
+
326
+ :param identifier: The identifier of apiKey.
327
+ :param alias: The alternative identifier of apiKey.
328
+ :return: The token for api key authentication.
329
+ """
330
+ if self.refresh_api_key_hook is not None:
331
+ self.refresh_api_key_hook(self)
332
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
333
+ if key:
334
+ prefix = self.api_key_prefix.get(identifier)
335
+ if prefix:
336
+ return "%s %s" % (prefix, key)
337
+ else:
338
+ return key
339
+
340
+ def get_basic_auth_token(self):
341
+ """Gets HTTP basic authentication header (string).
342
+
343
+ :return: The token for basic HTTP authentication.
344
+ """
345
+ username = ""
346
+ if self.username is not None:
347
+ username = self.username
348
+ password = ""
349
+ if self.password is not None:
350
+ password = self.password
351
+ return urllib3.util.make_headers(
352
+ basic_auth=username + ':' + password
353
+ ).get('authorization')
354
+
355
+ def auth_settings(self):
356
+ """Gets Auth Settings dict for api client.
357
+
358
+ :return: The Auth Settings information dict.
359
+ """
360
+ auth = {}
361
+ if self.access_token is not None:
362
+ auth['oauth2'] = {
363
+ 'type': 'oauth2',
364
+ 'in': 'header',
365
+ 'key': 'Authorization',
366
+ 'value': 'Bearer ' + self.access_token
367
+ }
368
+ return auth
369
+
370
+ def to_debug_report(self):
371
+ """Gets the essential information for debugging.
372
+
373
+ :return: The report for debugging.
374
+ """
375
+ return "Python SDK Debug Report:\n"\
376
+ "OS: {env}\n"\
377
+ "Python Version: {pyversion}\n"\
378
+ "Version of the API: v1\n"\
379
+ "SDK Package Version: 2024.07.08".\
380
+ format(env=sys.platform, pyversion=sys.version)
381
+
382
+ def get_host_settings(self):
383
+ """Gets an array of host settings
384
+
385
+ :return: An array of host settings
386
+ """
387
+ return [
388
+ {
389
+ 'url': "",
390
+ 'description': "No description provided",
391
+ }
392
+ ]
393
+
394
+ def get_host_from_settings(self, index, variables=None, servers=None):
395
+ """Gets host URL based on the index and variables
396
+ :param index: array index of the host settings
397
+ :param variables: hash of variable and the corresponding value
398
+ :param servers: an array of host settings or None
399
+ :return: URL based on host settings
400
+ """
401
+ if index is None:
402
+ return self._base_path
403
+
404
+ variables = {} if variables is None else variables
405
+ servers = self.get_host_settings() if servers is None else servers
406
+
407
+ try:
408
+ server = servers[index]
409
+ except IndexError:
410
+ raise ValueError(
411
+ "Invalid index {0} when selecting the host settings. "
412
+ "Must be less than {1}".format(index, len(servers)))
413
+
414
+ url = server['url']
415
+
416
+ # go through variables and replace placeholders
417
+ for variable_name, variable in server.get('variables', {}).items():
418
+ used_value = variables.get(
419
+ variable_name, variable['default_value'])
420
+
421
+ if 'enum_values' in variable \
422
+ and used_value not in variable['enum_values']:
423
+ raise ValueError(
424
+ "The variable `{0}` in the host URL has invalid value "
425
+ "{1}. Must be {2}.".format(
426
+ variable_name, variables[variable_name],
427
+ variable['enum_values']))
428
+
429
+ url = url.replace("{" + variable_name + "}", used_value)
430
+
431
+ return url
432
+
433
+ @property
434
+ def host(self):
435
+ """Return generated host."""
436
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
437
+
438
+ @host.setter
439
+ def host(self, value):
440
+ """Fix base path."""
441
+ self._base_path = value
442
+ self.server_index = None
weheat/exceptions.py ADDED
@@ -0,0 +1,166 @@
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
+ class OpenApiException(Exception):
16
+ """The base exception class for all OpenAPIExceptions"""
17
+
18
+
19
+ class ApiTypeError(OpenApiException, TypeError):
20
+ def __init__(self, msg, path_to_item=None, valid_classes=None,
21
+ key_type=None) -> None:
22
+ """ Raises an exception for TypeErrors
23
+
24
+ Args:
25
+ msg (str): the exception message
26
+
27
+ Keyword Args:
28
+ path_to_item (list): a list of keys an indices to get to the
29
+ current_item
30
+ None if unset
31
+ valid_classes (tuple): the primitive classes that current item
32
+ should be an instance of
33
+ None if unset
34
+ key_type (bool): False if our value is a value in a dict
35
+ True if it is a key in a dict
36
+ False if our item is an item in a list
37
+ None if unset
38
+ """
39
+ self.path_to_item = path_to_item
40
+ self.valid_classes = valid_classes
41
+ self.key_type = key_type
42
+ full_msg = msg
43
+ if path_to_item:
44
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
45
+ super(ApiTypeError, self).__init__(full_msg)
46
+
47
+
48
+ class ApiValueError(OpenApiException, ValueError):
49
+ def __init__(self, msg, path_to_item=None) -> None:
50
+ """
51
+ Args:
52
+ msg (str): the exception message
53
+
54
+ Keyword Args:
55
+ path_to_item (list) the path to the exception in the
56
+ received_data dict. None if unset
57
+ """
58
+
59
+ self.path_to_item = path_to_item
60
+ full_msg = msg
61
+ if path_to_item:
62
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
63
+ super(ApiValueError, self).__init__(full_msg)
64
+
65
+
66
+ class ApiAttributeError(OpenApiException, AttributeError):
67
+ def __init__(self, msg, path_to_item=None) -> None:
68
+ """
69
+ Raised when an attribute reference or assignment fails.
70
+
71
+ Args:
72
+ msg (str): the exception message
73
+
74
+ Keyword Args:
75
+ path_to_item (None/list) the path to the exception in the
76
+ received_data dict
77
+ """
78
+ self.path_to_item = path_to_item
79
+ full_msg = msg
80
+ if path_to_item:
81
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
82
+ super(ApiAttributeError, self).__init__(full_msg)
83
+
84
+
85
+ class ApiKeyError(OpenApiException, KeyError):
86
+ def __init__(self, msg, path_to_item=None) -> None:
87
+ """
88
+ Args:
89
+ msg (str): the exception message
90
+
91
+ Keyword Args:
92
+ path_to_item (None/list) the path to the exception in the
93
+ received_data dict
94
+ """
95
+ self.path_to_item = path_to_item
96
+ full_msg = msg
97
+ if path_to_item:
98
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
99
+ super(ApiKeyError, self).__init__(full_msg)
100
+
101
+
102
+ class ApiException(OpenApiException):
103
+
104
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
105
+ if http_resp:
106
+ self.status = http_resp.status
107
+ self.reason = http_resp.reason
108
+ self.body = http_resp.data
109
+ self.headers = http_resp.getheaders()
110
+ else:
111
+ self.status = status
112
+ self.reason = reason
113
+ self.body = None
114
+ self.headers = None
115
+
116
+ def __str__(self):
117
+ """Custom error messages for exception"""
118
+ error_message = "({0})\n"\
119
+ "Reason: {1}\n".format(self.status, self.reason)
120
+ if self.headers:
121
+ error_message += "HTTP response headers: {0}\n".format(
122
+ self.headers)
123
+
124
+ if self.body:
125
+ error_message += "HTTP response body: {0}\n".format(self.body)
126
+
127
+ return error_message
128
+
129
+ class BadRequestException(ApiException):
130
+
131
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
132
+ super(BadRequestException, self).__init__(status, reason, http_resp)
133
+
134
+ class NotFoundException(ApiException):
135
+
136
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
137
+ super(NotFoundException, self).__init__(status, reason, http_resp)
138
+
139
+
140
+ class UnauthorizedException(ApiException):
141
+
142
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
143
+ super(UnauthorizedException, self).__init__(status, reason, http_resp)
144
+
145
+
146
+ class ForbiddenException(ApiException):
147
+
148
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
149
+ super(ForbiddenException, self).__init__(status, reason, http_resp)
150
+
151
+
152
+ class ServiceException(ApiException):
153
+
154
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
155
+ super(ServiceException, self).__init__(status, reason, http_resp)
156
+
157
+
158
+ def render_path(path_to_item):
159
+ """Returns a string representation of a path"""
160
+ result = ""
161
+ for pth in path_to_item:
162
+ if isinstance(pth, int):
163
+ result += "[{0}]".format(pth)
164
+ else:
165
+ result += "['{0}']".format(pth)
166
+ return result
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ # flake8: noqa
4
+ """
5
+ Weheat Backend
6
+
7
+ This is the backend for the Weheat project
8
+
9
+ The version of the OpenAPI document: v1
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ # import models into model package
17
+ from weheat.models.device_state import DeviceState
18
+ from weheat.models.energy_view_dto import EnergyViewDto
19
+ from weheat.models.heat_pump_log_view_dto import HeatPumpLogViewDto
20
+ from weheat.models.raw_heat_pump_log_dto import RawHeatPumpLogDto
21
+ from weheat.models.read_all_heat_pump_dto import ReadAllHeatPumpDto
22
+ from weheat.models.read_heat_pump_dto import ReadHeatPumpDto
23
+ from weheat.models.read_user_dto import ReadUserDto
24
+ from weheat.models.role import Role
@@ -0,0 +1,42 @@
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
+ import json
16
+ import pprint
17
+ import re # noqa: F401
18
+ from aenum import Enum, no_arg
19
+
20
+
21
+
22
+
23
+
24
+ class BoilerType(int, Enum):
25
+ """
26
+ Type of model and use of the heat pump - Unknown: Not known if a boiler is in the installation (0) - None: No boiler detected (1) - OnOff: On/off boiler detected (2) - OpenTherm: OpenTherm boiler detected (3)
27
+ """
28
+
29
+ """
30
+ allowed enum values
31
+ """
32
+ NUMBER_0 = 0
33
+ NUMBER_1 = 1
34
+ NUMBER_2 = 2
35
+ NUMBER_3 = 3
36
+
37
+ @classmethod
38
+ def from_json(cls, json_str: str) -> BoilerType:
39
+ """Create an instance of BoilerType from a JSON string"""
40
+ return BoilerType(json.loads(json_str))
41
+
42
+