@@ -153,49 +153,55 @@ async def fetch_parameters_v2(self, gateway_id, system_id) -> list[Parameter]:
153153
154154 # api/portal/GetGuiDescriptionForGateway?GatewayId={gateway_id}&SystemId={system_id}
155155 async def fetch_parameters (self , gateway_id , system_id ) -> list [Parameter ]:
156+ await self .load_localized_json (self .region_set )
157+ payload = {GATEWAY_ID : gateway_id , SYSTEM_ID : system_id }
158+ desc = await self .__request (
159+ "get" , "api/portal/GetGuiDescriptionForGateway" , params = payload
160+ )
161+ _LOGGER .debug ("Fetched parameters: %s" , desc )
156162 if self .expert_mode :
157- return await self .fetch_parameters_v2 (gateway_id , system_id )
163+ descriptors = WolfClient ._extract_parameter_descriptors (desc )
164+ _LOGGER .debug ("Found parameter descriptors: %s" , len (descriptors ))
165+ descriptors .sort (key = lambda x : x ['ValueId' ])
166+ result = [[WolfClient ._map_parameter (p , None ) for p in descriptors ]]
158167 else :
159- await self .load_localized_json (self .region_set )
160- payload = {GATEWAY_ID : gateway_id , SYSTEM_ID : system_id }
161- desc = await self .__request (
162- "get" , "api/portal/GetGuiDescriptionForGateway" , params = payload
163- )
164- _LOGGER .debug ("Fetched parameters: %s" , desc )
165168 tab_views = desc [MENU_ITEMS ][0 ][TAB_VIEWS ]
166169 result = [WolfClient ._map_view (view ) for view in tab_views ]
167- result .reverse ()
168- distinct_ids = []
169- flattened = []
170- for sublist in result :
171- for val in sublist :
172- spaceSplit = val .name .split (SPLIT , 2 )
173- if len (spaceSplit ) == 2 :
174- key = (
175- spaceSplit [0 ].split ("_" )[1 ]
176- if spaceSplit [0 ].count ("_" ) > 0
177- else spaceSplit [0 ]
178- )
179- name = (
180- self .replace_with_localized_text (key )
181- + " "
182- + self .replace_with_localized_text (spaceSplit [1 ])
183- )
184- val .name = name
185- else :
186- val .name = self .replace_with_localized_text (val .name )
187-
188- if val .value_id not in distinct_ids :
189- distinct_ids .append (val .value_id )
190- flattened .append (val )
191- else :
192- _LOGGER .debug (
193- "Skipping parameter with id %s and name %s" ,
194- val .value_id ,
195- val .name ,
196- )
197- flattened_fixed = self .fix_duplicated_parameters (flattened )
198- return flattened_fixed
170+ result .reverse ()
171+ distinct_ids = []
172+ flattened = []
173+ for sublist in result :
174+ for val in sublist :
175+ if val is None :
176+ _LOGGER .debug ("Encountered None value in parameters" )
177+ continue
178+ spaceSplit = val .name .split (SPLIT , 2 )
179+ if len (spaceSplit ) == 2 :
180+ key = (
181+ spaceSplit [0 ].split ("_" )[1 ]
182+ if spaceSplit [0 ].count ("_" ) > 0
183+ else spaceSplit [0 ]
184+ )
185+ name = (
186+ self .replace_with_localized_text (key )
187+ + " "
188+ + self .replace_with_localized_text (spaceSplit [1 ])
189+ )
190+ val .name = name
191+ else :
192+ val .name = self .replace_with_localized_text (val .name )
193+
194+ if val .value_id not in distinct_ids :
195+ distinct_ids .append (val .value_id )
196+ flattened .append (val )
197+ else :
198+ _LOGGER .debug (
199+ "Skipping parameter with id %s and name %s" ,
200+ val .value_id ,
201+ val .name ,
202+ )
203+ flattened_fixed = self .fix_duplicated_parameters (flattened )
204+ return flattened_fixed
199205
200206 def fix_duplicated_parameters (self , parameters ):
201207 """Fix duplicated parameters."""
0 commit comments