pydiagral 1.5.0b1__py3-none-any.whl → 1.5.0b4__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 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
@@ -399,49 +400,49 @@ class DiagralAPI:
399
400
  self.__apikey = None
400
401
  self.__secret_key = None
401
402
 
402
- async def try_connection(self, ephemeral: bool = True) -> bool:
403
- """Establish a connection with the Diagral system.
403
+ async def try_connection(self, ephemeral: bool = True) -> TryConnectResult:
404
+ """Test connection with the Diagral system.
404
405
 
405
- This method tries to connect to the Diagral API by:
406
- 1. Checking if API keys are provided
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 and using temporary API keys,
413
- deletes them after validation. Defaults to True.
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
- bool: True if connection is successful
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
- return True
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.
@@ -488,6 +489,28 @@ class DiagralAPI:
488
489
  )
489
490
  return self.alarm_configuration
490
491
 
492
+ async def get_alarm_name(self) -> str:
493
+ """Get the name of the alarm from the configuration.
494
+
495
+ Returns:
496
+ str: The name of the alarm from the configuration.
497
+
498
+ Raises:
499
+ ConfigurationError: If unable to retrieve the alarm configuration.
500
+
501
+ Note:
502
+ This method will attempt to fetch the configuration if it hasn't been loaded yet.
503
+
504
+ """
505
+
506
+ if not self.alarm_configuration:
507
+ await self.get_configuration()
508
+
509
+ if not self.alarm_configuration:
510
+ raise ConfigurationError("Failed to retrieve alarm configuration")
511
+
512
+ return self.alarm_configuration.alarm.name
513
+
491
514
  async def get_devices_info(self) -> DeviceList:
492
515
  """Asynchronously retrieves information about various device types from the alarm configuration.
493
516
 
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.0b1
3
+ Version: 1.5.0b4
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=ZshZu5NTSyjK7ozPYrXO6q94yjxnHt3h_boiGzRIUzk,49410
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.0b4.dist-info/METADATA,sha256=qurrNFVqrGxsuLKX9VJKPdtsW8ZhnA2A19rnC1voRPM,48531
8
+ pydiagral-1.5.0b4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ pydiagral-1.5.0b4.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
10
+ pydiagral-1.5.0b4.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,,