pydiagral 1.5.0b1__py3-none-any.whl → 1.5.0b2__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.
- pydiagral/api.py +23 -22
- pydiagral/models.py +24 -0
- {pydiagral-1.5.0b1.dist-info → pydiagral-1.5.0b2.dist-info}/METADATA +1 -1
- pydiagral-1.5.0b2.dist-info/RECORD +10 -0
- pydiagral-1.5.0b1.dist-info/RECORD +0 -10
- {pydiagral-1.5.0b1.dist-info → pydiagral-1.5.0b2.dist-info}/WHEEL +0 -0
- {pydiagral-1.5.0b1.dist-info → pydiagral-1.5.0b2.dist-info}/licenses/LICENSE +0 -0
pydiagral/api.py
CHANGED
@@ -36,6 +36,7 @@ from .models import (
|
|
36
36
|
Rudes,
|
37
37
|
SystemDetails,
|
38
38
|
SystemStatus,
|
39
|
+
TryConnectResult,
|
39
40
|
Webhook,
|
40
41
|
)
|
41
42
|
from .utils import generate_hmac_signature
|
@@ -400,48 +401,48 @@ class DiagralAPI:
|
|
400
401
|
self.__secret_key = None
|
401
402
|
|
402
403
|
async def try_connection(self, ephemeral: bool = True) -> bool:
|
403
|
-
"""
|
404
|
+
"""Test connection with the Diagral system.
|
404
405
|
|
405
|
-
This method
|
406
|
-
|
407
|
-
2. If not, generating temporary API keys
|
408
|
-
3. Validating the connection by checking system status
|
409
|
-
4. Optionally cleaning up temporary keys if requested
|
406
|
+
This method tests the connection by either using provided API credentials or generating
|
407
|
+
temporary ones. It validates the connection by checking the system status.
|
410
408
|
|
411
409
|
Args:
|
412
|
-
ephemeral (bool, optional): If True
|
413
|
-
|
410
|
+
ephemeral (bool, optional): If True, temporary API keys will be deleted after
|
411
|
+
connection test. Defaults to True.
|
414
412
|
|
415
413
|
Returns:
|
416
|
-
|
414
|
+
TryConnectResult: Object containing connection test results and optionally API keys
|
415
|
+
if non-ephemeral temporary keys were generated.
|
417
416
|
|
418
417
|
Raises:
|
419
|
-
DiagralAPIError: If connection fails or system status check fails
|
418
|
+
DiagralAPIError: If connection attempt fails or system status check fails.
|
419
|
+
|
420
|
+
Note:
|
421
|
+
If API credentials are not provided during client initialization, temporary
|
422
|
+
keys will be generated (if ephemeral) for the connection test. These keys will be:
|
423
|
+
- Deleted after the test if ephemeral=True
|
424
|
+
- Returned in the result if ephemeral=False
|
420
425
|
|
421
426
|
"""
|
422
427
|
|
428
|
+
result: TryConnectResult = TryConnectResult()
|
423
429
|
api_keys_provided = bool(self.__apikey and self.__secret_key)
|
424
|
-
_LOGGER.warning("API keys provided: %s", api_keys_provided)
|
425
430
|
try:
|
431
|
+
# If API keys are not provided, generate temporary keys
|
426
432
|
if not api_keys_provided:
|
427
433
|
api_key_response: ApiKeyWithSecret = await self.set_apikey()
|
428
|
-
_LOGGER.debug(
|
429
|
-
"TEST CONNECTION - Successfully created temporary API key : %s",
|
430
|
-
api_key_response,
|
431
|
-
)
|
432
|
-
if await self.validate_apikey(apikey=api_key_response.api_key):
|
433
|
-
_LOGGER.debug(
|
434
|
-
"TEST CONNECTION - Successfully validated temporary API key"
|
435
|
-
)
|
436
|
-
self.__apikey: str = api_key_response.api_key
|
437
|
-
self.__secret_key: str = api_key_response.secret_key
|
438
434
|
|
435
|
+
# Retrieve system status to validate connection
|
439
436
|
await self.get_system_status()
|
437
|
+
# If connection is successful, clean up temporary keys if requested (ephemeral)
|
440
438
|
if ephemeral and not api_keys_provided:
|
441
439
|
await self.delete_apikey(apikey=self.__apikey)
|
440
|
+
elif not ephemeral and not api_keys_provided:
|
441
|
+
result.keys = api_key_response
|
442
442
|
except DiagralAPIError as e:
|
443
443
|
raise DiagralAPIError(f"Failed to connect to the system: {e}") from e
|
444
|
-
|
444
|
+
result.result = True
|
445
|
+
return result
|
445
446
|
|
446
447
|
async def get_configuration(self) -> None:
|
447
448
|
"""Asynchronously retrieve the configuration of the Diagral system.
|
pydiagral/models.py
CHANGED
@@ -355,6 +355,30 @@ class ApiKeys(CamelCaseModel):
|
|
355
355
|
)
|
356
356
|
|
357
357
|
|
358
|
+
@dataclass
|
359
|
+
class TryConnectResult(CamelCaseModel):
|
360
|
+
"""A class representing the result of an API connection attempt.
|
361
|
+
|
362
|
+
This class is used to store the result of an API connection attempt
|
363
|
+
and the associated API keys if the connection was successful.
|
364
|
+
|
365
|
+
Attributes:
|
366
|
+
result (bool | None): Whether the connection attempt was successful. Defaults to False.
|
367
|
+
keys (ApiKeyWithSecret | None): The API keys associated with the successful connection. Defaults to None.
|
368
|
+
|
369
|
+
Example:
|
370
|
+
>>> result = TryConnectResult(result=True, keys=api_key_obj)
|
371
|
+
>>> print(result.result)
|
372
|
+
True
|
373
|
+
>>> print(result.keys)
|
374
|
+
ApiKeyWithSecret(api_key='abc123', api_secret='xyz789')
|
375
|
+
|
376
|
+
"""
|
377
|
+
|
378
|
+
result: bool | None = False
|
379
|
+
keys: ApiKeyWithSecret | None = None
|
380
|
+
|
381
|
+
|
358
382
|
#####################################
|
359
383
|
# Data models for alarm configuration
|
360
384
|
#####################################
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pydiagral
|
3
|
-
Version: 1.5.
|
3
|
+
Version: 1.5.0b2
|
4
4
|
Summary: A Python library for interacting with Diagral systems
|
5
5
|
Project-URL: Homepage, https://github.com/mguyard/pydiagral
|
6
6
|
Project-URL: Documentation, https://github.com/mguyard/pydiagral
|
@@ -0,0 +1,10 @@
|
|
1
|
+
pydiagral/__init__.py,sha256=4uM-RD2GQ6JYJkxu-D6wj3XpqfY5gN2hP8NF6WvRI9k,576
|
2
|
+
pydiagral/api.py,sha256=F00LgyVtayPtZOm9O5DNQ2gLCv36vpsK6gCJXxOZNRk,48736
|
3
|
+
pydiagral/constants.py,sha256=2B0TdKxQHA3cpIBxojo43bMW44wN9xKYsHbBRHWsaBk,119
|
4
|
+
pydiagral/exceptions.py,sha256=Q5wEpNtiykLs3Ck0W8r1IQAJek_omaQ3jpMOtiiwBUg,1030
|
5
|
+
pydiagral/models.py,sha256=vUjxuApjVaMtd7H6Iw5LarwABi30O4FfdObhZRbUNuc,54931
|
6
|
+
pydiagral/utils.py,sha256=-VxI-lNaC4bU1K4DSmWDhvbsS2bXv5FAGULGKBf1UMU,449
|
7
|
+
pydiagral-1.5.0b2.dist-info/METADATA,sha256=ngDa7KSkaHBpcc5EEqf0CS5IlpmQwNF_dvmPDQClfxs,48531
|
8
|
+
pydiagral-1.5.0b2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
+
pydiagral-1.5.0b2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
10
|
+
pydiagral-1.5.0b2.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
pydiagral/__init__.py,sha256=4uM-RD2GQ6JYJkxu-D6wj3XpqfY5gN2hP8NF6WvRI9k,576
|
2
|
-
pydiagral/api.py,sha256=LEDHEdf5wRd7QB7flsk3hnb2X_sf1325sD9DPDkBOhM,48587
|
3
|
-
pydiagral/constants.py,sha256=2B0TdKxQHA3cpIBxojo43bMW44wN9xKYsHbBRHWsaBk,119
|
4
|
-
pydiagral/exceptions.py,sha256=Q5wEpNtiykLs3Ck0W8r1IQAJek_omaQ3jpMOtiiwBUg,1030
|
5
|
-
pydiagral/models.py,sha256=AKJd9ywPhislF5R685XNLvEpmJouFlkxWzz1pJXY4tA,54136
|
6
|
-
pydiagral/utils.py,sha256=-VxI-lNaC4bU1K4DSmWDhvbsS2bXv5FAGULGKBf1UMU,449
|
7
|
-
pydiagral-1.5.0b1.dist-info/METADATA,sha256=CudZesyW4jeyR1tR-N7K5tXVt4no-2nzY7voKEgaecc,48531
|
8
|
-
pydiagral-1.5.0b1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
-
pydiagral-1.5.0b1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
10
|
-
pydiagral-1.5.0b1.dist-info/RECORD,,
|
File without changes
|
File without changes
|