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 , ExecutionMode , 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 past executions and their outcomes."""
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 a currently running execution by its exec_id."""
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 currently running executions."""
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 :
@@ -550,7 +551,7 @@ async def cancel_execution(self, exec_id: str) -> None:
550551 async def get_action_groups (self ) -> list [ActionGroup ]:
551552 """List action groups persisted on the server."""
552553 response = await self ._get ("actionGroups" )
553- return [ ActionGroup ( ** action_group ) for action_group in decamelize (response )]
554+ return converter . structure ( decamelize (response ), list [ ActionGroup ])
554555
555556 @retry_on_auth_error
556557 async def get_places (self ) -> Place :
@@ -565,7 +566,7 @@ async def get_places(self) -> Place:
565566 - `sub_places`: List of nested places within this location
566567 """
567568 response = await self ._get ("setup/places" )
568- return Place ( ** decamelize (response ))
569+ return converter . structure ( decamelize (response ), Place )
569570
570571 @retry_on_auth_error
571572 async def execute_persisted_action_group (self , oid : str ) -> str :
@@ -587,7 +588,7 @@ async def get_setup_options(self) -> list[Option]:
587588 Access scope : Full enduser API access (enduser/*).
588589 """
589590 response = await self ._get ("setup/options" )
590- return [ Option ( ** o ) for o in decamelize (response )]
591+ return converter . structure ( decamelize (response ), list [ Option ])
591592
592593 @retry_on_auth_error
593594 async def get_setup_option (self , option : str ) -> Option | None :
@@ -598,7 +599,7 @@ async def get_setup_option(self, option: str) -> Option | None:
598599 response = await self ._get (f"setup/options/{ option } " )
599600
600601 if response :
601- return Option ( ** decamelize (response ))
602+ return converter . structure ( decamelize (response ), Option )
602603
603604 return None
604605
@@ -616,7 +617,7 @@ async def get_setup_option_parameter(
616617 response = await self ._get (f"setup/options/{ option } /{ parameter } " )
617618
618619 if response :
619- return OptionParameter ( ** decamelize (response ))
620+ return converter . structure ( decamelize (response ), OptionParameter )
620621
621622 return None
622623
@@ -648,7 +649,7 @@ async def get_reference_protocol_types(self) -> list[ProtocolType]:
648649 - label: Human-readable protocol label
649650 """
650651 response = await self ._get ("reference/protocolTypes" )
651- return [ ProtocolType ( ** protocol ) for protocol in response ]
652+ return converter . structure ( response , list [ ProtocolType ])
652653
653654 @retry_on_auth_error
654655 async def get_reference_timezones (self ) -> JSON :
@@ -678,7 +679,7 @@ async def get_reference_ui_profile(self, profile_name: str) -> UIProfileDefiniti
678679 response = await self ._get (
679680 f"reference/ui/profile/{ urllib .parse .quote_plus (profile_name )} "
680681 )
681- return UIProfileDefinition ( ** decamelize (response ))
682+ return converter . structure ( decamelize (response ), UIProfileDefinition )
682683
683684 @retry_on_auth_error
684685 async def get_reference_ui_profile_names (self ) -> list [str ]:
0 commit comments