@@ -147,37 +147,40 @@ async def initialize(self, with_node_servers=False):
147147 if not self .configuration ["model" ].startswith ("ISY 994" ):
148148 self .conn .increase_available_connections ()
149149
150- isy_setup_tasks = [
151- self .conn .get_status (),
152- self .conn .get_time (),
153- self .conn .get_nodes (),
154- self .conn .get_programs (),
155- self .conn .get_variable_defs (),
156- self .conn .get_variables (),
157- ]
158- if self .configuration [CONFIG_NETWORKING ] or self .configuration .get (CONFIG_PORTAL ):
159- isy_setup_tasks .append (asyncio .create_task (self .conn .get_network ()))
160- isy_setup_results = await asyncio .gather (* isy_setup_tasks )
150+ load_network = bool (self .configuration [CONFIG_NETWORKING ] or self .configuration .get (CONFIG_PORTAL ))
151+ async with asyncio .TaskGroup () as tg :
152+ status_task = tg .create_task (self .conn .get_status ())
153+ time_task = tg .create_task (self .conn .get_time ())
154+ nodes_task = tg .create_task (self .conn .get_nodes ())
155+ programs_task = tg .create_task (self .conn .get_programs ())
156+ var_defs_task = tg .create_task (self .conn .get_variable_defs ())
157+ vars_task = tg .create_task (self .conn .get_variables ())
158+ network_task = tg .create_task (self .conn .get_network ()) if load_network else None
159+
160+ status_xml = status_task .result ()
161+ time_xml = time_task .result ()
162+ nodes_xml = nodes_task .result ()
163+ programs_xml = programs_task .result ()
161164
162165 # Fail fast if the controller didn't return any of the load-bearing
163166 # responses — most often because the ISY is still booting. Mounting
164167 # empty managers silently leads to confused downstream consumers.
165- if any (isy_setup_results [ i ] is None for i in (0 , 1 , 2 , 3 )):
168+ if any (x is None for x in (status_xml , time_xml , nodes_xml , programs_xml )):
166169 raise ISYResponseParseError (
167170 "ISY did not return all setup data; the controller may still be initializing."
168171 )
169172
170- self .clock = Clock (self , xml = isy_setup_results [ 1 ] )
171- self .nodes = Nodes (self , xml = isy_setup_results [ 2 ] )
172- self .programs = Programs (self , xml = isy_setup_results [ 3 ] )
173+ self .clock = Clock (self , xml = time_xml )
174+ self .nodes = Nodes (self , xml = nodes_xml )
175+ self .programs = Programs (self , xml = programs_xml )
173176 self .variables = Variables (
174177 self ,
175- def_xml = isy_setup_results [ 4 ] ,
176- var_xml = isy_setup_results [ 5 ] ,
178+ def_xml = var_defs_task . result () ,
179+ var_xml = vars_task . result () ,
177180 )
178- if self . configuration [ CONFIG_NETWORKING ] or self . configuration . get ( CONFIG_PORTAL ) :
179- self .networking = NetworkResources (self , xml = isy_setup_results [ 6 ] )
180- await self .nodes .update (xml = isy_setup_results [ 0 ] )
181+ if network_task is not None :
182+ self .networking = NetworkResources (self , xml = network_task . result () )
183+ await self .nodes .update (xml = status_xml )
181184 if self .node_servers and with_node_servers :
182185 await self .node_servers .load_node_servers ()
183186
0 commit comments