def _parse_homehub_response(data_str):
 root = ET.fromstring(data_str)
 dirty_json = root.find('known_device_list').get('value')
 clean_json = unquote(dirty_json.replace("'", '"').replace('{', '{"').replace(':"', '":"').replace('",', '","'))
 known_devices = [x for x in json.loads(clean_json) if x]
 devices = {}
 for device in known_devices:
  name = device.get('name')
  mac = device.get('mac')
  if (_MAC_REGEX.match(mac) or (',' in mac)):
   for mac_addr in mac.split(','):
    if _MAC_REGEX.match(mac_addr):
     devices[mac_addr] = name
  else:
   devices[mac] = name
 return devices

def _parse_homehub_response ( data_str ) : root = ET . fromstring ( data_str ) dirty_json = root . find ( 'known_device_list' ) . get ( 'value' ) clean_json = unquote ( dirty_json . replace ( "'" , '"' ) . replace ( '{' , '{"' ) . replace ( ':"' , '":"' ) . replace ( '",' , '","' ) ) known_devices = [ x for x in json . loads ( clean_json ) if x ] devices = { } for device in known_devices : name = device . get ( 'name' ) mac = device . get ( 'mac' ) if ( _MAC_REGEX . match ( mac ) or ( ',' in mac ) ) : for mac_addr in mac . split ( ',' ) : if _MAC_REGEX . match ( mac_addr ) : devices [ mac_addr ] = name else : devices [ mac ] = name return devices
parse the bt home hub 5 data format .