@@ -150,9 +150,7 @@ def __get_response_error(self, response):
150150 def __get_response (self , response , index = 0 ):
151151 """Retrieve response from result."""
152152 try :
153- value = response ["reply" ]["actions" ][index ]["callbacks" ][index ][
154- "parameters"
155- ]
153+ value = response ["reply" ]["actions" ][index ]["callbacks" ][0 ]["parameters" ]
156154 except KeyError :
157155 value = None
158156
@@ -315,6 +313,29 @@ async def get_value_by_xpath(
315313
316314 return data
317315
316+ async def get_values_by_xpaths (self , xpaths , options : Optional [Dict ] = {}) -> Dict :
317+ """
318+ Retrieve raw values from router using XPath.
319+
320+ :param xpaths: Dict of key to xpath expression
321+ :param options: optional options
322+ """
323+ actions = [
324+ {
325+ "id" : i ,
326+ "method" : "getValue" ,
327+ "xpath" : urllib .parse .quote (xpath ),
328+ "options" : options ,
329+ }
330+ for i , xpath in enumerate (xpaths .values ())
331+ ]
332+
333+ response = await self .__api_request_async (actions , False )
334+ values = [self .__get_response_value (response , i ) for i in range (len (xpaths ))]
335+ data = dict (zip (xpaths .keys (), values ))
336+
337+ return data
338+
318339 async def set_value_by_xpath (
319340 self , xpath : str , value : str , options : Optional [Dict ] = {}
320341 ) -> Dict :
@@ -341,29 +362,20 @@ async def get_device_info(self) -> DeviceInfo:
341362 """Retrieve information about Sagemcom F@st device."""
342363 try :
343364 data = await self .get_value_by_xpath ("Device/DeviceInfo" )
344- return DeviceInfo (** data .get ("device_info" ))
345365 except UnknownPathException :
346- device_info = DeviceInfo ()
347- device_info .mac_address = await self .get_value_by_xpath (
348- "Device/DeviceInfo/MACAddress"
349- )
350- device_info .manufacturer = "Sagemcom"
351- device_info .model_name = await self .get_value_by_xpath (
352- "Device/DeviceInfo/ModelNumber"
353- )
354- device_info .model_number = await self .get_value_by_xpath (
355- "Device/DeviceInfo/ProductClass"
356- )
357- device_info .product_class = await self .get_value_by_xpath (
358- "Device/DeviceInfo/ProductClass"
366+ data = await self .get_values_by_xpaths (
367+ {
368+ "mac_address" : "Device/DeviceInfo/MACAddress" ,
369+ "model_name" : "Device/DeviceInfo/ModelNumber" ,
370+ "model_number" : "Device/DeviceInfo/ProductClass" ,
371+ "product_class" : "Device/DeviceInfo/ProductClass" ,
372+ "serial_number" : "Device/DeviceInfo/SerialNumber" ,
373+ "software_version" : "Device/DeviceInfo/SoftwareVersion" ,
374+ }
359375 )
360- device_info .serial_number = await self .get_value_by_xpath (
361- "Device/DeviceInfo/SerialNumber"
362- )
363- device_info .software_version = await self .get_value_by_xpath (
364- "Device/DeviceInfo/SoftwareVersion"
365- )
366- return device_info
376+ data ["manufacturer" ] = "Sagemcom"
377+
378+ return DeviceInfo (** data )
367379
368380 async def get_hosts (self , only_active : Optional [bool ] = False ) -> List [Device ]:
369381 """Retrieve hosts connected to Sagemcom F@st device."""
0 commit comments