2222from pyoverkiz .action_queue import ActionQueue , ActionQueueSettings
2323from pyoverkiz .auth import AuthStrategy , Credentials , build_auth_strategy
2424from pyoverkiz .const import SUPPORTED_SERVERS
25+ from pyoverkiz .converter import converter
2526from pyoverkiz .enums import APIType , CommandMode , Server
2627from pyoverkiz .exceptions import (
2728 ExecutionQueueFullError ,
@@ -305,7 +306,7 @@ async def get_setup(self, refresh: bool = False) -> Setup:
305306
306307 response = await self ._get ("setup" )
307308
308- setup = Setup ( ** decamelize (response ))
309+ setup = converter . structure ( decamelize (response ), Setup )
309310
310311 # Cache response
311312 self .setup = setup
@@ -343,7 +344,7 @@ async def get_devices(self, refresh: bool = False) -> list[Device]:
343344 return self .devices
344345
345346 response = await self ._get ("setup/devices" )
346- devices = [ Device ( ** d ) for d in decamelize (response )]
347+ devices = converter . structure ( decamelize (response ), list [ Device ])
347348
348349 # Cache response
349350 self .devices = devices
@@ -362,7 +363,7 @@ async def get_gateways(self, refresh: bool = False) -> list[Gateway]:
362363 return self .gateways
363364
364365 response = await self ._get ("setup/gateways" )
365- gateways = [ Gateway ( ** g ) for g in decamelize (response )]
366+ gateways = converter . structure ( decamelize (response ), list [ Gateway ])
366367
367368 # Cache response
368369 self .gateways = gateways
@@ -375,7 +376,7 @@ async def get_gateways(self, refresh: bool = False) -> list[Gateway]:
375376 async def get_execution_history (self ) -> list [HistoryExecution ]:
376377 """List execution history."""
377378 response = await self ._get ("history/executions" )
378- return [ HistoryExecution ( ** h ) for h in decamelize (response )]
379+ return converter . structure ( decamelize (response ), list [ HistoryExecution ])
379380
380381 @retry_on_auth_error
381382 async def get_device_definition (self , deviceurl : str ) -> JSON | None :
@@ -392,7 +393,7 @@ async def get_state(self, deviceurl: str) -> list[State]:
392393 response = await self ._get (
393394 f"setup/devices/{ urllib .parse .quote_plus (deviceurl )} /states"
394395 )
395- return [ State ( ** s ) for s in decamelize (response )]
396+ return converter . structure ( decamelize (response ), list [ State ])
396397
397398 @retry_on_auth_error
398399 async def refresh_states (self ) -> None :
@@ -436,7 +437,7 @@ async def fetch_events(self) -> list[Event]:
436437 """
437438 await self ._refresh_token_if_expired ()
438439 response = await self ._post (f"events/{ self .event_listener_id } /fetch" )
439- return [ Event ( ** e ) for e in decamelize (response )]
440+ return converter . structure ( decamelize (response ), list [ Event ])
440441
441442 async def unregister_event_listener (self ) -> None :
442443 """Unregister an event listener.
@@ -451,13 +452,13 @@ async def unregister_event_listener(self) -> None:
451452 async def get_current_execution (self , exec_id : str ) -> Execution :
452453 """Get an action group execution currently running."""
453454 response = await self ._get (f"exec/current/{ exec_id } " )
454- return Execution ( ** decamelize (response ))
455+ return converter . structure ( decamelize (response ), Execution )
455456
456457 @retry_on_auth_error
457458 async def get_current_executions (self ) -> list [Execution ]:
458459 """Get all action groups executions currently running."""
459460 response = await self ._get ("exec/current" )
460- return [ Execution ( ** e ) for e in decamelize (response )]
461+ return converter . structure ( decamelize (response ), list [ Execution ])
461462
462463 @retry_on_auth_error
463464 async def get_api_version (self ) -> str :
@@ -555,7 +556,7 @@ async def cancel_command(self, exec_id: str) -> None:
555556 async def get_action_groups (self ) -> list [ActionGroup ]:
556557 """List the action groups (scenarios)."""
557558 response = await self ._get ("actionGroups" )
558- return [ ActionGroup ( ** action_group ) for action_group in decamelize (response )]
559+ return converter . structure ( decamelize (response ), list [ ActionGroup ])
559560
560561 @retry_on_auth_error
561562 async def get_places (self ) -> Place :
@@ -570,7 +571,7 @@ async def get_places(self) -> Place:
570571 - `sub_places`: List of nested places within this location
571572 """
572573 response = await self ._get ("setup/places" )
573- return Place ( ** decamelize (response ))
574+ return converter . structure ( decamelize (response ), Place )
574575
575576 @retry_on_auth_error
576577 async def execute_scenario (self , oid : str ) -> str :
@@ -592,7 +593,7 @@ async def get_setup_options(self) -> list[Option]:
592593 Access scope : Full enduser API access (enduser/*).
593594 """
594595 response = await self ._get ("setup/options" )
595- return [ Option ( ** o ) for o in decamelize (response )]
596+ return converter . structure ( decamelize (response ), list [ Option ])
596597
597598 @retry_on_auth_error
598599 async def get_setup_option (self , option : str ) -> Option | None :
@@ -603,7 +604,7 @@ async def get_setup_option(self, option: str) -> Option | None:
603604 response = await self ._get (f"setup/options/{ option } " )
604605
605606 if response :
606- return Option ( ** decamelize (response ))
607+ return converter . structure ( decamelize (response ), Option )
607608
608609 return None
609610
@@ -621,7 +622,7 @@ async def get_setup_option_parameter(
621622 response = await self ._get (f"setup/options/{ option } /{ parameter } " )
622623
623624 if response :
624- return OptionParameter ( ** decamelize (response ))
625+ return converter . structure ( decamelize (response ), OptionParameter )
625626
626627 return None
627628
@@ -653,7 +654,7 @@ async def get_reference_protocol_types(self) -> list[ProtocolType]:
653654 - label: Human-readable protocol label
654655 """
655656 response = await self ._get ("reference/protocolTypes" )
656- return [ ProtocolType ( ** protocol ) for protocol in response ]
657+ return converter . structure ( response , list [ ProtocolType ])
657658
658659 @retry_on_auth_error
659660 async def get_reference_timezones (self ) -> JSON :
@@ -683,7 +684,7 @@ async def get_reference_ui_profile(self, profile_name: str) -> UIProfileDefiniti
683684 response = await self ._get (
684685 f"reference/ui/profile/{ urllib .parse .quote_plus (profile_name )} "
685686 )
686- return UIProfileDefinition ( ** decamelize (response ))
687+ return converter . structure ( decamelize (response ), UIProfileDefinition )
687688
688689 @retry_on_auth_error
689690 async def get_reference_ui_profile_names (self ) -> list [str ]:
0 commit comments