def rewrite_legacy(config):
 bridges = config.get(CONF_BRIDGES, [config])
 new_bridges = []
 for bridge_conf in bridges:
  groups = []
  if ('groups' in bridge_conf):
   groups = bridge_conf['groups']
  else:
   _LOGGER.warning('Legacy configuration format detected')
   for i in range(1, 5):
    name_key = ('group_%d_name' % i)
    if (name_key in bridge_conf):
     groups.append({'number': i, 'type': bridge_conf.get(('group_%d_type' % i), DEFAULT_LED_TYPE), 'name': bridge_conf.get(name_key)})
  new_bridges.append({'host': bridge_conf.get(CONF_HOST), 'groups': groups})
 return {'bridges': new_bridges}

def rewrite_legacy ( config ) : bridges = config . get ( CONF_BRIDGES , [ config ] ) new_bridges = [ ] for bridge_conf in bridges : groups = [ ] if ( 'groups' in bridge_conf ) : groups = bridge_conf [ 'groups' ] else : _LOGGER . warning ( 'Legacy configuration format detected' ) for i in range ( 1 , 5 ) : name_key = ( 'group_%d_name' % i ) if ( name_key in bridge_conf ) : groups . append ( { 'number' : i , 'type' : bridge_conf . get ( ( 'group_%d_type' % i ) , DEFAULT_LED_TYPE ) , 'name' : bridge_conf . get ( name_key ) } ) new_bridges . append ( { 'host' : bridge_conf . get ( CONF_HOST ) , 'groups' : groups } ) return { 'bridges' : new_bridges }
rewrite legacy configuration to new format .